void Application::Render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Set currently used shader program glUseProgram(m_program_ID); // Set world matrix m_world = glm::mat4(1.0f); // Set initial Model-View-Projection mx. glm::mat4 MVP = m_cam.getViewProj() * m_world; float gy8 = sqrtf(8.0f); float gy12 = sqrtf(12.0f); float down = gy12 - gy8; // ==================================================================================================== // ============================== Moving along circular path ========================================== // = According to http://gamedev.stackexchange.com/questions/9607/moving-an-object-in-a-circular-path = glm::vec3 rotation(0.0f + sinf(m_rotation)*10.0f, 0.0f + cosf(m_rotation)*10.0f, 0.0f); MVP = glm::translate(MVP, rotation); // ==================================================================================================== // ============================== Scaling on Z-axis =================================================== MVP = glm::scale(MVP, 1.0f, 1.0f, m_scaling); // ==================================================================================================== // ============================== Rendering the 3 cylinders =========================================== RenderCylinder(MVP, glm::vec3(0.0f, gy8, 0.0f)); RenderCylinder(MVP, glm::vec3(gy8, down, 0.0f)); RenderCylinder(MVP, glm::vec3(-down, down, 2.0f)); RenderCylinder(MVP, glm::vec3(-down, down, -2.0f)); // ==================================================================================================== // ============================== Undoing the translation ============================================= MVP = glm::translate(MVP, -rotation); glUniformMatrix4fv(m_loc_MVP, 1, GL_FALSE, &( MVP[0][0] )); // Send to the VGA // Draw axes if( draw_z ) { glBegin(GL_LINES); glVertex3f(0.0f, 0.0f, 1000.0f); glVertex3f(0.0f, 0.0f, -1000.0f); glEnd(); } if( draw_x ) { glBegin(GL_LINES); glVertex3f(1000.0f, 0.0f, 0.0f); glVertex3f(-1000.0f, 0.0f, 0.0f); glEnd(); } if( draw_y ) { glBegin(GL_LINES); glVertex3f(0.0f, 1000.0f, 0.0f); glVertex3f(0.0f, -1000.0f, 0.0f); glEnd(); } // We're not using the shader program anymore glUseProgram(0); }
void Indicator::RenderArrow(GraphicsDevice &GD, MatrixController &MC, const Vec3f &P1, const Vec3f &P2, const RGBColor &Color, bool ColorNormals) { Vec3f Diff = P2 - P1; Vec3f Dir = Vec3f::Normalize(Diff); float TotalHeight = Diff.Length(); float CylinderRadius = TotalHeight * 0.1f; float ArrowRadius = CylinderRadius * 2.0f; float ArrowHeight = ArrowRadius; float CylinderHeight = TotalHeight - ArrowHeight; RenderCylinder(GD, MC, CylinderRadius, P1, P1 + Dir * CylinderHeight, Color, false, ColorNormals); RenderCylinder(GD, MC, ArrowRadius, P1 + Dir * CylinderHeight, P2, Color, true, ColorNormals); }
void DrawWheelShape(NxShape* wheel) { if(wheel->is(NX_SHAPE_WHEEL) != NULL) { NxWheelShape* wheelShape = (NxWheelShape*)wheel; glPushMatrix(); float glmat[16]; wheel->getGlobalPose().getColumnMajor44(glmat); NxWheelShapeDesc wheelShapeDesc; float r = wheelShape->getRadius(); float a = wheelShape->getSteerAngle(); glMultMatrixf(&(glmat[0])); glTranslatef(-r/2,0,0); glRotatef(90,0,1,0); glRotatef(NxMath::radToDeg(a),0,1,0); glScalef(r, r, r); RenderCylinder(); glPopMatrix(); } }
void DrawCapsule(NxShape* capsule, const NxVec3& color) { NxMat34 pose = capsule->getGlobalPose(); const NxReal & r = capsule->isCapsule()->getRadius(); const NxReal & h = capsule->isCapsule()->getHeight(); glPushMatrix(); SetupGLMatrix(pose.t, pose.M); glPushMatrix(); glTranslatef(0.0f, h*0.5f, 0.0f); glScalef(r,r,r); RenderSphere(); glPopMatrix(); glPushMatrix(); glTranslatef(0.0f,-h*0.5f, 0.0f); glScalef(r,r,r); RenderSphere(); glPopMatrix(); glPushMatrix(); glTranslatef(0.0f,h*0.5f, 0.0f); glScalef(r,h,r); glRotatef(90.0f,1.0f,0.0f,0.0f); RenderCylinder(); glPopMatrix(); glPopMatrix(); }
void DrawCapsule(float r, float h, const PR& pose) { /* glPushMatrix(); SetupGLMatrix(pose); unsigned num = 12; glRotatef(90.0f, 0.0f, 1.0f, 0.0f); gluSphere(GetGLUQuadric(), r, num, num); gluCylinder(GetGLUQuadric(), r, r, h, num, num); glTranslatef(0.0f, 0.0f, h); gluSphere(GetGLUQuadric(), r, num, num); glPopMatrix(); return;*/ glPushMatrix(); SetupGLMatrix(pose); glPushMatrix(); glTranslatef(0.0f, h*0.5f, 0.0f); glScalef(r,r,r); glutSolidSphere(1.0f, 12, 12); // doesn't include texcoords glPopMatrix(); glPushMatrix(); glTranslatef(0.0f,-h*0.5f, 0.0f); glScalef(r,r,r); glutSolidSphere(1.0f, 12, 12); // doesn't include texcoords glPopMatrix(); glPushMatrix(); glTranslatef(0.0f,h*0.5f, 0.0f); glScalef(r,h,r); glRotatef(90.0f,1.0f,0.0f,0.0f); RenderCylinder(); glPopMatrix(); glPopMatrix(); }
PintCapsuleShapeRenderer(float r, float h) { glNewList(mDisplayListNum, GL_COMPILE); glPushMatrix(); glTranslatef(0.0f, h*0.5f, 0.0f); glScalef(r,r,r); glutSolidSphere(1.0f, 12, 12); // doesn't include texcoords glPopMatrix(); glPushMatrix(); glTranslatef(0.0f, -h*0.5f, 0.0f); glScalef(r,r,r); glutSolidSphere(1.0f, 12, 12); // doesn't include texcoords glPopMatrix(); glPushMatrix(); glTranslatef(0.0f, h*0.5f, 0.0f); glScalef(r,h,r); glRotatef(90.0f,1.0f,0.0f,0.0f); RenderCylinder(); glPopMatrix(); glEndList(); }
void DrawCapsule(const NxVec3& color, NxF32 r, NxF32 h) { glColor4f(color.x, color.y, color.z, 1.0f); glPushMatrix(); glTranslatef(0.0f, h*0.5f, 0.0f); glScalef(r,r,r); RenderSphere(); glPopMatrix(); glPushMatrix(); glTranslatef(0.0f,-h*0.5f, 0.0f); glScalef(r,r,r); RenderSphere(); glPopMatrix(); glPushMatrix(); glTranslatef(0.0f,h*0.5f, 0.0f); glScalef(r,h,r); glRotatef(90.0f,1.0f,0.0f,0.0f); RenderCylinder(); glPopMatrix(); }
void Indicator::RenderBox(GraphicsDevice &GD, MatrixController &MC, float Radius, const Rectangle3f &Rect, RGBColor Color) { RenderCylinder(GD, MC, Radius, Vec3f(Rect.Min.x, Rect.Min.y, Rect.Min.z), Vec3f(Rect.Max.x, Rect.Min.y, Rect.Min.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Max.x, Rect.Min.y, Rect.Min.z), Vec3f(Rect.Max.x, Rect.Max.y, Rect.Min.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Max.x, Rect.Max.y, Rect.Min.z), Vec3f(Rect.Min.x, Rect.Max.y, Rect.Min.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Min.x, Rect.Max.y, Rect.Min.z), Vec3f(Rect.Min.x, Rect.Min.y, Rect.Min.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Min.x, Rect.Min.y, Rect.Min.z), Vec3f(Rect.Min.x, Rect.Min.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Max.x, Rect.Min.y, Rect.Min.z), Vec3f(Rect.Max.x, Rect.Min.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Max.x, Rect.Max.y, Rect.Min.z), Vec3f(Rect.Max.x, Rect.Max.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Min.x, Rect.Max.y, Rect.Min.z), Vec3f(Rect.Min.x, Rect.Max.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Min.x, Rect.Min.y, Rect.Max.z), Vec3f(Rect.Max.x, Rect.Min.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Max.x, Rect.Min.y, Rect.Max.z), Vec3f(Rect.Max.x, Rect.Max.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Max.x, Rect.Max.y, Rect.Max.z), Vec3f(Rect.Min.x, Rect.Max.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Min.x, Rect.Max.y, Rect.Max.z), Vec3f(Rect.Min.x, Rect.Min.y, Rect.Max.z), Color); Matrix4 Scale = Matrix4::Scaling(Rect.Dimensions()); Matrix4 Translate = Matrix4::Translation(Rect.Min); MC.World = Scale * Translate; LPDIRECT3DDEVICE9 Device = GD.CastD3D9().GetDevice(); D3DCOLOR D3DColor = RGBColor(90, 90, 90); Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_BLENDFACTOR); Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVBLENDFACTOR); Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); Device->SetRenderState(D3DRS_BLENDFACTOR, D3DColor); _Box.SetColor(Color); _Box.Render(); Device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); }
void Indicator::DrawCamera(GraphicsDevice &GD, MatrixController &MC, const Matrix4 &Perspective, float Radius, float Length, const Camera &C) { Vec3f Frustrum[8], Target; GetCameraLine(Perspective, C, 0.0f, 0.0f, Frustrum[0], Frustrum[4]); GetCameraLine(Perspective, C, 1.0f, 0.0f, Frustrum[1], Frustrum[5]); GetCameraLine(Perspective, C, 1.0f, 1.0f, Frustrum[2], Frustrum[6]); GetCameraLine(Perspective, C, 0.0f, 1.0f, Frustrum[3], Frustrum[7]); //get the 8 vertices of the perspective cube in world space RenderCylinder(GD, MC, Radius, Frustrum[0], Frustrum[1], RGBColor::White); RenderCylinder(GD, MC, Radius, Frustrum[1], Frustrum[2], RGBColor::White); RenderCylinder(GD, MC, Radius, Frustrum[2], Frustrum[3], RGBColor::White); RenderCylinder(GD, MC, Radius, Frustrum[3], Frustrum[0], RGBColor::White); RenderCylinder(GD, MC, Radius, Frustrum[0], Frustrum[4], RGBColor::White); RenderCylinder(GD, MC, Radius, Frustrum[1], Frustrum[5], RGBColor::White); RenderCylinder(GD, MC, Radius, Frustrum[2], Frustrum[6], RGBColor::White); RenderCylinder(GD, MC, Radius, Frustrum[3], Frustrum[7], RGBColor::White); RenderCylinder(GD, MC, Radius, Frustrum[4], Frustrum[5], RGBColor::White); RenderCylinder(GD, MC, Radius, Frustrum[5], Frustrum[6], RGBColor::White); RenderCylinder(GD, MC, Radius, Frustrum[6], Frustrum[7], RGBColor::White); RenderCylinder(GD, MC, Radius, Frustrum[7], Frustrum[4], RGBColor::White); //render the 12 line segments of the perspective cube in world space RenderSphere(GD, MC, Radius * 2.0f, C.VecEye(), RGBColor::Blue); //render the camera eye vector Target = C.VecEye() - C.VecLookDir() * Length; RenderCylinder(GD, MC, Radius, C.VecEye(), Target, RGBColor::Red); Target = C.VecEye() + C.VecUp() * Length; RenderCylinder(GD, MC, Radius, C.VecEye(), Target, RGBColor::Green); Target = C.VecEye() + C.VecRight() * Length; RenderCylinder(GD, MC, Radius, C.VecEye(), Target, RGBColor::Yellow); //render the C.VecLookDir, C.VecUp, and C.VecLeft vectors }
void Indicator::DrawCameraLine(GraphicsDevice &GD, MatrixController &MC, const Matrix4 &Perspective, float Radius, const RGBColor &Color, const Camera &C, float x, float y) { Vec3f P1Out, P2Out; GetCameraLine(Perspective, C, x, y, P1Out, P2Out); //get the camera line RenderCylinder(GD, MC, Radius, P1Out, P2Out, Color); //draw it }