void Rotator::Move(ivec2 location) { vec3 start = MapToSphere(m_fingerStart); vec3 end = MapToSphere(location); Quaternion delta = Quaternion::CreateFromVectors(start, end); m_orientation = delta.Rotated(m_prevOrientation); }
inline void onTouchMove(int ix, int iy) { if (m_spinning) { vec3 start = MapToSphere(m_fingerStart); vec3 end = MapToSphere(vec2(ix,iy)); CQuaternion delta = CQuaternion::CreateFromVectors(start, end); m_orientation = delta.Rotated(m_prevOrientation); } }
void ApplicationEngine::OnFingerMove(ivec2 oldLocation, ivec2 location) { if (m_spinning) { vec3 start = MapToSphere(m_fingerStart); vec3 end = MapToSphere(location); Quaternion delta = Quaternion::CreateFromVectors(start, end); m_orientation = delta.Rotated(m_previousOrientation); } }
inline void processTouches(int command, int x, int y) { switch (command) { case CMD_TOUCH_END2: touch2.clear(); nFingers--; break; case CMD_TOUCH_START2: touch2.x = x; touch2.y = y; oldlen = touch2.subtract(touch2, touch1).length(); m_spinning = false; nFingers++; break; case CMD_TOUCHMOVE2: touch2.x = x; touch2.y = y; m_spinning = false; break; case CMD_TOUCHMOVE: { if (m_spinning && !isPinching()) { start = MapToSphere(m_fingerStart); end = MapToSphere(vec2(x,y)); delta = CQuaternion::CreateFromVectors(start, end); m_orientation = delta.Rotated(m_prevOrientation); } } break; case CMD_TOUCH_START: touch1.x = x; touch1.y = y; onTouchDown(x,y); nFingers++; break; case CMD_TOUCH_END: touch1.x = x; touch1.y = y; onTouchUp(x,y); touch1.clear(); touch2.clear(); m_spinning = false; nFingers--; break; case CMD_SCREENSIZE: touch1.x = x; touch1.y = y; onScreenSize(x,y); break; } }
void Trackball<Real>::BeginTracking(int x, int y) { startVector = Celer::Vector3<Real>(Real(x), Real(y), 0); startOrientation = mOrientation; MapToSphere(startVector); }
void Trackball<Real>::Tracking(int x, int y) { Celer::Quaternion<Real> q; Celer::Vector3<Real> endVector(Real(x), Real(y), 0); MapToSphere(endVector); q.ToRotationArc(startVector, endVector); mOrientation = q * startOrientation; //mOrientation.Normalize(); }
void Arcball::Drag(const Point3f* _point, Quaternion* qNewRotation) { MapToSphere(_point, &endVector); if(qNewRotation) { Vector3f vPerpendicular; //compute the vector perpendicular to the begin and end vectors vPerpendicular = Vector3f::Cross(&startVector, &endVector); //compute the length of the perpendicular vecotr if(vPerpendicular.Magnitude() > 0) { //return the perpendicular vector as the transform *qNewRotation = Quaternion(vPerpendicular.X(), vPerpendicular.Y(), vPerpendicular.Z(), Vector3f::Dot(&startVector, &endVector)); } else { //the begin and end vectors coincide, so return an identity transform *qNewRotation = Quaternion(0, 0, 0, 0); } } }
void Arcball::Click(const Point3f* _point) { MapToSphere(_point, &startVector); }
/* * Creates a new planet and appends it to planetsList */ void CreatePlanet(struct PlanetStruct planet, GLuint playSound) { if(numberOfPlanets < maxNumberOfPlanets || maxNumberOfPlanets == 0) { numberOfPlanets++; planetsList = realloc(planetsList, sizeof(struct PlanetStruct)*numberOfPlanets); planet.startingPosition = planet.center; planet.timeOfCreation = glutGet(GLUT_ELAPSED_TIME); planet.upVec = SetVector(0,1,0); planet.frontVec = SetVector(0,0,1); mat4 terrainTransformationMatrix[6]; TextureData* terrainTextures[6]; CreateCubeHeightMaps(terrainTextures, terrainTransformationMatrix, &planet); //Generate terrain /* TextureData* tex = chkmalloc(sizeof(TextureData)); GenerateProceduralTerrainTexture(256, tex); terrainTextures[0] = tex;*/ GLuint i; for(i = 0; i < 6; i++) { planet.terrainModels[i] = GenerateTerrainModelSimple(terrainTextures[i], planet.textureScale); switch(planet.type) { case SMOOTH_PLANET: planet.terrainModels[i] = MapToFlatSphere(planet, terrainTransformationMatrix, terrainTextures[i], i); break; case ROUGH_PLANET: planet.terrainModels[i] = MapToSphere(planet, terrainTransformationMatrix, terrainTextures[i], i); break; case CUBE_PLANET: planet.terrainModels[i] = MapToCube(planet, terrainTransformationMatrix, terrainTextures[i], i); break; default: fprintf(stderr, "Unknown planet type"); } deleteTexture(terrainTextures[i]); //Dont need them in memory anymore, free properly } planet.ModelToWorldMatrix = T(planet.center.x, planet.center.y, planet.center.z); planetsList[numberOfPlanets-1] = planet; //Decide if/what sound to play if(playSound != NO_SOUND) PlayAudioFile(createPlanetNoise); printf("Let there be light!\n"); } else { //Play fail noise? fprintf(stderr, "Max number of planets reached\n"); } }