void GLUI_Rotation::iaction_draw_active_area_persp( void ) { if ( NOT can_draw() ) return; copy_float_array_to_ball(); setup_texture(); setup_lights(); glEnable(GL_CULL_FACE ); glMatrixMode( GL_MODELVIEW ); glPushMatrix(); mat4 tmp_rot = *ball->rot_ptr; glMultMatrixf( (float*) &tmp_rot[0][0] ); /*** Draw the checkered box ***/ /*glDisable( GL_TEXTURE_2D ); */ draw_ball( 1.96 ); glPopMatrix(); glDisable( GL_TEXTURE_2D ); glDisable( GL_LIGHTING ); glDisable( GL_CULL_FACE ); }
void GLUI_Rotation::iaction_draw_active_area_persp( void ) { /********** arcball *******/ copy_float_array_to_ball(); setup_texture(); setup_lights(); glEnable(GL_CULL_FACE ); glMatrixMode( GL_MODELVIEW ); glPushMatrix(); mat4 tmp_rot = *ball->rot_ptr; glMultMatrixf( (float*) &tmp_rot[0][0] ); /*** Draw the checkered box ***/ /*glDisable( GL_TEXTURE_2D ); */ draw_ball(1.35); // 1.96 ); glPopMatrix(); glBindTexture(GL_TEXTURE_2D,0); /* unhook our checkerboard texture */ glDisable( GL_TEXTURE_2D ); glDisable( GL_LIGHTING ); glDisable( GL_CULL_FACE ); }
void Scene::render(){ glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMultMatrixd(mT.m); for (Object3D* o : childs) o->render(); setup_lights(); glPopMatrix(); }
ENTRYPOINT void init_queens(ModeInfo *mi) { int screen = MI_SCREEN(mi); Queenscreen *qs; wire = MI_IS_WIREFRAME(mi); if(!qss && !(qss = (Queenscreen *) calloc(MI_NUM_SCREENS(mi), sizeof(Queenscreen)))) return; qs = &qss[screen]; qs->window = MI_WINDOW(mi); qs->trackball = gltrackball_init (); qs->BOARDSIZE = 8; /* 8 cuz its classic */ if((qs->glx_context = init_GL(mi))) reshape_queens(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); else MI_CLEARWINDOW(mi); glClearColor(0.0, 0.0, 0.0, 0.0); glNewList(QUEEN, GL_COMPILE); qs->queen_polys = draw_model(countof(spidermodel), spidermodel, 24); glEndList(); if(flat) glShadeModel(GL_FLAT); clearbits = GL_COLOR_BUFFER_BIT; glColorMaterial(GL_FRONT, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); if(!wire) { setup_lights(qs); glEnable(GL_DEPTH_TEST); clearbits |= GL_DEPTH_BUFFER_BIT; clearbits |= GL_STENCIL_BUFFER_BIT; glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } else glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); /* find a solution */ go(qs); }
ENTRYPOINT void draw_queens(ModeInfo *mi) { Queenscreen *qs = &qss[MI_SCREEN(mi)]; Window w = MI_WINDOW(mi); Display *disp = MI_DISPLAY(mi); if(!qs->glx_context) return; glXMakeCurrent(disp, w, *(qs->glx_context)); if(flat) glShadeModel(GL_FLAT); clearbits = GL_COLOR_BUFFER_BIT; glColorMaterial(GL_FRONT, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); if(!wire) { setup_lights(qs); glEnable(GL_DEPTH_TEST); clearbits |= GL_DEPTH_BUFFER_BIT; clearbits |= GL_STENCIL_BUFFER_BIT; glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } else glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); mi->polygon_count = display(qs); mi->recursion_depth = qs->BOARDSIZE; if(mi->fps_p) do_fps(mi); glFinish(); glXSwapBuffers(disp, w); }
ENTRYPOINT void init_flipflop(ModeInfo *mi) { int screen; Flipflopcreen *c; if (MI_IS_WIREFRAME(mi)) textured = 0; /* Set all constants to their correct values */ if (board_avg_size != 0) { /* general size specified by user */ board_x_size = board_avg_size; board_y_size = board_avg_size; } else { board_avg_size = (board_x_size + board_y_size) / 2; } if ((numsquares == 0) && (freesquares != 0)) { numsquares = board_x_size * board_y_size - freesquares; } if (strcmp(flipflopmode_str, "tiles")) { textured = 0; /* textures look dumb in stick mode */ half_thick = 1.0 * DEF_STICK_THICK / 100.0; if (numsquares == 0) { /* No value defined by user */ numsquares = board_x_size * board_y_size * DEF_STICK_RATIO / 100; } } else { half_thick = 1.0 * DEF_TILE_THICK / 100.0; if (numsquares == 0) { /* No value defined by user */ numsquares = board_x_size * board_y_size * DEF_TILE_RATIO/ 100;; } } if (board_avg_size < 2) { fprintf (stderr,"%s: the board must be at least 2x2.\n", progname); exit(1); } if ((board_x_size < 1) || (board_y_size < 1) || (numsquares < 1)) { fprintf (stderr,"%s: the number of elements ('-count') and the dimensions of the board ('-size-x', '-size-y') must be positive integers.\n", progname); exit(1); } if (board_x_size * board_y_size <= numsquares) { fprintf (stderr,"%s: the number of elements ('-count') that you specified is too big \n for the dimensions of the board ('-size-x', '-size-y'). Nothing will move.\n", progname); } screen = MI_SCREEN(mi); wire = MI_IS_WIREFRAME(mi); if(!qs && !(qs = (Flipflopcreen *) calloc(MI_NUM_SCREENS(mi), sizeof(Flipflopcreen)))) return; c = &qs[screen]; c->window = MI_WINDOW(mi); c->trackball = gltrackball_init (False); c->flipspeed = 0.03; c->reldist = 1; c->energy = 40; if((c->glx_context = init_GL(mi))) reshape_flipflop(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); else MI_CLEARWINDOW(mi); /* At this point, all the constants have already been set, */ /* so we can create the board */ c->sheet = (randsheet*) malloc(sizeof(randsheet)); randsheet_create( c->sheet ); clearbits = GL_COLOR_BUFFER_BIT; glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); setup_lights(); glEnable(GL_DEPTH_TEST); clearbits |= GL_DEPTH_BUFFER_BIT; glEnable(GL_CULL_FACE); glCullFace(GL_BACK); randsheet_initialize( c->sheet ); if( textured ){ /* check for anisotropic filtering */ if(strstr((char *)glGetString(GL_EXTENSIONS), "GL_EXT_texture_filter_anisotropic")) glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &c->anisotropic); else c->anisotropic = 0; /* allocate a new texture and get it */ glGenTextures(1, &c->texid); get_texture(mi); } }
/** initialization handler */ ENTRYPOINT void init_chess(ModeInfo *mi) { Chesscreen *cs; int screen = MI_SCREEN(mi); if(!qs && !(qs = (Chesscreen *) calloc(MI_NUM_SCREENS(mi), sizeof(Chesscreen)))) return; cs = &qs[screen]; cs->window = MI_WINDOW(mi); cs->wire = MI_IS_WIREFRAME(mi); cs->trackball = gltrackball_init (); cs->oldwhite = -1; cs->colors[0][0] = 1.0; cs->colors[0][1] = 0.5; cs->colors[0][2] = 0.0; cs->colors[1][0] = 0.6; cs->colors[1][1] = 0.6; cs->colors[1][2] = 0.6; cs->done = 1; cs->count = 99; cs->mod = 1.4; /* cs->position[0] = 0.0; */ /* cs->position[1] = 5.0; */ /* cs->position[2] = 5.0; */ /* cs->position[3] = 1.0; */ cs->position[0] = 0.0; cs->position[1] = 24.0; cs->position[2] = 2.0; cs->position[3] = 1.0; cs->position2[0] = 5.0; cs->position2[1] = 5.0; cs->position2[2] = 5.0; cs->position2[3] = 1.0; cs->ground[0] = 0.0; cs->ground[1] = 1.0; cs->ground[2] = 0.0; cs->ground[3] = -0.00001; cs->oldgame = -1; if((cs->glx_context = init_GL(mi))) reshape_chess(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); else MI_CLEARWINDOW(mi); if (!cs->wire) { glDepthFunc(GL_LEQUAL); glClearStencil(0); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); make_piece_texture(cs); make_board_texture(cs); } gen_model_lists( classic, cs->poly_counts); if(!cs->wire) { setup_lights(cs); glColorMaterial(GL_FRONT, GL_DIFFUSE); glShadeModel(smooth ? GL_SMOOTH : GL_FLAT); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_DEPTH_TEST); } else glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); }
static void draw_scene(GLFWwindow* window, double t) { double xpos, ypos, zpos, angle_x, angle_y, angle_z; static double t_old = 0.0; float dt; // Calculate frame-to-frame delta time dt = (float) (t - t_old); t_old = t; glClearColor(0.1f, 0.1f, 0.1f, 1.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(65.0, aspect_ratio, 1.0, 60.0); // Setup camera glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Rotate camera angle_x = 90.0 - 10.0; angle_y = 10.0 * sin(0.3 * t); angle_z = 10.0 * t; glRotated(-angle_x, 1.0, 0.0, 0.0); glRotated(-angle_y, 0.0, 1.0, 0.0); glRotated(-angle_z, 0.0, 0.0, 1.0); // Translate camera xpos = 15.0 * sin((M_PI / 180.0) * angle_z) + 2.0 * sin((M_PI / 180.0) * 3.1 * t); ypos = -15.0 * cos((M_PI / 180.0) * angle_z) + 2.0 * cos((M_PI / 180.0) * 2.9 * t); zpos = 4.0 + 2.0 * cos((M_PI / 180.0) * 4.9 * t); glTranslated(-xpos, -ypos, -zpos); glFrontFace(GL_CCW); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); setup_lights(); glEnable(GL_LIGHTING); glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_EXP); glFogf(GL_FOG_DENSITY, 0.05f); glFogfv(GL_FOG_COLOR, fog_color); draw_floor(); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glDepthMask(GL_TRUE); draw_fountain(); glDisable(GL_LIGHTING); glDisable(GL_FOG); // Particles must be drawn after all solid objects have been drawn draw_particles(window, t, dt); // Z-buffer not needed anymore glDisable(GL_DEPTH_TEST); }
World::World(WindowFramework* windowFrameworkPtr) : m_windowFrameworkPtr(windowFrameworkPtr) { // preconditions if(m_windowFrameworkPtr == NULL) { nout << "ERROR: parameter windowFrameworkPtr cannot be NULL." << endl; return; } // This code puts the standard title and instruction text on screen COnscreenText title("title", COnscreenText::TS_plain); title.set_text("Panda3D: Tutorial - Joint Manipulation"); title.set_fg(Colorf(1,1,1,1)); title.set_pos(LVecBase2f(0.7, -0.95)); title.set_scale(0.07); title.reparent_to(m_windowFrameworkPtr->get_aspect_2d()); m_titleNp = title.generate(); m_esckeyTextNp = gen_label_text("ESC: Quit" , 0); m_onekeyTextNp = gen_label_text("[1]: Teapot" , 1); m_twokeyTextNp = gen_label_text("[2]: Candy cane", 2); m_threekeyTextNp = gen_label_text("[3]: Banana" , 3); m_fourkeyTextNp = gen_label_text("[4]: Sword" , 4); // setup key input m_windowFrameworkPtr->enable_keyboard(); m_windowFrameworkPtr->get_panda_framework()->define_key("escape", "Exit" , sys_exit , NULL); m_windowFrameworkPtr->get_panda_framework()->define_key("1" , "Teapot" , call_set_object<M_teapot >, this); m_windowFrameworkPtr->get_panda_framework()->define_key("2" , "CandyCane", call_set_object<M_candy_cane>, this); m_windowFrameworkPtr->get_panda_framework()->define_key("3" , "Banana" , call_set_object<M_banana >, this); m_windowFrameworkPtr->get_panda_framework()->define_key("4" , "Sword" , call_set_object<M_sword >, this); // Disable mouse-based camera-control // Note: disable by default in C++ // Position the camera m_windowFrameworkPtr->get_camera_group().set_pos(0,-15, 2); // Load our animated character // Note: File eve_walk.egg is broken! // The name of the animation is case sensitive and at line 13 of file // eve_walk.egg you should read `Eve' instead of `eve'. You need to // correct this in order to bind the animation automatically using // auto_bind() or WindowFramework::loop_animations(). Or you can use // PartGroup::HMF_ok_wrong_root_name to ask auto_bind() to be more // forgiving. CActor::AnimMap eveAnims; eveAnims["../models/eve_walk"].push_back("walk"); m_eve.load_actor(m_windowFrameworkPtr, "../models/eve", &eveAnims, PartGroup::HMF_ok_wrong_root_name); // Put it in the scene NodePath renderNp = m_windowFrameworkPtr->get_render(); m_eve.reparent_to(renderNp); // Now we use control_joint to get a NodePath that's in control of her neck // This must be done before any animations are played m_eveNeckNp = m_eve.control_joint("Neck"); // We now play an animation. An animation must be played, or at least posed // for the nodepath we just got from control_joint to actually effect the model m_eve.find_anim("walk")->set_play_rate(2); m_eve.loop("walk", true); // Now we add a task that will take care of turning the head PT(GenericAsyncTask) turnHeadTask = new GenericAsyncTask("turnHead", call_turn_head, this); if(turnHeadTask != NULL) { AsyncTaskManager::get_global_ptr()->add(turnHeadTask); } // Now we will expose the joint the hand joint. ExposeJoint allows us to // get the position of a joint while it is animating. This is different than // control_joint which stops that joint from animating but lets us move it. // This is particularly useful for putting an object (like a weapon) in an // actor's hand m_eveRightHandNp = m_eve.expose_joint("RightHand"); // This is a table with models, positions, rotations, and scales of objects to // be attached to our exposed joint. These are stock models and so they needed // to be repositioned to look right. vector<ModelData> positions(M_models); positions[M_teapot ] = ModelData("../models/teapot" , LVecBase3f(0.00,-0.66,-0.95), LVecBase3f(90, 0,90), 0.40); positions[M_candy_cane] = ModelData("../models/candycane", LVecBase3f(0.15,-0.99,-0.22), LVecBase3f(90, 0,90), 1.00); positions[M_banana ] = ModelData("../models/banana" , LVecBase3f(0.08,-0.10, 0.09), LVecBase3f( 0,-90, 0), 1.75); positions[M_sword ] = ModelData("../models/sword" , LVecBase3f(0.11, 0.19, 0.06), LVecBase3f( 0, 0,90), 1.00); // A list that will store our models objects m_modelsNp.reserve(M_models); NodePath modelsNp = m_windowFrameworkPtr->get_panda_framework()->get_models(); for(vector<ModelData>::iterator i = positions.begin(); i < positions.end(); ++i) { // Load the model NodePath np = m_windowFrameworkPtr->load_model(modelsNp, i->m_filename); // Position it np.set_pos(i->m_pos); // Rotate it np.set_hpr(i->m_hpr); // Scale it np.set_scale(i->m_scale); // Reparent the model to the exposed joint. That way when the joint moves, // the model we just loaded will move with it. np.reparent_to(m_eveRightHandNp); // Add it to our models list m_modelsNp.push_back(np); } // Make object 0 the first shown set_object(M_teapot); // Put in some default lighting setup_lights(); }