void ProjectileManager::createProjectile(const Ogre::Vector3& tankPosition, const Ogre::Quaternion& turretOrientation, const Ogre::Degree& angle, const float& velocity, const float& dmg){ std::ostringstream oss; oss << "Projectile" << time(0) << projectiles.size() << counter++; Ogre::ParticleSystem* particleSystem = mSceneMgr->createParticleSystem(oss.str(), "Examples/PurpleFountain"); scaleBy(1.f, particleSystem); Ogre::SceneNode* parentParticleSn = mSceneMgr->getRootSceneNode()->createChildSceneNode(); Ogre::SceneNode* particleSn = parentParticleSn->createChildSceneNode(); Ogre::Vector3 start(-115.f, 10.f, 0.f); parentParticleSn->setPosition(tankPosition); particleSn->setPosition(start); parentParticleSn->yaw(turretOrientation.getYaw()); particleSn->attachObject(particleSystem); particleSn->roll(Ogre::Degree(-90.f)); particleSn->scale(Ogre::Vector3(0.1f)); projectiles.insert(new Projectile(start, particleSn, angle, velocity, dmg)); }
f00Quat& f00Quat::normalize() { GLfloat factor = d_val[ 0 ] * d_val[ 0 ] + d_val[ 1 ] * d_val[ 1 ] + d_val[ 2 ] * d_val[ 2 ] + d_val[ 3 ] * d_val[ 3 ]; assert( factor != 0 ); GLfloat scaleBy((GLfloat)( 1.0 / sqrt( factor ) )); d_val[ 0 ] = d_val[ 0 ] * scaleBy; d_val[ 1 ] = d_val[ 1 ] * scaleBy; d_val[ 2 ] = d_val[ 2 ] * scaleBy; d_val[ 3 ] = d_val[ 3 ] * scaleBy; return *this; }
f00Quat& f00Quat::set( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ) { // Convert to radians. angle *= (GLfloat)( M_PI / 180.0 ); // Normalize the axis. GLfloat factor = x * x + y * y + z * z; assert( factor != 0 ); GLfloat scaleBy((GLfloat)( 1.0 / sqrt( factor ) )); x = x * scaleBy; y = y * scaleBy; z = z * scaleBy; // Build a quaternion! d_val[ 0 ] = (GLfloat)cos( angle / 2.0 ); GLfloat sinHalfAngle( (GLfloat)(sin( angle / 2.0 ) )); d_val[ 1 ] = x * sinHalfAngle; d_val[ 2 ] = y * sinHalfAngle; d_val[ 3 ] = z * sinHalfAngle; return *this; }
void zoomOut() { scaleBy(1.0 / 1.1); }
/** * Draws a branch. The more deep you go into the l-system, the smaller the * branch becomes. * NOTE: This was completed before I realized a simpler way to do it was creating * two arrays: vertices and indices. But it worked, and more work is more work, * so I left it as is. * @param direction left, right, center, or term as defined in the enum inside * of drawplant.h. LEFT and RIGHT make it so the branch will appear to connect * to the rest of the tree easier. TERM will cause the top of the branch * to taper slightly. * @param depth used for scaling the branch */ void drawBranch(int direction, int depth) { glColor3f(treeRed, treeGreen, treeBlue); /* ADD YOUR CODE to make the 2D branch a 3D extrusion */ GLfloat lowerLeftBack[3] = {-1.0, 0.0, -1.0}; GLfloat lowerRightBack[3] = { 1.0, 0.0, -1.0}; GLfloat upperLeftBack[3] = {-1.0, 6.0, -1.0}; GLfloat upperRightBack[3] = { 1.0, 6.0, -1.0}; GLfloat lowerLeftFront[3] = {-1.0, 0.0, 1.0}; GLfloat lowerRightFront[3] = { 1.0, 0.0, 1.0}; GLfloat upperLeftFront[3] = {-1.0, 6.0, 1.0}; GLfloat upperRightFront[3] = { 1.0, 6.0, 1.0}; if (direction & RIGHT) { lowerRightBack[1] = -6.0; lowerLeftBack[1] = -3.0; lowerRightFront[1] = -6.0; lowerLeftFront[1] = -3.0; } // if else if (direction & LEFT) { lowerRightBack[1] = -3.0; lowerLeftBack[1] = -6.0; lowerRightFront[1] = -3.0; lowerLeftFront[1] = -6.0; } // else if if (direction & TERM) { upperRightBack[0] = 0.25; upperLeftBack[0] = -0.25; upperRightFront[0] = 0.25; upperLeftFront[0] = -0.25; } // if pushMatrix(); scaleBy((depth * 1.0 / scaleFactor), depth*1.0 / scaleFactor, depth*1.0 / scaleFactor); glBegin(GL_POLYGON); // Draw back face glVertex3fv(lowerRightBack); glVertex3fv(upperRightBack); glVertex3fv(upperLeftBack); glVertex3fv(lowerLeftBack); // Draw front face glVertex3fv(lowerRightFront); glVertex3fv(upperRightFront); glVertex3fv(upperLeftFront); glVertex3fv(lowerLeftFront); // Draw left face glVertex3fv(lowerLeftFront); glVertex3fv(upperLeftFront); glVertex3fv(upperLeftBack); glVertex3fv(lowerLeftBack); // Draw top face glVertex3fv(upperRightFront); glVertex3fv(upperRightBack); glVertex3fv(upperLeftBack); glVertex3fv(upperLeftFront); // Draw right face glVertex3fv(lowerRightBack); glVertex3fv(upperRightBack); glVertex3fv(upperRightFront); glVertex3fv(lowerRightFront); // Draw bottom face glVertex3fv(lowerRightFront); glVertex3fv(lowerRightBack); glVertex3fv(lowerLeftBack); glVertex3fv(lowerLeftFront); // Draws a peak on the branch if the branch is a terminating branch if (direction & TERM) { // Draw back face glVertex3fv(upperRightBack); glVertex3fv(lowerLeftBack); glVertex3f(0.0, 7.0, -0.5); // Draw front face glVertex3fv(upperRightFront); glVertex3fv(lowerLeftFront); glVertex3f(0.0, 7.0, 0.5); // Draw left face glVertex3fv(upperLeftFront); glVertex3f(0.0, 7.0, 0.5); glVertex3f(0.0, 7.0, -0.5); glVertex3fv(upperLeftBack); // draw right face glVertex3fv(upperRightFront); glVertex3f(0.0, 7.0, 0.5); glVertex3f(0.0, 7.0, -0.5); glVertex3fv(upperRightBack); } // if popMatrix(); glEnd(); } // drawBranch