void rotate(double edge[20][3]) { int ch; int i; double temp,theta,temp1; clrscr(); cout<<"-=[ Rotation About ]=-"; cout<<"1:==> X-Axis "; cout<<"2:==> Y-Axis"; cout<<"3:==> Z-Axis "; cout<<"Enter Your Choice "; cin>>ch; switch(ch) { case 1: cout<<" Enter The Angle "; cin>>theta; theta=(theta*3.14)/180; for(i=0;i<20;i++) { edge[i][0]=edge[i][0]; temp=edge[i][1]; temp1=edge[i][2]; edge[i][1]=temp*cos(theta)-temp1*sin(theta); edge[i][2]=temp*sin(theta)+temp1*cos(theta); } draw_cube(edge); break; case 2: cout<<" Enter The Angle "; cin>>theta; theta=(theta*3.14)/180; for(i=0;i<20;i++) { edge[i][1]=edge[i][1]; temp=edge[i][0]; temp1=edge[i][2]; edge[i][0]=temp*cos(theta)+temp1*sin(theta); edge[i][2]=-temp*sin(theta)+temp1*cos(theta); } draw_cube(edge); break; case 3: cout<<" Enter The Angle "; cin>>theta; theta=(theta*3.14)/180; for(i=0;i<20;i++) { edge[i][2]=edge[i][2]; temp=edge[i][0]; temp1=edge[i][1]; edge[i][0]=temp*cos(theta)-temp1*sin(theta); edge[i][1]=temp*sin(theta)+temp1*cos(theta); } draw_cube(edge); break; } }
void draw::draw_tail(){ glPushMatrix(); //Link 1 glPushMatrix(); const dReal *tail_link_1_location = dBodyGetPosition(body_bag->getTailLink1Body()); glTranslatef(tail_link_1_location[0], tail_link_1_location[1], tail_link_1_location[2]); const dReal *tail_link_1_rotation_matrix_ode = dBodyGetRotation(body_bag->getTailLink1Body()); float tail_link_1_rotation_matrix_openGL[16]; getOpenGLRotationMatrix(tail_link_1_rotation_matrix_openGL, tail_link_1_rotation_matrix_ode); //rotate the link glMultMatrixf(tail_link_1_rotation_matrix_openGL); glScalef(4, 4, 60); draw_cube(); glPopMatrix(); //Link 2 glPushMatrix(); const dReal *tail_link_2_location = dBodyGetPosition(body_bag->getTailLink2Body()); glTranslatef(tail_link_2_location[0], tail_link_2_location[1], tail_link_2_location[2]); const dReal *tail_link_2_rotation_matrix_ode = dBodyGetRotation(body_bag->getTailLink2Body()); float tail_link_2_rotation_matrix_openGL[16]; getOpenGLRotationMatrix(tail_link_2_rotation_matrix_openGL, tail_link_2_rotation_matrix_ode); //rotate the link glMultMatrixf(tail_link_2_rotation_matrix_openGL); glScalef(4, 4, 60); draw_cube(); glPopMatrix(); //Link 3 glPushMatrix(); const dReal *tail_link_3_location = dBodyGetPosition(body_bag->getTailLink3Body()); glTranslatef(tail_link_3_location[0], tail_link_3_location[1], tail_link_3_location[2]); const dReal *tail_link_3_rotation_matrix_ode = dBodyGetRotation(body_bag->getTailLink3Body()); float tail_link_3_rotation_matrix_openGL[16]; getOpenGLRotationMatrix(tail_link_3_rotation_matrix_openGL, tail_link_3_rotation_matrix_ode); //rotate the link glMultMatrixf(tail_link_3_rotation_matrix_openGL); glScalef(4, 4, 60); draw_cube(); glPopMatrix(); //Link 4 glPushMatrix(); const dReal *tail_link_4_location = dBodyGetPosition(body_bag->getTailLink4Body()); glTranslatef(tail_link_4_location[0], tail_link_4_location[1], tail_link_4_location[2]); const dReal *tail_link_4_rotation_matrix_ode = dBodyGetRotation(body_bag->getTailLink4Body()); float tail_link_4_rotation_matrix_openGL[16]; getOpenGLRotationMatrix(tail_link_4_rotation_matrix_openGL, tail_link_4_rotation_matrix_ode); //rotate the link glMultMatrixf(tail_link_4_rotation_matrix_openGL); glScalef(4, 4, 60); draw_cube(); glPopMatrix(); glPopMatrix(); }
void perspect(double edge[20][3]) { int ch; int i; double p,q,r; clrscr(); cout<<"-=[ Perspective Projection About ]=-"; cout<<" 1:==> X-Axis "; cout<<"2:==> Y-Axis "; cout<<"3:==> Z-Axis"; cout<<" Enter Your Choice :="; cin>>ch; switch(ch) { case 1: cout<<" Enter P :="; cin>>p; for(i=0;i<20;i++) { edge[i][0]=edge[i][0]/(p*edge[i][0]+1); edge[i][1]=edge[i][1]/(p*edge[i][0]+1); edge[i][2]=edge[i][2]/(p*edge[i][0]+1); } draw_cube(edge); break; case 2: cout<<" Enter Q :="; cin>>q; for(i=0;i<20;i++) { edge[i][1]=edge[i][1]/(edge[i][1]*q+1); edge[i][0]=edge[i][0]/(edge[i][1]*q+1); edge[i][2]=edge[i][2]/(edge[i][1]*q+1); } draw_cube(edge); break; case 3: cout<<" Enter R :="; cin>>r; for(i=0;i<20;i++) { edge[i][2]=edge[i][2]/(edge[i][2]*r+1); edge[i][0]=edge[i][0]/(edge[i][2]*r+1); edge[i][1]=edge[i][1]/(edge[i][2]*r+1); } draw_cube(edge); break; } closegraph(); }
void Game::draw() { std::uniform_real_distribution<> dist(-0.5f, 0.5f); currentShake.x = (float)dist(random) * shakeIntensity * 20.0f; currentShake.y = (float)dist(random) * shakeIntensity * 20.0f; //for (auto it = players.begin(); it != players.end(); ++it) for (size_t i = 0; i < players.size(); i++) { Player *it = &*players[i]; it->draw(); } for (auto it = particles.begin(); it != particles.end(); ++it) { if (it->duration > 0.0f) it->draw(); } for (auto it = powerups.begin(); it != powerups.end(); ++it) { it->draw(); } for (auto it = blocks.begin(); it != blocks.end(); ++it) { if (it->alive) it->draw(); } glm::mat4 model = glm::mat4(); model = glm::translate(model, glm::vec3(0.0f, 1000.0f, 0.0f)); model = glm::scale(model, glm::vec3(3200.0f, 100.0f, 0.0f)); draw_cube(model, glm::vec4(100 / 255.0f, 150 / 255.0f, 200 / 255.0f, 1.0f)); for (int i = 0; i < 2; i++) { if (bound[i] > 0.0f) { model = glm::mat4(); model = glm::translate(model, glm::vec3(i * 3200.0f, 0.0f, 0.0f)); model = glm::scale(model, glm::vec3(4.0f, 1000.0f, 0.0f)); draw_cube(model, glm::vec4(1.0f, 1.0f, 1.0f, bound[i])); } } }
void draw_screen( void ) { // Step you_angle += ( 10 * you_velocity * you_turn ) / fps; float you_x_new = you_x - ( (float)sin(you_angle*piover180) * you_velocity * you_dir ) / fps; float you_z_new = you_z + ( (float)cos(you_angle*piover180) * you_velocity * you_dir ) / fps; int joel = boundCheck(you_x_new, you_x_new, you_z_new, you_z_new); // TODO change this to avoid repetition if (joel == 1) { you_x = you_x_new; you_z = you_z_new; } glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen and The Depth Buffer /* We don't want to modify the projection matrix. */ glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); you_compensate(); // Some nice material/colour settings glColorMaterial ( GL_FRONT_AND_BACK, GL_EMISSION ) ; glEnable ( GL_COLOR_MATERIAL ) ; glLoadIdentity(); you_compensate(); glTranslatef( 0.0f, 3.0f, 0.0f ); draw_cube(); DrawWorld(); if (debug) { glLoadIdentity(); glTranslatef(0, 0, -1); glColor3f(1, 1, 1); glRasterPos2f(-0.7f, -0.5f); glPrint("X: %f Z: %f Angle: %f Velocity: %f", you_x, you_z, you_angle, you_velocity); glRasterPos2f(-0.7f, 0.5f); glPrint("FPS: %f", fps); } if (joel == 12) { glLoadIdentity(); glTranslatef(0, 0, -1); glColor3f(1, 1, 1); glRasterPos2f(-0.7f, 0.5f); glPrint("The Cake,"); glRasterPos2f(-0.7f, 0.4f); glPrint("Is a Lie!!"); // glRasterPos2f(-0.7f, 0.3f); // glPrint("Third Line"); } Frames++; GLint t = SDL_GetTicks(); if (t - T0 >= 100) { GLfloat seconds = (t - T0) / 1000.0; fps = Frames / seconds; T0 = t; Frames = 0; } SDL_GL_SwapBuffers( ); }
void gui_redraw () { switch_focus(mainWindow); //lock // graph_log_lines(); // graph_fft_mag(dbRange); // graph_spectral_centroid(); // graph_dominant_pitch_lp(); // pthread_mutex_lock(&spectrogram_lock); // graph_spectrogram_3d_poly(dbRange); // pthread_mutex_unlock(&spectrogram_lock); draw_cube(1); glfwSwapBuffers(mainWindow); //PITCH TRACKING WINDOW switch_focus(trackerWindow); graph_x_log_lines(); graph_midi_notes(); graph_NON_NOFFs(); glfwSwapBuffers(trackerWindow); }
void draw_player( Player *player, GLuint position_loc, GLuint normal_loc, GLuint uv_loc) { draw_cube( player->position_buffer, player->normal_buffer, player->uv_buffer, position_loc, normal_loc, uv_loc); }
//draw floor void draw_floor(){ glPushMatrix(); stacks.push(nothing); nothing = nothing * Mtranslate(0,0,-4); nothing = nothing * Mscale(20,20,0.2); draw_cube(1,c7,nothing); //tree1 nothing = stacks.top(); nothing *=Mtranslate(5,5,-3); draw_tree(nothing); //tree2 nothing = stacks.top(); nothing *=Mtranslate(-5,5,-3); nothing *=Mscale(0.8,0.8,0.8); draw_tree(nothing); //tree3 nothing = stacks.top(); nothing *=Mtranslate(0,5,-3); nothing *=Mscale(0.4,0.4,0.4); draw_tree(nothing); nothing = stacks.top(); stacks.pop(); glPopMatrix(); }
// Render the world from the specified point of view. void RenderView( const OSVR_RenderInfoOpenGL& renderInfo, //< Info needed to render GLuint frameBuffer, //< Frame buffer object to bind our buffers to GLuint colorBuffer, //< Color buffer to render into GLuint depthBuffer //< Depth buffer to render into ) { // Render to our framebuffer glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer); // Set color and depth buffers for the frame buffer glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colorBuffer, 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer); // Set the list of draw buffers. GLenum DrawBuffers[1] = { GL_COLOR_ATTACHMENT0 }; glDrawBuffers(1, DrawBuffers); // "1" is the size of DrawBuffers // Always check that our framebuffer is ok if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { std::cerr << "RenderView: Incomplete Framebuffer" << std::endl; return; } // Set the viewport to cover our entire render texture. glViewport(0, 0, static_cast<GLsizei>(renderInfo.viewport.width), static_cast<GLsizei>(renderInfo.viewport.height)); // Set the OpenGL projection matrix GLdouble projection[16]; osvr::renderkit::OSVR_ProjectionMatrix temp; temp.bottom = renderInfo.projection.bottom; osvr::renderkit::OSVR_Projection_to_OpenGL(projection, ConvertProjectionMatrix(renderInfo.projection)); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMultMatrixd(projection); /// Put the transform into the OpenGL ModelView matrix GLdouble modelView[16]; osvr::renderkit::OSVR_PoseState_to_OpenGL(modelView, renderInfo.pose); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrixd(modelView); // Clear the screen to black and clear depth glClearColor(0, 0, 0, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // ================================================================= // This is where we draw our world and hands and any other objects. // We're in World Space. To find out about where to render objects // in OSVR spaces (like left/right hand space) we need to query the // interface and handle the coordinate tranforms ourselves. // Draw a cube with a 5-meter radius as the room we are floating in. draw_cube(5.0); }
//! [7] void GLWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glScalef(scale, scale, scale); glTranslatef(xMove, yMove, -10.0); glRotatef(xRot / 16.0, 1.0, 0.0, 0.0); glRotatef(yRot / 16.0, 0.0, 1.0, 0.0); glRotatef(zRot / 16.0, 0.0, 0.0, 1.0); draw_cube(); if(tex != NULL) { glPushMatrix(); { glTranslatef(xmin, ymin, zmin); glScalef((xmax-xmin)/vsvr.tex_ni(), (ymax - ymin)/vsvr.tex_nj(), (zmax-zmin)/vsvr.tex_nk()); if(force_reload) { force_reload = !vsvr.gl_render(); } else { force_reload = !vsvr.gl_redisplay(); } } glPopMatrix(); } else { //logo->draw(); } }
void zeichneSzene(void) { glClearColor(1, 1, 1, 1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-60, 80, -60, 100, -70, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT); // blue cube glRotatef(-45, 1, 1, 0); draw_cube(0, 0, 1, 40); glPushMatrix(); // red cube glTranslatef(40, 40, 40); draw_cube(1, 0, 0, 40); glPopMatrix(); // green cube glRotatef(-45, 1, 1, 0); draw_cube(0, 1, 0, 40); glutWireCube(40); glFlush(); }
void Scene::example_2() { glClear(GL_COLOR_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glRotatef(1,1,0,0); glRotatef(2,0,1,0); glColor3f(0.2,0.3,0.4); draw_cube(0,0,0,0.50); }
void Scene::example_1() { glClear(GL_COLOR_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glLoadIdentity(); glRotatef(45,1,0,0);//Поворот вида/модели на 45 градусов glColor3f(0.2,0.3,0.4); draw_cube(0,0,0,0.50); }
int main(int argc, char** argv) { SDL_Event event; int keypress = 0; // Init random number generator srand(clock()); // Init everything sdl_init("OpenGL example"); opengl_init(); audioplayer_init(); // Init internal data init_sin_table(); init_textures(); // Load audioplayer tune audioplayer_loadtune(&simpletune); audioplayer_play(); // Loop until the end while(!keypress && audioplayer_isplaying()) { // Lock SDL surface if needed if(SDL_MUSTLOCK(screen)) if(SDL_LockSurface(screen) < 0) exit(EXIT_FAILURE); // Draw the plasma draw_cube(screen, audioplayer_getpos()); // Unlock the SDL surface if needed if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); // Update screen SDL_GL_SwapBuffers(); // Handle SDL events while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: case SDL_KEYDOWN: keypress = 1; break; } } } // Exit gracefully SDL_Quit(); return EXIT_SUCCESS; }
void ShZshapeManager::draw_shape(const char* content) { if (content == "cube") { draw_cube(); } if (content == "cylinder") { draw_cylinder(); } if (content == "pipe") { draw_pipe(); } if (content == "cone") { draw_cone(); } if (content == "circle") { draw_circle(); } if (content == "ring") { draw_ring(); } if (content == "pyramid") { draw_pyramid(); } if (content == "triangle") { draw_triangle(); } if (content == "rectangle") { draw_rectangle(); } if (content == "polygon") { draw_polygon(); } if (content == "multigonalStar") { draw_multigonalStar(); } }
void reflect(double edge[20][3]) { int ch; int i; clrscr(); cout<<"-=[ Reflection About ]=-"; cout<<"1:==> X-Axis"; cout<<"2:==> Y-Axis "; cout<<"3:==> Z-Axis "; cout<<" Enter Your Choice "; cin>>ch; switch(ch) { case 1: for(i=0;i<20;i++) { edge[i][0]=edge[i][0]; edge[i][1]=-edge[i][1]; edge[i][2]=-edge[i][2]; } draw_cube(edge); break; case 2: for(i=0;i<20;i++) { edge[i][1]=edge[i][1]; edge[i][0]=-edge[i][0]; edge[i][2]=-edge[i][2]; } draw_cube(edge); break; case 3: for(i=0;i<20;i++) { edge[i][2]=edge[i][2]; edge[i][0]=-edge[i][0]; edge[i][1]=-edge[i][1]; } draw_cube(edge); break; } }
static int motion_cb(Ihandle *ih,int x,int y,char* status) { (void)status; if (move) { double dif_x, dif_y; double dx, dy, dz; double x1, y1, z1; double x2, y2, z2; double angle, norma; int height = IupGetInt2(ih, "RASTERSIZE"); double mv[16]; double pm[16]; int vp[4]; IupGLMakeCurrent(ih); glGetDoublev(GL_MODELVIEW_MATRIX, mv); glGetDoublev(GL_PROJECTION_MATRIX, pm); glGetIntegerv(GL_VIEWPORT, vp); dif_x = x - pos_x; dif_y = y - pos_y; if (dif_x == 0 && dif_y == 0) return IUP_DEFAULT; pos_x = x; pos_y = y; angle = sqrt(dif_x*dif_x + dif_y*dif_y); gluUnProject(pos_x, INVERT_Y(pos_y), 0.0, mv, pm, vp, &x1, &y1, &z1); gluUnProject((double)(dif_y + pos_x), (double)(dif_x + INVERT_Y(pos_y)), 0.0, mv, pm, vp, &x2, &y2, &z2); dx = x2-x1; dy = y2-y1; dz = z2-z1; norma = sqrt(dx*dx + dy*dy + dz*dz); dx /= norma; dy /= norma; dz /= norma; glMatrixMode(GL_MODELVIEW); glTranslated(0.5, 0.5, 0.5); glRotated (angle, dx, dy, dz); glTranslated(-0.5, -0.5, -0.5); glGetDoublev(GL_MODELVIEW_MATRIX, model_view_matrix); use_model_matrix = 1; draw_cube(); IupGLSwapBuffers(ih); } return IUP_DEFAULT; }
void windowerr_display3(VeWindow *w, long tm, VeWallView *wv) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); glBindTexture(GL_TEXTURE_2D,2); if (current_window == w) glColor3fv(current_tex); else glColor3fv(wall_tex); draw_cube(cube_size); glTranslatef(0.0,0.0,-3.0); glRotatef(45.0,0.0,1.0,0.0); glRotatef(45.0,1.0,0.0,0.0); glColor3fv(current_tex); draw_cube(0.3); draw_data(w); }
static int action(Ihandle *ih) { IupGLMakeCurrent(ih); init(); draw_cube(); IupGLSwapBuffers(ih); return IUP_DEFAULT; }
void draw(OBJECT *verts) // draws the cube and house { int i, j; // loop variables // polymorphic way to draw shapes glClearColor(0,0,0,0); // else black for(i = 0; i < crt_vs; i++) // handles main body of array { for(j = 0; j < crt_rs; j++) { draw_cube(verts->shape_verts, verts->shape_normals, verts->cube_tex, i,j,i,j+1,i+1,j+1,i+1,j, RED); // draws shape } } for (i = 0; i < crt_vs; i ++) // connects the sides { // textures can be manipulated on the stack as well glMatrixMode(GL_TEXTURE); glLoadIdentity(); glRotatef(90.0, 0, 0, 1); draw_cube(verts->shape_verts, verts->shape_normals, verts->cube_tex, i, crt_rs, i+1, crt_rs, i + 1, 0, i, 0, RED); glRotatef(-90.0, 0, 0, 1); glMatrixMode(GL_MODELVIEW); } if(my_objects[num_objects - 1].sid == 0 || my_objects[num_objects].sid == 1) // fixes cube and house normal { for(i = 0; i < 2; i++) // draws tops of house and cube { draw_cube(verts->shape_verts,verts->shape_normals, verts->cube_tex, crt_vs - i, 0, crt_vs - i, 1, crt_vs - i, 2, crt_vs - i, 3, RED); } } }
// Render a cube with ID w at x, y. This function is used to render the inventory // blocks, like the belt and the inventory screen. void render_inventory_block(Attrib *attrib, int w, float s, float x, float y, int flag) { glUseProgram(attrib->program); glUniform3f(attrib->camera, 0, 0, 5); glUniform1i(attrib->sampler, 0); // GL_TEXTURE0 glUniform1f(attrib->timer, PI*2); float identity[16]; mat_identity(identity); glUniformMatrix4fv(attrib->extra5, 1, GL_FALSE, identity); float matrix[16]; GLuint buffer; // Default block rotations float rx = -PI/4; float ry = -PI/10; float rz = 0; float dz = 0; switch (flag) { case 1: rx = -PI/8; break; case 2: rx = -PI/8; ry = -PI/10; rz = -PI/16; dz = -1.0; break; case 3: rx = -PI/8; ry = -PI/10; rz = -PI/16; dz = 2.0; break; } set_matrix_item_r(matrix, g->width, g->height, s, x, y, rx, ry, rz); if (is_plant(w)) { glDeleteBuffers(1, &buffer); buffer = gen_plant_buffer(0, 0, dz, 0.5, w); } else { buffer = gen_cube_buffer(0, 0, dz, 0.5, w); } glUniformMatrix4fv(attrib->matrix, 1, GL_FALSE, matrix); if (is_plant(w)) { draw_plant(attrib, buffer); } else { draw_cube(attrib, buffer); } del_buffer(buffer); }
static void draw_mipmap_tree(int x, int y) { int i,j; for (i = 0; i < TEX_LEVELS; i++) { int cubes = num_layers / 6; for (j = 0; j < cubes; j++) { draw_cube(x + j*(DRAW_SIZE * 4 + 5), y + i*(DRAW_SIZE * 3 + 5), i, j); } } }
void glut_display(){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0, 1.0, 0.1, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(g_distance*cos(g_angle2)*sin(g_angle1), g_distance*sin(g_angle2), g_distance*cos(g_angle2)*cos(g_angle1), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); draw_cube();//描画の登録 glFlush();//描画の画面への反映 glDisable(GL_DEPTH_TEST); glutSwapBuffers();//バッファの交換(ダブルバッファだから(裏で描画して、最後に反映)) }
/* * EduRaster drawing routines. */ static void draw(){ clear_buffer(); er_load_identity(); mat3 rotx, roty; rotatex_mat3(rotx, deg_to_rad(camera_phi)); rotatey_mat3(roty, deg_to_rad(camera_theta)); vec3 cam_pos = {0.0f, 0.0f, camera_offset}; mult_mat3_vec3(rotx, cam_pos, cam_pos); mult_mat3_vec3(roty, cam_pos, cam_pos); vec3 up_vec = {0.0f, 1.0f, 0.0f}; mult_mat3_vec3(rotx, up_vec, up_vec); mult_mat3_vec3(roty, up_vec, up_vec); er_look_at(cam_pos[0], cam_pos[1], cam_pos[2], 0.0f, 0.0f, 0.0f, up_vec[0], up_vec[1], up_vec[2]); draw_cube(1.5f); }
void display(void) { GLfloat m[4][4]; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); build_rotmatrix(m, curquat); glMultMatrixf(&m[0][0]); draw_cube(); glPopMatrix(); glutSwapBuffers(); }
void cal_projection(cube cube1){ q=sqrt(cop.x*cop.x + cop.y*cop.y + (cop.z-zp)*(cop.z-zp)); dx=cop.x/q; dy=cop.y/q ;dz=(cop.z-zp)/q; double x,y,z,xp,yp; int i; for(i=0;i<8;i++){ x=cube1.p[i].x; y=cube1.p[i].y; z=cube1.p[i].z; //printf("i= %d %lf %lf %lf\n",i,x,y,z); xp=x-(z*(dx/dz))+(zp*(dx/dz)); xp/=(((zp-z)/(q*dz))+1); yp=y-(z*(dy/dz))+(zp*(dy/dz)); yp/=(((zp-z)/(q*dz))+1); cube1.p[i].X=xp; cube1.p[i].Y=yp; } draw_cube(cube1); }
void translate(double edge[20][3]) { int a,b,c; int i; cout<<"Enter The Translation Factors"; cin>>a>>b>>c; initgraph(&gd,&gm,"..\bgi"); clearviewport(); for(i=0;i<20;i++) { edge[i][0]+=a; edge[i][0]+=b; edge[i][0]+=c; } draw_cube(edge); closegraph(); }
void scale(double edge[20][3]) { double a,b,c; int i; cout<<"Enter The Scaling Factors "; cin>>a>>b>>c; initgraph(&gd,&gm,"..\bgi"); clearviewport(); for(i=0;i<20;i++) { edge[i][0]=edge[i][0]*a; edge[i][1]=edge[i][1]*b; edge[i][2]=edge[i][2]*c; } draw_cube(edge); closegraph(); }
void disp(void) { mat4_t xform; quat_to_mat(xform, rot); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(pos.x, pos.y, pos.z); glMultMatrixf((float*)xform); draw_cube(); glutSwapBuffers(); }
void display() { glEnable(GL_DEPTH_TEST); glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60, 1, .1, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,0,5,0,0,0,0,1,0); glRotatef(x_angle, 0, 1,0); glRotatef(y_angle, 1,0,0); glScalef(scale_size, scale_size, scale_size); if (toggle_draw_pathlines == true) draw_pathlines(); else if (toggle_animate_pathlines == true) animate_pathlines(); // just draw a simple bounding box, scaled to match the aspect // ration of the field glPushMatrix(); glScalef(1.0, len[1]/len[0], len[2]/len[0]); draw_cube(0,0,1); glPopMatrix(); // draw axes glBegin(GL_LINES); glColor3f(1,0,0); // red: X glVertex3f(0,0,0); glVertex3f(1,0,0); glColor3f(0,1,0); // green: Y glVertex3f(0,0,0); glVertex3f(0,1,0); glColor3f(0,0,1); // blue: Z glVertex3f(0,0,0); glVertex3f(0,0,1); glEnd(); glutSwapBuffers(); }