Vector3f DragManipulator::GetCenterPosition() const { // Calculate the center of the group of object. Vector3f centerPosition(0, 0, 0); std::list<Entity*>::const_iterator itEntity; for(itEntity = mEntities.begin(); itEntity != mEntities.end(); ++itEntity) centerPosition += (*itEntity)->GetPosition(); return centerPosition / mEntities.size(); }
void PlayerComponent::draw(float dt) { _drawPointNode->clear(); _drawLineNode->clear(); if (is_onTouch) { Vec2 centerPosition(_player->getBoundingBox().size.width, _player->getBoundingBox().size.height); Vec2 destination = (_touchPosition - _movements->getPoint()) * (1 / _player->getScale()) + centerPosition; _drawPointNode->drawPoint(destination, 15, Color4F(0.0, 1.0, 0.0, 1.0)); _drawLineNode->drawLine(centerPosition, destination, Color4F(1.0, 1.0, 1.0, 1.0)); } }
//--------------------------------------------------------------------------- void Clouds::update (void) { renderClouds = false; scrollU += frameLength * SCROLL_U_FACTOR; scrollV += frameLength * SCROLL_V_FACTOR; if (scrollU > 1.0f) scrollU -= 1.0f; if (scrollV > 1.0f) scrollV -= 1.0f; if (scrollU < -1.0f) scrollU += 1.0f; if (scrollV < -1.0f) scrollV += 1.0f; //--------------------------------------------------------------------- // If projectionAngle is less then some magic number, draw the clouds. // Otherwise, do not do anything! if (eye->active && eye->usePerspective && (eye->getProjectionAngle() < MAX_CLOUDS_ANGLE)) { //renderClouds = true; //------------------------------------------------------- // Create the cloud grid based on camera CENTER position. Stuff::Vector3D centerPosition(eye->getPosition()); //------------------------------------------------------- // Create a topLeft vertex float tLeftX = centerPosition.x + MAX_CLOUDS_SIZE; float tLeftY = centerPosition.y + MAX_CLOUDS_SIZE; //------------------------------------------------------- // Create the grid. long cloudInc = float2long(MAX_CLOUDS_SIZE * 2.0f / gridSize); float uvInc = MAX_UV_REPEAT / float(gridSize); for (long y=0;y<gridSize;y++) { for (long x=0;x<gridSize;x++) { cloudVertices[x + (y*gridSize)].vx = tLeftX - (cloudInc * x); cloudVertices[x + (y*gridSize)].vy = tLeftY - (cloudInc * y); cloudVertices[x + (y*gridSize)].pu = CLOUD_START_U + (uvInc * x); cloudVertices[x + (y*gridSize)].pv = CLOUD_START_V + (uvInc * y); } } //------------------------------------------------------- // Transform Grid long gridTotal = gridSize * gridSize; for (long i=0;i<gridTotal;i++) { //---------------------------------------------------------------------------------------- // Figure out if we are in front of camera or not. Should be faster then actual project! // Should weed out VAST overwhelming majority of vertices! bool onScreen = true; //----------------------------------------------------------------- // Find angle between lookVector of Camera and vector from camPos // to Target. If angle is less then halfFOV, object is visible. //------------------------------------------------------------------- // Then figure out if FarClipped. Should weed out a boatload more! float hazeFactor = 0.0f; Stuff::Point3D Distance; Stuff::Point3D vPosition; Stuff::Point3D eyePosition(eye->getPosition()); vPosition.x = cloudVertices[i].vx;; vPosition.y = cloudVertices[i].vy; vPosition.z = centerPosition.z; Distance.Subtract(eyePosition,vPosition); float eyeDistance = Distance.GetApproximateLength(); if (eyeDistance > Camera::MaxClipDistance) { hazeFactor = 1.0f; //onScreen = false; } else if (eyeDistance > Camera::MinHazeDistance) { hazeFactor = (eyeDistance - Camera::MinHazeDistance) * Camera::DistanceFactor; } else { hazeFactor = 0.0f; } //------------------------------------------------------------ // Calculate the HazeDWORD here if (hazeFactor != 0.0f) { float fogFactor = 1.0 - hazeFactor; DWORD distFog = float2long(fogFactor * 255.0f); cloudVertices[i].fogRGB = (distFog<<24) + (0xffffff); } else { cloudVertices[i].fogRGB = 0xffffffff; } if (onScreen) { Stuff::Vector3D Distance; Stuff::Point3D objPosition; Stuff::Point3D eyePosition(eye->getCameraOrigin()); objPosition.x = -cloudVertices[i].vx; objPosition.y = CLOUD_ALTITUDE; objPosition.z = cloudVertices[i].vy; Distance.Subtract(objPosition,eyePosition); Distance.Normalize(Distance); float cosine = Distance * eye->getLookVector(); if (cosine > eye->cosHalfFOV) onScreen = true; else onScreen = false; } else { hazeFactor = 1.0f; } Stuff::Vector3D vertex3D(cloudVertices[i].vx,cloudVertices[i].vy,(CLOUD_ALTITUDE+eye->getCameraOrigin().y)); Stuff::Vector4D screenPos; bool inView = eye->projectZ(vertex3D,screenPos); cloudVertices[i].px = screenPos.x; cloudVertices[i].py = screenPos.y; cloudVertices[i].pz = screenPos.z; cloudVertices[i].pw = screenPos.w; //------------------------------------------------------------ // Fix clip. Vertices can all be off screen and triangle // still needs to be drawn! cloudVertices[i].clipInfo = onScreen && inView; //------------------------------------------------------------ // Still need to scrollUVs here! cloudVertices[i].pu += scrollU; cloudVertices[i].pv += scrollV; } for (y=0;y<(gridSize-1);y++) { for (long x=0;x<(gridSize-1);x++) { CloudVertexPtr cloudVertex0 = &(cloudVertices[x + (y *gridSize)]); CloudVertexPtr cloudVertex1 = &(cloudVertices[(x+1) + (y *gridSize)]); CloudVertexPtr cloudVertex2 = &(cloudVertices[(x+1) + ((y+1)*gridSize)]); CloudVertexPtr cloudVertex3 = &(cloudVertices[x + ((y+1)*gridSize)]); bool clipCheck = (cloudVertex0->clipInfo || cloudVertex1->clipInfo || cloudVertex2->clipInfo); if (clipCheck && ((cloudVertex0->pz < 1.0f) && (cloudVertex0->pz > 0.0f) && (cloudVertex1->pz < 1.0f) && (cloudVertex1->pz > 0.0f) && (cloudVertex2->pz < 1.0f) && (cloudVertex2->pz > 0.0f))) { mcTextureManager->addTriangle(mcTextureNodeIndex,MC2_DRAWALPHA); } clipCheck = (cloudVertex0->clipInfo || cloudVertex2->clipInfo || cloudVertex3->clipInfo); if (clipCheck && ((cloudVertex0->pz < 1.0f) && (cloudVertex0->pz > 0.0f) && (cloudVertex2->pz < 1.0f) && (cloudVertex2->pz > 0.0f) && (cloudVertex3->pz < 1.0f) && (cloudVertex3->pz > 0.0f))) { mcTextureManager->addTriangle(mcTextureNodeIndex,MC2_DRAWALPHA); } } } } }
QRectF Ball::boundingRect() const { return centerPosition(ballWidth,ballHeight); }