void resetCamera() { mLookAt=STVector3(0.f,0.f,0.f); mPosition=STVector3(0.f,5.f,15.f); mUp=STVector3(0.f,1.f,0.f); SetUpAndRight(); }
bool circleEmitter::addParticle(){ particle *newParticle; float speed; //Particle pool exists and max num particles not exceeded if(e != NULL && *managerParticleList != NULL && e->particleCount < e->totalParticles && emitting){ newParticle = *managerParticleList; *managerParticleList = (*managerParticleList)->next; if(e->particleList != NULL){ e->particleList->prev = newParticle; } newParticle->next = e->particleList; newParticle->prev = NULL; e->particleList = newParticle; float angle = randomAngle(); float radScalar = randDist(); newParticle->rand = radScalar; newParticle->radius = radius * radScalar; STVector3 point = STVector3(radius*radScalar*cosf(angle), 0, radius*radScalar*sinf(angle)); STVector3 straightUp = STVector3(0,1,0); STVector3 circleDir = STVector3(e->dir.x, e->dir.y, e->dir.z); STVector3 a = STVector3::Cross(straightUp, circleDir); float w = sqrt(powf(straightUp.Length(), 2) * powf(circleDir.Length(), 2)) + STVector3::Dot(straightUp, circleDir); Quaternion rotateCircle = Quaternion(w, a.x, a.y, a.z); rotateCircle.Normalize(); STVector3 rotatedPoint = rotateCircle.rotate(point, rotateCircle); newParticle->pos.x = rotatedPoint.x + e->pos.x; newParticle->pos.y = rotatedPoint.y + e->pos.y; newParticle->pos.z = rotatedPoint.z + e->pos.z; /* newParticle->pos.x = e->pos.x + radius*sinf(angle); newParticle->pos.y = e->pos.y; newParticle->pos.z = e->pos.z + radius*cosf(angle); */ newParticle->prevPos.x = 0; newParticle->prevPos.y = 0; newParticle->prevPos.z = 0; newParticle->dir = e->dir + (e->dirVar*randDist()); speed = e->speed + (e->speed * randDist()); newParticle->dir.x *= speed; newParticle->dir.y *= speed; newParticle->dir.z *= speed; newParticle->life = e->life + (int)((float)e->lifeVar * randDist()); newParticle->side = randDist(); e->particleCount++; return true; } return false; }
//----------------------------------------------------------------------- // TO DO:Returns index of smallest point // Find the middle point at each edge, remove duplicates // call the offset() function to offset the point from the icosahedron to the // sphere surface //----------------------------------------------------------------------- int midPoint(int p1, int p2, std::multimap<long, int> *midPointIndices, std::vector<STVector3> *vertices) { int index = 0; //code added piyush long key; float pos = (1.0 + sqrtf(5.0))/2.0; double radius = sqrtf(1*1 + pos*pos); float a,b,c; if(p1<p2) key = (p1 << 4) | p2; else key = (p2 << 4) | p1; if ( midPointIndices->find(key) == midPointIndices->end()) { //not found a = (vertices->at(p1).x + vertices->at(p2).x)/2; b = (vertices->at(p1).y + vertices->at(p2).y)/2; c = (vertices->at(p1).z + vertices->at(p2).z)/2; index = vertices->size(); offset(STVector3(a, b, c), vertices, radius); midPointIndices->insert(std::make_pair(key, index)); } else{ index = midPointIndices->find(key)->second; } //code end piyush return(index); }
void resetUp() { mUp = STVector3(0.f,1.f,0.f); mRight = STVector3::Cross(mLookAt - mPosition, mUp); mRight.Normalize(); mUp = STVector3::Cross(mRight, mLookAt - mPosition); mUp.Normalize(); }
void SpecialKeyCallback(int key, int x, int y) { switch(key) { case GLUT_KEY_LEFT: AdjustCameraTranslationBy(STVector3(-0.2,0,0)); break; case GLUT_KEY_RIGHT: AdjustCameraTranslationBy(STVector3(0.2,0,0)); break; case GLUT_KEY_DOWN: AdjustCameraTranslationBy(STVector3(0,-0.2,0)); break; case GLUT_KEY_UP: AdjustCameraTranslationBy(STVector3(0,0.2,0)); break; default: break; } glutPostRedisplay(); }
void Camera::nudgeCam() { target = target_note->getLocation(); //printf("position is (%f,%f,%f)\n", target_pos.x,target_pos.y,target_pos.z); STVector3 remaining_path = (STVector3(*target) - STVector3(phantom_position)); remaining_path.z = 0.0; // so camera height doesn't factor in //printf("mult thing %f\n", easeBump(1.0-remaining_path.Length()/cam_travel_dist)); float pcnt_there = 1.0-remaining_path.Length()/cam_travel_dist; last_position = phantom_position; phantom_position += 1.0 * easeBump(pcnt_there) * remaining_path; //calculateAccelteration(); //phantom_position.z = default_height + 5*acceleration; phantom_position.z += .05 * pow(cam_travel_dist,2) * easeBump(pcnt_there); phantom_position.z = default_height + .9 * (phantom_position.z - default_height); slewRealCam(); }
bool Triangle::intersectionWithRay(Ray r, Intersection *outIntersection) { float a = v[0].x - v[1].x; float b = v[0].y - v[1].y; float c = v[0].z - v[1].z; float d = v[0].x - v[2].x; float e = v[0].y - v[2].y; float f = v[0].z - v[2].z; float g = r.d.x; float h = r.d.y; float i = r.d.z; float j = v[0].x - r.e.x; float k = v[0].y - r.e.y; float l = v[0].z - r.e.z; float ak_jb = a * k - j * b; float jc_al = j * c - a * l; float bl_kc = b * l - k * c; float ei_hf = e * i - h * f; float gf_di = g * f - d * i; float dh_eg = d * h - e * g; float M = a * ei_hf + b * gf_di + c * dh_eg; float t = -(f * ak_jb + e * jc_al + d * bl_kc) / M; if (!r.isValidT(t)) return false; float gamma = (i * ak_jb + h * jc_al + g * bl_kc) / M; if (gamma < 0 || gamma > 1) return false; float beta = (j * ei_hf + k * gf_di + l * dh_eg) / M; if (beta < 0 || beta > 1 - gamma) return false; outIntersection->t = t; outIntersection->position = STPoint3((1.0f - beta - gamma) * STVector3(v[0]) + beta * STVector3(v[1]) + gamma * STVector3(v[2])); outIntersection->normal = STVector3::Cross(v[2] - v[0], v[1] - v[0]); outIntersection->normal.Normalize(); return true; }
PointLight::PointLight(const STPoint3 &loc, const STColor3f &col) : Light(col) { location = STVector3(loc); }
void Camera::computeTravelDist(){ STVector3 target_pos = STVector3(*target_note->getLocation()); cam_travel_dist = (target_pos - STVector3(position)).Length(); }
void environmentMatrixTransform(const aiScene * scene, int face) { STVector3 facingDir, upDir; switch (face) { case 0: facingDir = STVector3(-1,0,0); upDir = STVector3(0,1,0); break; case 1: facingDir = STVector3(1,0,0); upDir = STVector3(0,1,0); break; case 2: facingDir = STVector3(0,-1,0); upDir = STVector3(0,0,1); break; case 3: facingDir = STVector3(0,1,0); upDir = STVector3(0,0,-1); break; case 4: facingDir = STVector3(0,0,1); upDir = STVector3(0,1,0); break; case 5: facingDir = STVector3(0,0,-1); upDir = STVector3(0,1,0); break; default: printf("Your face is invalid!\n"); break; } GLfloat aspectRatio = 1.0f; GLfloat nearClip = 0.1f; GLfloat farClip = 500.0f; GLfloat fieldOfView = 90.0f; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fieldOfView, aspectRatio, nearClip, farClip); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(statue_location.x, statue_location.y, statue_location.z, statue_location.x + facingDir.x, statue_location.y + facingDir.y, statue_location.z + facingDir.z, upDir.x, upDir.y, upDir.z); setupLights(); applyMatrixTransform(scene->mRootNode); }
/** * Timer function for moving forward/back, and turning */ static void Timer(int value) { frame++; // boxFrame1++; boxFrame2++; boxFrame3++; glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION,2 + sinf(frame)); if (gameState == GAME_RUNNING) { futurePos = STVector3(worldPos.x, worldPos.y, worldPos.z); if (upKeyPressed) { futurePos.x = worldPos.x + 1*sin(PI/180*worldAngle); futurePos.z = worldPos.z - 1*cos(PI/180*worldAngle); if(jumpOn && ruskoPhys->movingDuringJump == false){ futurePos.x = worldPos.x; futurePos.z = worldPos.z; } if (ruskoBounds->inBounds(futurePos) && collisions->lateralMovement){ worldPos.x = futurePos.x; worldPos.z = futurePos.z; if(systemSound->walking == false && systemSound->jumping != true){ systemSound->startWalking(); } if(systemSound->jumping == true) systemSound->stopWalking(); }else{ } } else if (downKeyPressed) { futurePos.x -= 1*sin(PI/180*worldAngle); futurePos.z += 1*cos(PI/180*worldAngle); if(jumpOn && ruskoPhys->movingDuringJump == false){ futurePos.x = worldPos.x; futurePos.z = worldPos.z; } if (ruskoBounds->inBounds(futurePos)){ worldPos.x = futurePos.x; worldPos.z = futurePos.z; } } if (rightKeyPressed){ if (worldAngle == 360) worldAngle = 0; worldAngle += 10; } if (leftKeyPressed){ if (worldAngle == 360) worldAngle = 0; worldAngle -= 10; } if (upKeyPressed || downKeyPressed || rightKeyPressed || leftKeyPressed ){ glutPostRedisplay(); } } glutTimerFunc(2000/fps, Timer, 0); // 10 milliseconds }
// // Create a sphere with the given radius and center point. 'numStacks' is // the number of layers along the Z axis and 'numSlices' is the number // of radial divisions. // STShape* CreateSphere( float radius, const STPoint3& center, unsigned int numSlices, unsigned int numStacks) { STShape* result = new STShape(); float PI_Stacks = float(M_PI) / float(numStacks); float PI2_Slices = 2.0f * float(M_PI) / float(numSlices); // // Add the interior vertices // for (unsigned int ii = 1; ii < numStacks; ++ii) { float phi = float(ii) * PI_Stacks; float cosPhi = cosf(phi); float sinPhi = sinf(phi); for(unsigned int jj = 0; jj < numSlices; ++jj) { float theta = float(jj) * PI2_Slices; STPoint3 position = center + STVector3(radius * cosf(theta) * sinPhi, radius * sinf(theta) * sinPhi, radius * cosPhi); result->AddVertex(STShape::Vertex( position, STVector3::Zero, STPoint2::Origin)); } } // // Add the pole vertices // STShape::Vertex topVertex( center + STVector3(0,0,radius), STVector3::Zero, STPoint2::Origin); STShape::Index topVertexIndex = result->AddVertex(topVertex); STShape::Vertex bottomVertex( center + STVector3(0,0,-radius), STVector3::Zero, STPoint2::Origin); STShape::Index bottomVertexIndex = result->AddVertex(bottomVertex); // // Add the top and bottom triangles (all triangles involving the pole vertices) // for( unsigned int ii = 0; ii < numSlices; ii++) { unsigned int iiPlus1 = (ii + 1) % numSlices; result->AddFace( STShape::Face(ii, iiPlus1, topVertexIndex)); result->AddFace(STShape::Face( iiPlus1 + (numStacks - 2) * numSlices, ii + (numStacks - 2) * numSlices, bottomVertexIndex)); } // // Add all the interior triangles // for(unsigned int ii = 0; ii < numStacks - 2; ++ii) { for(unsigned int jj = 0; jj < numSlices; ++jj) { unsigned int jjPlus1 = (jj + 1) % numSlices; result->AddFace(STShape::Face( (ii + 1)*numSlices + jj, (ii + 0)*numSlices + jjPlus1, (ii + 0)*numSlices + jj)); result->AddFace(STShape::Face( (ii + 1)*numSlices + jj, (ii + 1)*numSlices + jjPlus1, (ii + 0)*numSlices + jjPlus1)); } } result->GenerateNormals(); return result; }
Ray::Ray(void) : m_origin (STVector3(0,0,0)), m_direction (STVector3(0,0,1)) { }
// Initialize 12 vertices for an icosahedron // centered at zero. See icosphere_visual.pdf in the docs/folder void initVertices(std::vector<STVector3> *vertices) { float pos = (1.0 + sqrtf(5.0))/2.0; vertices->push_back(STVector3(-1, pos, 0)); vertices->push_back(STVector3(1, pos, 0)); vertices->push_back(STVector3(-1, -pos, 0)); vertices->push_back(STVector3(1, -pos, 0)); vertices->push_back(STVector3(0, -1, pos)); vertices->push_back(STVector3(0, 1, pos)); vertices->push_back(STVector3(0, -1, -pos)); vertices->push_back(STVector3(0, 1, -pos)); vertices->push_back(STVector3(pos, 0, -1)); vertices->push_back(STVector3(pos, 0, 1)); vertices->push_back(STVector3(-pos, 0, -1)); vertices->push_back(STVector3(-pos, 0, 1)); }
STVector3 Light::getDirectionTo(STVector3 &point) { return STVector3(0,0,0); }
STVector3 Light::getLocation(STVector3 &point) { return STVector3(0,0,0); }
STVector3 vertex2Vector3(STVertex* v){ return (STVector3(v->pt.x,v->pt.y,v->pt.z)); }
void resetCamera() { mCameraTranslation = STVector3(0.f, 1.f, 1.5f); mCameraAzimuth = 0.f; mCameraElevation = 65.0f; }
Sphere::Sphere(float r, const STPoint3& c){ radius = r; center = STVector3(c.x, c.y, c.z); }
GLuint cubeMap; // current rotation angle static float h_angle = 0.0; static float v_angle = MY_PI/2; bool mouseInit = false; float lastTime = 0.0; STPoint2 cur_mouse = STPoint2(0.0,0.0); STPoint2 last_mouse = STPoint2(0.0,0.0); STVector2 mouse_move = STVector2(0.0,0.0); STPoint3 current_location = STPoint3(-10,2,0); STPoint3 statue_location = STPoint3(0,2.92,0); STVector3 Up = STVector3(0.0,1.0,0.0); STVector3 current_forward = STVector3(sin(v_angle)*cos(h_angle),cos(v_angle),sin(v_angle)*sin(h_angle)); STVector3 current_right = STVector3::Cross(current_forward, Up); // globals for keyboard control bool go_forward = false; bool go_backward = false; bool go_left = false; bool go_right = false; bool go_up = false; bool go_down = false; struct meshObject { const aiMesh* mesh; std::vector<unsigned> indexBuffer;
void Camera::slewRealCam() { position += .1 * (STVector3(phantom_position) - STVector3(position)); }
void handleInput() { // this handles setting keyboard booleans for motion go_forward = Input.IsKeyDown(sf::Key::W); go_backward = Input.IsKeyDown(sf::Key::S); go_left = Input.IsKeyDown(sf::Key::A); go_right = Input.IsKeyDown(sf::Key::D); go_up = Input.IsKeyDown(sf::Key::Space); go_down = Input.IsKeyDown(sf::Key::C); // Event loop, for processing user input, etc. For more info, see: // http://www.sfml-dev.org/tutorials/1.6/window-events.php sf::Event evt; while (window.GetEvent(evt)) { switch (evt.Type) { case sf::Event::Closed: // Close the window. This will cause the game loop to exit, // because the IsOpened() function will no longer return true. window.Close(); break; case sf::Event::Resized: // If the window is resized, then we need to change the perspective // transformation and viewport glViewport(0, 0, evt.Size.Width, evt.Size.Height); break; // Mouse Movement case sf::Event::MouseMoved: if (!mouseInit) { cur_mouse = STPoint2(evt.MouseMove.X, evt.MouseMove.Y); last_mouse = cur_mouse; mouseInit = true; } else { cur_mouse = STPoint2(evt.MouseMove.X, evt.MouseMove.Y); } mouse_move = cur_mouse - last_mouse; h_angle += .01 * mouse_move.x; v_angle += .01 * mouse_move.y; if (v_angle < 0) { v_angle = 0.01; } else if (v_angle > MY_PI) { v_angle = MY_PI-.01; } current_forward = STVector3(sin(v_angle)*cos(h_angle),cos(v_angle),sin(v_angle)*sin(h_angle)); current_forward.Normalize(); current_right = STVector3::Cross(current_forward, Up); current_right.Normalize(); last_mouse = cur_mouse; break; // Key presses case sf::Event::KeyPressed: switch (evt.Key.Code) { case sf::Key::Escape: window.Close(); break; default: break; } default: break; } } }
//----------------------------------------------- // offset each point to the sphere surface //----------------------------------------------- int offset(STVector3 p, std::vector<STVector3> *vertices, double radius) { double length = sqrtf(p.x * p.x + p.y * p.y + p.z * p.z); vertices->push_back(STVector3(p.x*radius/length, p.y*radius/length, p.z*radius/length)); return(globalCount + 1); }