bool EllipticalRegion::hitBottomModifyPoint(const QPoint &point) { bool result = false; QPoint bottomModifyPoint(getCenterPoint().x(), getCenterPoint().y() + getMinorAxis()); if (distance(point, bottomModifyPoint) <= SQUARE(MODIFY_POINT_RADIUS)) { result = true; setIsBottomSelected(); } else { clearIsBottomSelected(); } return result; }
bool EllipticalRegion::hitRightModifyPoint(const QPoint &point) { bool result = false; QPoint rightModifyPoint(getCenterPoint().x() + getMajorAxis(), getCenterPoint().y()); if (Region::distance(point, rightModifyPoint) <= SQUARE(MODIFY_POINT_RADIUS)) { result = true; setIsRightSelected(); } else { clearIsRightSelected(); } return result; }
void Palace::doLaunchDeathhand(int x, int y) { if(!isSpecialWeaponReady()) { return; } if((originalHouseID != HOUSE_HARKONNEN) && (originalHouseID != HOUSE_SARDAUKAR)) { // wrong house (see DoSpecialWeapon) return; } float randAngle = 2.0f * strictmath::pi * currentGame->randomGen.randFloat(); int radius = currentGame->randomGen.rand(0,10*TILESIZE); int deathOffX = strictmath::sin(randAngle) * radius; int deathOffY = strictmath::cos(randAngle) * radius; Coord centerPoint = getCenterPoint(); Coord dest( x * TILESIZE + TILESIZE/2 + deathOffX, y * TILESIZE + TILESIZE/2 + deathOffY); bulletList.push_back(new Bullet(objectID, ¢erPoint, &dest, Bullet_LargeRocket, PALACE_DEATHHAND_WEAPONDAMAGE, false)); soundPlayer->playSoundAt(Sound_Rocket, getLocation()); if(getOwner() != pLocalHouse) { currentGame->addToNewsTicker(_("@DUNE.ENG|81#Missile is approaching")); soundPlayer->playVoice(MissileApproaching, pLocalHouse->getHouseID()); } specialWeaponTimer = getMaxSpecialWeaponTimer(); }
void Boss::deltaTrack() { /*//add code here VECTOR2 vel = getCenterPoint()-targetEntity.getCenterPoint(); if(abs(vel.x/vel.y) > 2 && vel.x>0) else if(abs(vel.x/vel.y) > 2 && vel.x<0) else if(abs(vel.x/vel.y) > 2 && vel.x>0) setVelocity(-vel);*/ VECTOR2 vel = VECTOR2(1,1); VECTOR2 targetCenter = targetEntity.getCenterPoint(); if(getCenterPoint().y <= targetCenter.y) vel.y = -1; if(getCenterPoint().x <= targetCenter.x) vel.y = -1; VECTOR2* foo = D3DXVec2Normalize(&vel, &vel); setVelocity(-vel); }
void Boss::vectorTrack()//We're going to want to change this so that it takes an argument that is what we want to track { VECTOR2 vel = getCenterPoint()-targetEntity.getCenterPoint(); if(vel.x == 0 && vel.y==0) return; VECTOR2* foo = D3DXVec2Normalize(&vel, &vel); setVelocity(-vel); setRadians((atan((targetEntity.getCenterY()-getCenterY())/(targetEntity.getCenterX()-getCenterX())))-PI/2); if(targetEntity.getCenterX()>getCenterX()) setRadians(getRadians()+PI); }
bool CircularRegion::checkAmbit(QPoint point){ bool result = false; if (distance(point, getCenterPoint()) <= SQUARE(getRadius())) { result = true; setIsSelected(); } else { clearIsSelected(); } return result; }
void AnimationViewerPanel::setCenterPoint(QMouseEvent *event) { KeyFrameData* pKeyFrameData = mpSelectedCelModel->getKeyFrameDataReference(); if (pKeyFrameData && pKeyFrameData->mSpriteDescriptor.isImage()) { QPoint centerPoint = getCenterPoint(); int centerX = (int)(event->x() - centerPoint.x() - pKeyFrameData->mSpriteDescriptor.mPosition.mX + pKeyFrameData->mSpriteDescriptor.mCenter.mX); int centerY = (int)(event->y() - centerPoint.y() - pKeyFrameData->mSpriteDescriptor.mPosition.mY + pKeyFrameData->mSpriteDescriptor.mCenter.mY); mpSelectedCelModel->setCenterX(centerX);// / pKeyFrameData->mSpriteDescriptor.textureCenter().x()); mpSelectedCelModel->setCenterY(centerY);// / pKeyFrameData->mSpriteDescriptor.textureCenter().y()); } }
bool CircularRegion::hitRightBottomModifyPoint(const QPoint &point) { bool result = false; QPoint center = getCenterPoint(); int radius = getRadius(); QPoint rightBottomModifyPoint(center.x() + (int)(radius * cos(45 * PI / 180)), center.y() + (int)(radius * sin(45 * PI / 180))); //右下角的調整點座標 if (Region::distance(point, rightBottomModifyPoint) <= SQUARE(MODIFY_POINT_RADIUS)) { result = true; setIsRightBottomSelected(); } else { clearIsRightBottomSelected(); } return result; }
void TurretClass::attack() { if ((weaponTimer == 0) && (target.getObjPointer() != NULL)) { Coord centerPoint = getCenterPoint(); Coord targetCenterPoint = target.getObjPointer()->getClosestCenterPoint(location); bulletList.push_back( new BulletClass( objectID, ¢erPoint, &targetCenterPoint,bulletType, currentGame->objectData.data[itemID].weapondamage, target.getObjPointer()->isAFlyingUnit() ) ); soundPlayer->playSoundAt(attackSound, location); weaponTimer = weaponReloadTime; } }
bool EllipticalRegion::checkAmbit(QPoint point) { bool result = false; QPoint center = getCenterPoint(); double x = (point.x() < center.x()) ? center.x() - point.x() : point.x() - center.x(), y = (point.y() < center.y()) ? center.y() - point.y() : point.y() - center.y(); double a = getMajorAxis(), b = getMinorAxis(); if (SQUARE(x) / SQUARE(a) + SQUARE(y) / SQUARE(b) <= 1) { result = true; setIsSelected(); } else { clearIsSelected(); } return result; }
int PointCloud::getMaximumDeviation() const { Point center = getCenterPoint(); double maxDistance = 0; for (list<Point>::const_iterator it = mData->begin(); it != mData->end(); ++it) { double dist = center.calculateDistanceTo((*it)); if (dist > maxDistance) { maxDistance = dist; } } return (int) (maxDistance); }
void ReconVarIC::initialSetup() { // number of grains this ICs deals with _grain_num = _consider_phase ?_ebsd_reader.getGrainNum(_phase) : _ebsd_reader.getGrainNum(); // fetch all center points _centerpoints.resize(_grain_num); for (unsigned int index = 0; index < _grain_num; ++index) _centerpoints[index] = getCenterPoint(index); // We do not want to have more order parameters than grains. That would leave some unused. if (_op_num > _grain_num) mooseError("ERROR in PolycrystalReducedIC: Number of order parameters (op_num) can't be larger than the number of grains (grain_num)"); // Assign grains to each order parameter in a way that maximizes distance _assigned_op.resize(_grain_num); _assigned_op = PolycrystalICTools::assignPointsToVariables(_centerpoints, _op_num, _mesh, _var); }
void AnimationViewerPanel::paintEvent(QPaintEvent *event) { if (mIsAnimationPlaying && !refreshed){return;} refreshed = false; // Get center point, all cel position should be relative to this QPoint centerPoint = getCenterPoint(); // Start painter QPainter painter(this); // clear screen painter.setPen(Qt::black); painter.setBrush(Qt::NoBrush); painter.fillRect(QRect(0, 0, width() - 1, height() - 1), Qt::SolidPattern); if (mShowAnimationUI) { renderCross(painter); } renderCelSprites(centerPoint, painter); if (mShowAnimationUI) { renderTargetSprite(centerPoint, painter);} painter.end(); }
void AnimationViewerPanel::mouseMoveEvent(QMouseEvent *event) { QPoint centerPoint = getCenterPoint(); int newPosX = event->x() - centerPoint.x() + mSelectedOffset.x(); int newPosY = event->y() - centerPoint.y() + mSelectedOffset.y(); KeyFrameData* pKeyFrameData = mpSelectedCelModel->getKeyFrameDataReference(); if (event->modifiers() & Qt::ControlModifier) { setCenterPoint(event); } else if (mCelGrabbed) { // Move cel if it is selected if (pKeyFrameData) { const KeyFrame::KeyFramePosition& keyframePosition = mpAnimationModel->getCurrentKeyFramePosition(); if (pKeyFrameData->mSpriteDescriptor.mPositionType != GLSprite::PositionType_None) { newPosX -= (int)mpAnimationModel->getTargetSprite()->mSpriteDescriptor.mPosition.mX; newPosY -= (int)mpAnimationModel->getTargetSprite()->mSpriteDescriptor.mPosition.mY; } if(keyframePosition.mLineNo == AnimationModel::LINE_target) { newPosX -= AnimationModel::TARGET_originX; newPosY -= AnimationModel::TARGET_originY; } mpSelectedCelModel->setPositionX(newPosX); mpSelectedCelModel->setPositionY(newPosY); } } else if (mTargetGrabbed) { mpAnimationModel->setTargetSpritePosition(newPosX, newPosY); refresh(); } }
void Circle::makeMove(DirectionMoveType direction) { Point centerPoint = getCenterPoint(); bool needUpdate = true; switch (direction) { case kUpDirectionMove: { centerPoint.y++; break; } case kDownDirectionMove: { centerPoint.y--; break; } case kRightDirectionMove: { centerPoint.x++; break; } case kLeftDirectionMove: { centerPoint.x--; break; } default: { needUpdate = false; break; } } if (needUpdate) { setCenterPoint(centerPoint); } }
void EllipticalRegion::move(int distanceX, int distanceY) { Region::move(distanceX, distanceY); setCenter(QPoint(getCenterPoint().x() + distanceX, getCenterPoint().y() + distanceY)); }
void Mesh::subDivide() { Mesh newMesh = *this; // Maybe have to write a copy constructor for this to work as we would like //All vertices that were in the original mesh are stored in the oldVertices vector //to give us a reference for what vertices will be moved later on std::vector<Vertex*> oldVertices; for (int i = 0; i < newMesh.halfEdges.size(); i++) oldVertices.push_back(newMesh.halfEdges[i].vertex); //This will be filled as new vertices are created so that we can ensure that these vertices are pointing //to the correct half-edge at the end. //std::vector<Vertex*> newVertices; /* Next we find the center points of each face by averaging the positions of all the vertices that make up the face. Store that center vertex as a temporary member of the face. */ for (int i = 0; i < newMesh.faces.size(); i++) { Face* currentFace = &newMesh.faces[i]; Vertex centerVertex = getCenterPoint(currentFace); currentFace->centerPoint = ¢erVertex; /********** I foresee a problem with centerPoint being added to the vertex but then going out of scope so now the vector just sees a junk vertex. */ } /* Next create all new vertices that will lay on the current edges. These vertices are given a position (obviously), and a halfEdge. The halfedge that the vertex points to is the halfedge that it lies on. The halfEdge that the vertex lies on also is given a temporary pointer to that vertex as well. */ /*********** NOTE: Remember to change the new vertices to contain a pointer to the halfedge = halfedge->next->sym (where halfedge is the original halfedge that pointed to the vertex) **/ for (int i = 0; i < newMesh.halfEdges.size(); i++) { Vertex edgeVertex; if (newMesh.halfEdges[i].halfVertex != NULL || newMesh.halfEdges[i].sym->halfVertex != NULL) continue; //if the half edge already has a vertex there. /************If Sym can never be null, then there will always be 4 points at the center of a face (Erase the else)**/ if (halfEdges[i].sym != NULL) { //average vertices on all four sides of half edge Vertex v1 = *newMesh.halfEdges[i].vertex; Vertex v2 = *getPreviousVertex(&newMesh.halfEdges[i]); Vertex v3 = *newMesh.halfEdges[i].face->centerPoint; Vertex v4 = *newMesh.halfEdges[i].sym->face->centerPoint; edgeVertex.pos = (v1.pos + v2.pos + v3.pos + v4.pos) / 4.0f; //MIGHT NOT NEED THIS ELSE IF THERE WILL NEVER BE A NULL "SYM" }else { //outer half edge //Only use vertices on either side of the halfedge Vertex v1 = *newMesh.halfEdges[i].vertex; Vertex v2 = *getPreviousVertex(&newMesh.halfEdges[i]); edgeVertex.pos = (v1.pos + v2.pos)/2.0f; } //A vertex needs to store a position and a halfEdge edgeVertex.halfEdge = &newMesh.halfEdges[i]; //add a halfedge to the vertex newMesh.halfEdges[i].halfVertex = &edgeVertex; //add the vertex to the halfedge (temporarily) newMesh.halfEdges[i].sym->halfVertex = &edgeVertex; //add the vertex to the halfedge's sym (temporarily) //store the two faces for this in the face's newVertices vector edgeVertex.halfEdge->face->newVertices.push_back(&edgeVertex); edgeVertex.halfEdge->sym->face->newVertices.push_back(&edgeVertex); //how do i set it for a face, when we're looping through half edges? /****** I foresee a problem with adding edgeVertex to the vector and then it going out of scope so the vector is left pointing at a junk vertex. */ } /* Next create the halfedges that will border the existing faces (Halfedges that go from the original vertices to the edge half-vertices). In this step, no halfedges will be created that go from the center of the face out to the edges. That comes later (after creating the faces). */ for (int i = 0; i < newMesh.faces.size(); i++) { HalfEdge* firstHe = newMesh.faces[i].halfEdge; //For each halfedge around the face. for (HalfEdge* originalHe = firstHe; originalHe->next != firstHe; originalHe = originalHe->next) { HalfEdge newHalfEdge = *originalHe; //Create halfedge identical to this halfedge //add it to newMesh newMesh.halfEdges.push_back(newHalfEdge); newHalfEdge.halfVertex = NULL; //clear the new halfedge's halfvertex. Only the original needs it. //I foresee a problem with this HE going out of scope and so all the information is borked. //Update all the original half-edge data members to reference the new halfedge that is placed in // front of it. originalHe->vertex->halfEdge = &newHalfEdge; originalHe->vertex = originalHe->halfVertex; originalHe->halfVertex = NULL; originalHe->next = &newHalfEdge; originalHe->sym = originalHe->next->sym->next; originalHe->face = originalHe->face; //Keep the same for now. } } /* Next create all the new faces that will be inside the original face. These faces will take the place of the one big face. At the end of this, make sure to set the originalFace->centerPoint equal to NULL. Don't forget to add a normal equal to the normal of the original face as well. Also set newVertices to null for all faces */ /*********** NOTE: Remember to change the new vertices to contain a pointer to the halfedge = halfedge->next->sym (where halfedge is the original halfedge that pointed to the vertex) **/ std::vector<Face*> newFaces; for (int i = 0; i < newMesh.faces.size(); i++) { //first create vector of new faces for(int j=0; j<newMesh.faces[i].newVertices.size(); j++) { Face* face; newFaces.push_back(face); } //first set the first HE you start at to point to face 1 (newFaces[0]) in the newFaces vec newMesh.faces[i].halfEdge->face = newFaces[0]; //set newFaces[0]'s HE to this first HE newFaces[0]->halfEdge = newMesh.faces[i].halfEdge; HalfEdge* firstHe = newMesh.faces[i].halfEdge; HalfEdge* iterator = newMesh.faces[i].halfEdge; for(int j=1; j<newMesh.faces[i].newVertices.size(); j++) { //go to next HE, set face to newFaces[i] iterator = iterator->next; iterator->face = newFaces[i]; //go to next HE, set face to newFaces[i] iterator = iterator->next; iterator->face = newFaces[i]; //set newFaces[i]'s HE to this HE newFaces[i]->halfEdge = iterator; newFaces[i]->normal = newMesh.faces[i].normal; newFaces[i]->centerPoint = NULL; } //set last one to face 1 -- the next one should now be the first one iterator = iterator->next; iterator->face = newFaces[0]; //NOW WE WILL CREATE THE NEW HE's for this face that are between the center point and the new vertices //temp vector of HE's that point out from middle to be used for connecting "nexts" std::vector<HalfEdge*> outwardHEs; std::vector<HalfEdge*> inwardHEs; for(int j = 0; j < newMesh.faces[i].newVertices.size(); j++) { //he1 and he2 are down and up HalfEdge he1(newMesh.faces[i].centerPoint, NULL, NULL, newFaces[j]); //face to the left -- NOT SURE IF THIS IS RIGHT FACE -- now face to the right.....now clap your hands HalfEdge he2(newMesh.faces[i].newVertices[j], NULL, &he1, newFaces[(j+1)%newMesh.faces[i].newVertices.size()]);//face to the right newMesh.faces[i].newVertices[j]->halfEdge = &he2; //add them to newMesh newMesh.halfEdges.push_back(he1); newMesh.halfEdges.push_back(he2); outwardHEs.push_back(&he2); inwardHEs.push_back(&he1); he1.sym = &he2; //loop through all outer HE, comparing their "vertex" to newVertices[j] //he2.next will equal THAT one's next for (HalfEdge* originalHe = firstHe; originalHe->next != firstHe; originalHe = originalHe->next) { if(newMesh.faces[i].halfEdge->vertex == newMesh.faces[i].newVertices[j]) he2.next = newMesh.faces[i].halfEdge->next; //else major error } //for all the new faces, set the remaining unconnected "next" HE to be connected //This assumes that the first halfedge of a face matches up with the first item in the inwardHEs. for(int k=0; k<newFaces.size(); k++) { newFaces[i]->halfEdge->next = inwardHEs[i]; } int temp = j; if((temp-1) < 0) temp = newMesh.faces[i].newVertices.size()-1; he1.next = outwardHEs[temp]; newMesh.faces[i].centerPoint->halfEdge = &he1; } } /* By this point, the mesh should be in a state where it has been completely subdivided. All new vertices have been added, all new halfedges have been added, all new faces have been added. */ /* Next, move all original vertices. Do this by looping through the vector of original vertices, and move their positions to the average of the four surrounding vertices. The four surrounding vertices are the vertices that were created in the center of the edge during this CC iteration. */ for (int i = 0; i < oldVertices.size(); i++) { Vertex* vert = oldVertices[i]; Vertex v1 = *getPreviousVertex(vert->halfEdge); //Beneath Vertex v2 = *vert->halfEdge->next->vertex; //Right Vertex v3 = *vert->halfEdge->next->sym->next->vertex; //Up Vertex v4 = *vert->halfEdge->next->sym->next->sym->next->vertex;//Left vec3 newPos = (v1.pos+v2.pos+v3.pos+v4.pos)/4.0f; vert->pos = newPos; } //LEFT TO UPDATE IN NEWMESH: //faces, as well as their normals, halfEdge, centerPoint -- DONE //vertices, as well as their pos, halfEdge -- DONE //halfEdges, as well as their vertex, next, sym, face, halfVertex -- not sure //update newMesh's faces newMesh.faces.clear(); for(int i=0; i<newFaces.size(); i++) { newMesh.faces.push_back(*newFaces[i]); } //update newMesh's vertices //run through all OLD faces, getting the "newVertices" AND centerPoint for that face and adding that to newMesh's vertices along with old vertices...? for(int i=0; i<this->faces.size(); i++) { for(int j=0; j<this->faces[i].newVertices.size(); j++) newMesh.vertices.push_back(*this->faces[i].newVertices[j]); newMesh.vertices.push_back(*this->faces[i].centerPoint); } //Finally, overwrite THIS mesh to be equal to the mesh that we just created! *this = newMesh; }
QPoint EllipticalRegion::getStartPoint(void) { return getCenterPoint(); }
void CircleObject::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent) { setCenterPoint(getCenterPoint() + pTouch->getDelta()); drawCircle(false); }
/////////////////////////////////////////////////////////// // // Calculate the rectancle to use to draw the image // /////////////////////////////////////////////////////////// void view::updateImageRect(imbxInt32 centerPointX, imbxInt32 centerPointY) { imbxInt32 tempCenterPointX = 0; imbxInt32 tempCenterPointY = 0; getCenterPoint(&tempCenterPointX, &tempCenterPointY); if(centerPointX < 0) centerPointX = tempCenterPointX; if(centerPointY < 0) centerPointY = tempCenterPointY; imbxInt32 leftPosition, topPosition, rightPosition, bottomPosition; leftPosition= topPosition= rightPosition= bottomPosition = 0; // Get the window's size /////////////////////////////////////////////////////////// imbxUint32 windowSizeX = 0; imbxUint32 windowSizeY = 0; getWindowSize(&windowSizeX, &windowSizeY); // Get the scroll size /////////////////////////////////////////////////////////// imbxUint32 scrollSizeX = 0; imbxUint32 scrollSizeY = 0; getScrollSize(&scrollSizeX, &scrollSizeY); // Get the scroll position /////////////////////////////////////////////////////////// imbxInt32 scrollPosX = 0; imbxInt32 scrollPosY = 0; getScrollPosition(&scrollPosX, &scrollPosY); // For now, the new scroll size and position are the same // as the old ones /////////////////////////////////////////////////////////// imbxUint32 newScrollSizeX=scrollSizeX; imbxUint32 newScrollSizeY=scrollSizeY; if(m_originalImage != 0) { imbxUint32 imageSizeX(0), imageSizeY(0); m_originalImage->getSize(&imageSizeX, &imageSizeY); // Retrieve the screen's resolution /////////////////////////////////////////////////////////// imbxUint32 screenHorzDPI, screenVertDPI; screenHorzDPI=screenVertDPI=75; getScreenDPI(&screenHorzDPI, &screenVertDPI); // Get the image's size (in mms and pixels) /////////////////////////////////////////////////////////// double imageSizeMmX = 0; double imageSizeMmY = 0; m_originalImage->getSizeMm(&imageSizeMmX, &imageSizeMmY); if(imageSizeMmX == 0) { imageSizeMmX = (double)imageSizeX * 25.4 / (double)screenHorzDPI; } if(imageSizeMmY == 0) { imageSizeMmY = (double)imageSizeY * 25.4 / (double)screenVertDPI; } // Calculate the area occupied by the image, in screen's // pixels /////////////////////////////////////////////////////////// imbxUint32 displayAreaWidth=(imbxUint32)((double)imageSizeMmX*m_zoom*(double)screenHorzDPI/25.4+0.5); imbxUint32 displayAreaHeight=(imbxUint32)((double)imageSizeMmY*m_zoom*(double)screenVertDPI/25.4+0.5); if(displayAreaWidth>windowSizeX) { rightPosition = displayAreaWidth; } else { leftPosition = (windowSizeX-displayAreaWidth)>>1; rightPosition = leftPosition+displayAreaWidth; } if(displayAreaHeight>windowSizeY) { bottomPosition = displayAreaHeight; } else { topPosition = (windowSizeY-displayAreaHeight)>>1; bottomPosition = topPosition+displayAreaHeight; } newScrollSizeX = displayAreaWidth; newScrollSizeY = displayAreaHeight; }
void AnimationViewerPanel::refresh() { if (!isAnimationPlaying() || isAnimationExist()) { refreshed = true; clearSprites(); } if (!isAnimationPlaying()) { float targetX = mpAnimationModel->getTargetSprite()->mSpriteDescriptor.mPosition.mX; float targetY = mpAnimationModel->getTargetSprite()->mSpriteDescriptor.mPosition.mY; QPoint centerPoint = getCenterPoint(); if (targetX < -centerPoint.x()){targetX = -centerPoint.x();} if (targetX > centerPoint.x()){targetX = centerPoint.x();} if (targetY < -centerPoint.y()){targetY = -centerPoint.y();} if (targetY > centerPoint.y()){targetY = centerPoint.y();} mpAnimationModel->setTargetSpritePosition(targetX, targetY); // set cel reference KeyFrame::KeyFramePosition keyframePosition = mpAnimationModel->getCurrentKeyFramePosition(); KeyFrame* pKeyframe = mpAnimationModel->getKeyFrame(keyframePosition.mLineNo, keyframePosition.mFrameNo); if (pKeyframe) { mpSelectedCelModel->setKeyFrameDataReference(pKeyframe->mpKeyFrameData); emit celSelected(pKeyframe->mpKeyFrameData); } else { mpSelectedCelModel->setKeyFrameDataReference(NULL); emit celSelected(NULL); } } // Update target info GLSprite* pTargetMonsterSprite = mpAnimationModel->createGLSpriteAt(NULL, mpAnimationModel->getCurrentKeyFramePosition().mFrameNo, AnimationModel::LINE_target); if (pTargetMonsterSprite) { if (pTargetMonsterSprite->mLineNo == AnimationModel::LINE_target) { GLSprite::Point2 pt = spTargetSprite->mSpriteDescriptor.mPosition; pt.mX = pTargetMonsterSprite->mSpriteDescriptor.mPosition.mX + AnimationModel::TARGET_originX; pt.mY = pTargetMonsterSprite->mSpriteDescriptor.mPosition.mY + AnimationModel::TARGET_originY; spTargetSprite->mSpriteDescriptor.mPosition = pt; //spTargetSprite->mSpriteDescriptor.mTextureSrcRect = pTargetMonsterSprite->mSpriteDescriptor.mTextureSrcRect; spTargetSprite->mSpriteDescriptor.mCenter.mX = 0; spTargetSprite->mSpriteDescriptor.mCenter.mY = 0; } delete pTargetMonsterSprite; } mGlSpriteList = mpAnimationModel->createGLSpriteListAt(NULL, mpAnimationModel->getCurrentKeyFramePosition().mFrameNo); mRenderSpriteList.append(mGlSpriteList); for (int lineNo = 0; lineNo < AnimationModel::LINE_COUNT; lineNo++) { for (int i = mEmittedAnimationList[lineNo].count() - 1; i >= 0; i--) { mRenderSpriteList.push_back(mEmittedAnimationList[lineNo][i]->getSprite()); } } qSort(mRenderSpriteList.begin(), mRenderSpriteList.end(), GLSprite::priorityLessThan); repaint(); }
void AnimationViewerPanel::mousePressEvent(QMouseEvent *event) { this->setFocus(); // Get center point here QPoint centerPoint = getCenterPoint(); // Calculate pressed position relative from center QPoint relativePressedPosition = QPoint(event->x(), event->y()) - centerPoint; mTargetGrabbed = false; mCelGrabbed = false; // only for edit mode if (!mIsAnimationPlaying) { // center point mode if (event->modifiers() & Qt::ControlModifier) { setCenterPoint(event); return; } grabCel(relativePressedPosition); if(!mCelGrabbed) { QString path1 = mpAnimationModel->getLoadedAnimationPath(); QString path2 = mpAnimationModel->getSelectedSourcePath(); if (mpAnimationModel->getLoadedAnimationPath() == mpAnimationModel->getSelectedSourcePath()) { QMessageBox::information(window(), tr("Animation nest error"), tr("You cannot nest the same animation")); } else { KeyFrame::KeyFramePosition currentPosition = mpAnimationModel->getCurrentKeyFramePosition(); switch(ResourceManager::getFileType(mpAnimationModel->getSelectedSourcePath())) { case ResourceManager::FileType_Animation: case ResourceManager::FileType_Image: if (mpAnimationModel->getKeyFrameIndex(currentPosition.mLineNo, currentPosition.mFrameNo) == -1) { GLSprite::Point2 pt; pt.mX = relativePressedPosition.x(); pt.mY = relativePressedPosition.y(); mpAnimationModel->setKeyFrame(currentPosition.mLineNo, currentPosition.mFrameNo, pt); } else { if (event->modifiers() & Qt::ShiftModifier) { swapSourceTexture(); } } break; default: break; } } } } if (!mCelGrabbed) { grabTarget(relativePressedPosition); } }
void UnitBase::attack() { if(numWeapons) { Coord targetCenterPoint; Coord centerPoint = getCenterPoint(); bool bAirBullet; if(target.getObjPointer() != NULL) { targetCenterPoint = target.getObjPointer()->getClosestCenterPoint(location); bAirBullet = target.getObjPointer()->isAFlyingUnit(); } else { targetCenterPoint = currentGameMap->getTile(attackPos)->getCenterPoint(); bAirBullet = false; } int currentBulletType = bulletType; Sint32 currentWeaponDamage = currentGame->objectData.data[itemID][originalHouseID].weapondamage; if(getItemID() == Unit_Trooper) { // Troopers change weapon type depending on distance float distance = distanceFrom(centerPoint, targetCenterPoint); if(distance > 2*TILESIZE) { currentBulletType = Bullet_SmallRocket; } } if(primaryWeaponTimer == 0) { bulletList.push_back( new Bullet( objectID, ¢erPoint, &targetCenterPoint, currentBulletType, currentWeaponDamage, bAirBullet) ); playAttackSound(); primaryWeaponTimer = getWeaponReloadTime(); secondaryWeaponTimer = 15; if(attackPos && getItemID() != Unit_SonicTank && currentGameMap->getTile(attackPos)->isSpiceBloom()) { setDestination(location); forced = false; attackPos.invalidate(); } // shorten deviation time if(deviationTimer > 0) { deviationTimer = std::max(0,deviationTimer - MILLI2CYCLES(20*1000)); } } if((numWeapons == 2) && (secondaryWeaponTimer == 0) && (isBadlyDamaged() == false)) { bulletList.push_back( new Bullet( objectID, ¢erPoint, &targetCenterPoint, currentBulletType, currentWeaponDamage, bAirBullet) ); playAttackSound(); secondaryWeaponTimer = -1; if(attackPos && getItemID() != Unit_SonicTank && currentGameMap->getTile(attackPos)->isSpiceBloom()) { setDestination(location); forced = false; attackPos.invalidate(); } // shorten deviation time if(deviationTimer > 0) { deviationTimer = std::max(0,deviationTimer - MILLI2CYCLES(20*1000)); } } } }
QVector<Vertex> SimpleFilter::findQrCode( const QVector<CvSeq *> &contours ) { QVector<Vertex> qrCodes; if(contours.size()<3) return qrCodes; for( int indx=0; indx<contours.size()-2; indx++ ) { for( int indx2=indx+1; indx2<contours.size()-1; indx2++ ) { for( int indx3=indx2+1; indx3<contours.size(); indx3++ ) { bool find=false; CvPoint cp1,cp2,cp3; cp1=getCenterPoint( contours[indx] ); cp2=getCenterPoint( contours[indx2] ); cp3=getCenterPoint( contours[indx3] ); double lenght1 = 0, lenght2 = 0, lenght3 = 0; lenght1=getLenghtLine( cp1, cp2 ); lenght2=getLenghtLine( cp2, cp3 ); lenght3=getLenghtLine( cp1, cp3 ); lenght1=pow( lenght1, 2 ); lenght2=pow( lenght2, 2 ); lenght3=pow( lenght3, 2 ); if( lenght1 > lenght2 && lenght1 > lenght3 ) { find = isEquilateralTriangle( lenght1, lenght2, lenght3 ); } else if( lenght2 > lenght1 && lenght2 > lenght3 ) { find = isEquilateralTriangle( lenght2, lenght1, lenght3 ); } else if( lenght3 > lenght1 && lenght3 > lenght1 ) { find = isEquilateralTriangle( lenght3, lenght1, lenght2 ); } if( !find ) return qrCodes; Vertex buf; buf.con1 = contours[indx]; buf.con2 = contours[indx2]; buf.con3 = contours[indx3]; buf.p1 = cp1; buf.p2 = cp2; buf.p3 = cp3; qrCodes.push_back( buf ); } } } return qrCodes; }
void Circle::printContent() const { Point centerPoint = getCenterPoint(); printf(kPrintContentFormatString, centerPoint.x, centerPoint.y, getRadius()); }