//------------------------------------------------------------------------------- // @ Player::Render() //------------------------------------------------------------------------------- // Render stuff //------------------------------------------------------------------------------- void Player::Render() { // build 4x4 matrix IvMatrix44 transform(mRotate); transform(0,0) *= mScale; transform(1,0) *= mScale; transform(2,0) *= mScale; transform(0,1) *= mScale; transform(1,1) *= mScale; transform(2,1) *= mScale; transform(0,2) *= mScale; transform(1,2) *= mScale; transform(2,2) *= mScale; transform(0,3) = mTranslate.x; transform(1,3) = mTranslate.y; transform(2,3) = mTranslate.z; mShader->GetUniform("dirLightDirection")->SetValue(mLightPos, 0); IvSetWorldMatrix(transform); // draw geometry DrawPlane(); } // End of Player::Render()
/* void StructuredGrid::LoadLineCases() { for (int i=0;i<16;i++) for (int j=0;j<5;j++) lineCases[i].edges[j] = -1; lineCases[1].edges[0] = lineCases[2].edges[1] = lineCases[5].edges[0] = lineCases[6].edges[1] = lineCases[9].edges[0] = lineCases[10].edges[1] = lineCases[13].edges[0] = lineCases[14].edges[1] = 0; lineCases[1].edges[1] = lineCases[3].edges[1] = lineCases[5].edges[1] = lineCases[7].edges[1] = lineCases[8].edges[0] = lineCases[10].edges[2] = lineCases[12].edges[0] = lineCases[14].edges[0] = DimX; lineCases[4].edges[0] = lineCases[6].edges[0] = lineCases[7].edges[0] = lineCases[8].edges[1] = lineCases[9].edges[1] = lineCases[10].edges[3] = lineCases[11].edges[1] = DimX+1; } */ void StructuredGrid::Render(Renderer *aren) { int i,j; if(Data == NULL) { DrawWhiteGrid(aren); } else { switch (CurMode) { case PLANE: DrawPlane(aren); break; case GRID: DrawColoredGrid(aren); break; case CONTOURS: Contour(); CellSet::Render(aren); break; default: CellSet::Render(aren); break; } } }
void DrawObjects(Shader &s) { // 平面描画 s.SetUniformMatrix4x4("uModel", Matrix().m); glColor4f(0.7f, 0.7f, 0.7f, 1.0f); DrawPlane(20.0f); // 立方体 // ModelMatrix s.SetUniformMatrix4x4("uModel", Matrix().m); glColor4f(1, 0.4f, 0.5f, 1.0f); DrawCube(1.0f, 1.0f, 1.0f); // ModelMatrix s.SetUniformMatrix4x4("uModel", Matrix::TranslateMatrix(0.85f, 0.7f, 0.3f).m); glColor4f(0.98f, 0.98f, 0.98f, 1.0f); DrawCube(1.0f, 1.0f, 1.0f); // ModelMatrix s.SetUniformMatrix4x4("uModel", Matrix::TranslateMatrix(-0.3f, -0.5f, 2.5f).m); glColor4f(0.2f, 0.3f, 1, 1.0f); DrawCube(1.0f, 1.0f, 1.0f); // ModelMatrix s.SetUniformMatrix4x4("uModel", Matrix::TranslateMatrix(2.0f, 0.6f, 1.5f).m); glColor4f(0.2f, 1.0f, 0.3f, 1.0f); DrawCube(1.0f, 1.0f, 1.0f); // ModelMatrix s.SetUniformMatrix4x4("uModel", Matrix::TranslateMatrix(-1.85f, -0.5f, -1.3f).m); glColor4f(0.98f, 0.98f, 0.98f, 1.0f); DrawCube(1.0f, 1.0f, 1.0f); }
void DrawShape(NxShape* shape, const NxVec3& color) { switch(shape->getType()) { case NX_SHAPE_PLANE: DrawPlane(shape); break; case NX_SHAPE_BOX: DrawBox(shape, color); break; case NX_SHAPE_SPHERE: DrawSphere(shape, color); break; case NX_SHAPE_CAPSULE: DrawCapsule(shape, color); break; case NX_SHAPE_CONVEX: DrawConvex(shape, color); break; case NX_SHAPE_MESH: DrawMesh(shape, color); break; case NX_SHAPE_WHEEL: DrawWheelShape(shape); break; default: break; } }
Vector3D OpenGLSceneViewCore::positionFromAxisPoint(Axis axis, NSPoint point) { DrawPlane(_camera->GetAxisX(), _camera->GetAxisY(), planeSize); Vector3D position = positionInSpaceByPoint(point); Vector3D result = _manipulated->selectionCenter(); result[(int)axis] = position[(int)axis]; return result; }
Vector3D OpenGLSceneViewCore::positionFromRotatedAxisPoint(Axis axis, NSPoint point, Quaternion rotation) { DrawPlane(_camera->GetAxisX(), _camera->GetAxisY(), planeSize); Vector3D position = positionInSpaceByPoint(point); Vector3D result = _manipulated->selectionCenter(); position = rotation.Conjugate().ToMatrix().Transform(position); result[(int)axis] = position[(int)axis]; return result; }
void HouseBathroom::Render(Vec3& position, Vec2& dimension, Vec2& texture_coordinate, Vec2& texture_dimension, bool no_floor) { // (x, y, z), (w, h), (u, v), , (w, h) , , reflect , front, left, back, right, frontw, leftw, backw, rightw, up, down. Room::Render(position, dimension, texture_coordinate, texture_dimension, 3, no_floor, true, true, false, false, false, false, true, false, false, false); // Draw the rest of the room here. // Inside of the room. glPushMatrix(); // Places in a light shade. CreateLightShade(Vec3((dimension.getX() / 2.0f), -dimension.getY(), (-dimension.getX() / 2.0f)), Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); // To the floor. glPushMatrix(); BindTexture(floor_dark_diamonds_, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR); glTranslatef(0.0f, 0.01f, -dimension.getX()); glRotatef(90.0f, 1.0f, 0.0f, 0.0f); DrawPlane(position, dimension, texture_coordinate, texture_dimension, Vec3(0.0f, 1.0f, 0.0f), 3); // Back to the bathroom. glPopMatrix(); // Moving everything up to the second floor. glTranslatef(0.0f, (dimension.getY() / 8.0f), 0.0f); // To the bath tub. glPushMatrix(); glTranslatef(8.0f, -1.5f, -10.0f); glRotatef(90.0f, 0.0f, 1.0f, 0.0f); CreateBathTub(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); // Back to the bath room. glPopMatrix(); // To the drawers. glPushMatrix(); glTranslatef(11.0f, -1.5f, -6.0f); glScalef(1.0f, 1.25f, 1.0f); glRotatef(180.0f, 0.0f, 1.0f, 0.0f); CreateDrawers(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); // Back to the bath room. glPopMatrix(); // Back to the original 3D scene. glPopMatrix(); }
int main( int argc, char *argv[]) { float Delta,TickNow = 0.,TickLast = 0.; input_handler::CamTrasform CTr; input_handler testInput; testInput.Speed = .1; width = 1920; height = 1080; glClearColor(0.0f,0.0f,0.0f,1.0f); init(); glUniform1f(AspectRatio, float(width)/height); glUniform1i(samplecount,100); float time; mat4 CamRotOld; vec3 PosOld; float fspp = 10; while (testInput.wasdqe[6]) { Delta = (TickNow = SDL_GetTicks()) - TickLast; TickLast = TickNow; float fps = 1000/Delta; float d_speed = -1.0f * fps - TARG_FPS; d_speed /= 1.0f; d_speed = clamp(d_speed, -10.0f, -1.0f); fspp += clamp(fps - TARG_FPS, d_speed, 0.1f); int spp = clamp(int(fspp), 1, 150); glUniform1i(samplecount, spp); fprintf(stderr,"\r fps: %f %f ms spp: %i ", fps, Delta, spp); //SDL_Delay(clamp(1000.0f/TARG_FPS-Delta, 0.0f, 1000.0f/TARG_FPS)); CTr = testInput.GetCamTrasform(Delta); glUniform3f(CamPosition,CTr.CamPos.x,CTr.CamPos.y,CTr.CamPos.z); glUniform3f(OldPosition,PosOld.x,PosOld.y,PosOld.z); PosOld = CTr.CamPos; glUniformMatrix4fv(CamRotMatrix, 1,GL_FALSE, &CTr.CamRot[0][0]); glUniformMatrix4fv(CamRotMatrixOld, 1,GL_FALSE, &CamRotOld[0][0]); CamRotOld = CTr.CamRot; glUniform1f(Gtime,SDL_GetTicks()); DrawPlane(); } glDisableVertexAttribArray(0); return 0; }
// ---------------------------------------------------------------------------- // C#Name#::AppCycle // Draws and animates the objects. // aFrame = Number of the frame to be rendered. // aTimeSecs = Seconds elapsed since the application started running. // aDeltaTimeSecs = Seconds elapsed since last call to AppCycle(). // ---------------------------------------------------------------------------- // void CRain::AppCycle( GLuint /*aFrame*/, GLfloat /*aTimeSecs*/, GLfloat aDeltaTimeSecs ) { glClear( GL_DEPTH_BUFFER_BIT ); /* Draws the clouds, and the ground plane */ glDisable( GL_DEPTH_TEST ); DrawCloud( aDeltaTimeSecs ); DrawPlane(); //Draw the trees. DrawTree( -TREE_STEP_X, -1*TREE_STEP_Z); DrawTree( +TREE_STEP_X, -1*TREE_STEP_Z); DrawTree( -TREE_STEP_X, -2*TREE_STEP_Z); DrawTree( +TREE_STEP_X, -2*TREE_STEP_Z); glEnable( GL_DEPTH_TEST ); /*Update and render the particle engine */ iRainfall->UpdateEngine(aDeltaTimeSecs); iRainfall->RenderEngine(iCamera); }
void ManipulatorWidget::DrawCore(float size) { switch (widget) { case WidgetLine: DrawLine(size); break; case WidgetArrow: DrawArrow(size); break; case WidgetCircle: DrawCircle(size * 0.7f); break; case WidgetPlane: DrawPlane(size * 0.3f, size * 0.2f); break; case WidgetCube: DrawCubeArrow(size); break; default: break; } }
int runScene(Drawable & scene){ glfwInit(); if( !glfwOpenWindow( 500, 500, 0,0,0,0, 16,0, GLFW_WINDOW ) ) { glfwTerminate(); } glfwSetWindowTitle( "3D" ); glfwEnable( GLFW_STICKY_KEYS ); glfwEnable( GLFW_MOUSE_CURSOR ); glfwDisable( GLFW_AUTO_POLL_EVENTS ); setupCallbacks(); do //Main Loop. { setupProjection(); // stereo_state.Ping(); projection_state.Load(); float zoom=2.0; glScalef(zoom*2.0/256.0, zoom*2.0/256.0, zoom*2.0/256.0); glDisable (GL_BLEND); glDisable(GL_LIGHTING); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); setupModelview(); /* Temporary light insertion: */ navigator.Draw(); //reference plane DrawPlane(V3f(0,0,0), V3f(20,0,0), V3f(0,20,0), 5); SetupLighting(); scene.Draw(); //Clear modified mouse state. mouse_state.Moved(); glfwSwapBuffers(); if(!stereo_state.enabled){ glfwWaitEvents(); }else{ glfwPollEvents(); glfwSleep(0.01); //just sleep. }; navigator.idle_move(); } while(!glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED )); return true; };
void HouseKitchen::Render(Vec3& position, Vec2& dimension, Vec2& texture_coordinate, Vec2& texture_dimension, bool no_floor) { // (x, y, z), (w, h), (u, v), , (w, h) , , reflect , front, left, back, right, frontw, leftw, backw, rightw, up, down. Room::Render(position, dimension, texture_coordinate, texture_dimension, 3, no_floor, true, true, false, false, false, false, false, false, false, false); // Draw the rest of the room here. // Inside of the room. glPushMatrix(); // Creating the stencil before we create the scene. glEnable(GL_STENCIL_TEST); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glStencilFunc(GL_ALWAYS, 1, 1); //// We aren't rendering to the frame, so always pass the stencil test. glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); // Disable depth testing. glDisable(GL_DEPTH_TEST); // To the floor. glPushMatrix(); BindTexture(floor_dark_diamonds_, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR); glTranslatef(0.0f, 0.125f, -dimension.getX()); glRotatef(90.0f, 1.0f, 0.0f, 0.0f); DrawPlane(position, dimension, texture_coordinate, texture_dimension, Vec3(0.0f, 1.0f, 0.0f), 3); // Back to the kitchen. glPopMatrix(); glEnable(GL_DEPTH_TEST); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // Turn on rendering to the frame buffer. glStencilFunc(GL_EQUAL, 1, 1); // Don't change the stencil values. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // To the reflected worktop. glPushMatrix(); // Making the kitchen objects upside down. glScalef(1.0f, -1.0f, 1.0f); // Placing the worktop exactly where I want it. glTranslatef((dimension.getX() / 2.0f) - 0.5f, 0.0f, -12.45f); glScalef(1.25f, 1.75f, 1.0f); glRotatef(270.0f, 0.0f, 1.0f, 0.0f); CreateWorkTop(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); glRotatef(-270.0f, 0.0f, 1.0f, 0.0f); glTranslatef(5.0f, 0.0f, 3.75f); glScalef(1.25f, 1.0f, 1.0f); glRotatef(180.0f, 0.0f, 1.0f, 0.0f); CreateWorkTop(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); // Back to the reflected kitchen. glPopMatrix(); // To the reflected teapot model. glPushMatrix(); glScalef(1.0f, -1.0f, 1.0f); glTranslatef((dimension.getX() / 2.0f) + 1.0f, 3.125f, (dimension.getX() / 2.0f) - 18.0f); glScalef(0.03125f, 0.03125f, 0.03125f); teapot_.Render(); // Back to the reflected kitchen. glPopMatrix(); // To the reflected cupboards. glPushMatrix(); glScalef(1.0f, -1.0f, 1.0f); glTranslatef((dimension.getX() / 2.0f), 5.0f, -12.45f); glScalef(1.0f, 1.25f, 1.0f); glRotatef(270.0f, 0.0f, 1.0f, 0.0f); CreateCupboard(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); glTranslatef(0.0f, 0.0f, -3.0f); CreateCupboard(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); glRotatef(-270.0f, 0.0f, 1.0f, 0.0f); glTranslatef(3.0f, 0.0f, 1.0f); glScalef(1.5f, 1.0f, 1.0f); glRotatef(180.0f, 0.0f, 1.0f, 0.0f); CreateCupboard(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); glTranslatef(0.0f, 0.0f, -3.0f); CreateCupboard(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); // Back to the kitchen. glPopMatrix(); // No longer need the stencil test. glDisable(GL_STENCIL_TEST); // To combine the flow and rendered reflection of the object. glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Lighting not really needed. glDisable(GL_LIGHTING); // To the floor. glPushMatrix(); BindTexture(floor_dark_diamonds_, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR); glTranslatef(0.0f, 0.125f, -dimension.getX()); glRotatef(90.0f, 1.0f, 0.0f, 0.0f); DrawPlane(position, dimension, texture_coordinate, texture_dimension, Vec3(0.0f, 1.0f, 0.0f), 3); // Back to the kitchen. glPopMatrix(); glEnable(GL_LIGHTING); //glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); // To the light shade. glPushMatrix(); // Places in a light shade. CreateLightShade(Vec3((dimension.getX() / 2.0f), -dimension.getY(), (-dimension.getX() / 2.0f)), Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); // Back to the kitchen. glPopMatrix(); // To the worktop. glPushMatrix(); glTranslatef((dimension.getX() / 2.0f) - 0.5f, 0.0f, -12.45f); glScalef(1.25f, 1.75f, 1.0f); glRotatef(270.0f, 0.0f, 1.0f, 0.0f); CreateWorkTop(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); glRotatef(-270.0f, 0.0f, 1.0f, 0.0f); glTranslatef(5.0f, 0.0f, 3.75f); glScalef(1.25f, 1.0f, 1.0f); glRotatef(180.0f, 0.0f, 1.0f, 0.0f); CreateWorkTop(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); // Back to the kitchen. glPopMatrix(); // To the teapot model. glPushMatrix(); glTranslatef((dimension.getX() / 2.0f) + 1.0f, 3.125f, (dimension.getX() / 2.0f) - 18.0f); glScalef(0.03125f, 0.03125f, 0.03125f); teapot_.Render(); // Back to the kitchen. glPopMatrix(); // To the cupboards. glPushMatrix(); glTranslatef((dimension.getX() / 2.0f), 5.0f, -12.45f); glScalef(1.0f, 1.25f, 1.0f); glRotatef(270.0f, 0.0f, 1.0f, 0.0f); CreateCupboard(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); glTranslatef(0.0f, 0.0f, -3.0f); CreateCupboard(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); glRotatef(-270.0f, 0.0f, 1.0f, 0.0f); glTranslatef(3.0f, 0.0f, 1.0f); glScalef(1.5f, 1.0f, 1.0f); glRotatef(180.0f, 0.0f, 1.0f, 0.0f); CreateCupboard(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); glTranslatef(0.0f, 0.0f, -3.0f); CreateCupboard(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); // Back to the kitchen. glPopMatrix(); // Back to the original 3D scene. glPopMatrix(); }
void HouseMasterBedroom::Render(Vec3& position, Vec2& dimension, Vec2& texture_coordinate, Vec2& texture_dimension, bool no_floor) { // (x, y, z), (w, h), (u, v), , (w, h) , , reflect , front, left, back, right, frontw, leftw, backw, rightw, up, down. Room::Render(position, dimension, texture_coordinate, texture_dimension, 3, no_floor, false, false, true, true, true, false, false, false, false, false); // Draw the rest of the room here. glPushMatrix(); // Places in a light shade. CreateLightShade(Vec3((dimension.getX() / 2.0f), -dimension.getY(), (-dimension.getX() / 2.0f)), Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); // To the floor. glPushMatrix(); BindTexture(fabric_rough_carpet_, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR); glTranslatef(0.0f, 0.01f, -dimension.getX()); glRotatef(90.0f, 1.0f, 0.0f, 0.0f); DrawPlane(position, dimension, texture_coordinate, texture_dimension, Vec3(0.0f, 1.0f, 0.0f), 3); // Back to the master bedroom. glPopMatrix(); // Moving everything up to the second floor. glTranslatef(0.0f, (dimension.getY() / 8.0f), 0.0f); // To the double bed. glPushMatrix(); glTranslatef((dimension.getX() / 2.0f) - 3.0f, -1.5f, -0.25f); glScalef(0.5f, 1.0f, 0.75f); CreateBed(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension, true); // Back to the master bed room. glPopMatrix(); // To the tables. glPushMatrix(); glTranslatef(0.5f, -1.5f, -0.5f); glScalef(0.5f, 0.5f, 0.25f); CreateTable(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); glTranslatef(14.0f, 0.0f, 0.0f); CreateTable(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); // Back to the master bed room. glPopMatrix(); // To the lamps. glPushMatrix(); glTranslatef(1.5f, -0.25f, -1.0f); glScalef(0.25f, 0.25f, 0.25f); CreateLamp(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); glTranslatef(28.0f, 0.0f, 0.0f); CreateLamp(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); // Back to the master bed room. glPopMatrix(); // To the painting. glPushMatrix(); glTranslatef(-1.5f, 2.5f, -6.5f); glScalef(2.0f, 1.0f, 2.0f); glRotatef(90.0f, 0.0f, 1.0f, 0.0f); CreatePainting(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension, "Converted_Textures/painting_trees.jpg"); // Back to the master bed room. glPopMatrix(); // To the drawers. glPushMatrix(); glTranslatef(0.25f, -1.5f, -12.0f); glScalef(2.0f, 1.5f, 1.0f); glRotatef(270.0f, 0.0f, 1.0f, 0.0f); CreateDrawers(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); glTranslatef(0.0f, 0.0f, -1.0f); CreateDrawers(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension); // Back to the master bed room. glPopMatrix(); // Back to the original 3D scene. glPopMatrix(); }