Exemplo n.º 1
0
void rotate( const Model& hand, const Model& uarm, const Model& larm)
{
	//upperarm
	glPushMatrix();
	glTranslatef(0.0, 0.0, -25.0);
	glRotatef(App->rotshoulder, 1.0, 0.0, 0.0);
	glTranslatef(0.0, 0.0, 0.0);
	glPushMatrix();
	draw_model (uarm, App->smooth);

	//lowerarm
	glPushMatrix();
	glTranslatef(0.0, 0.0, 25.0);
	glRotatef(App->rotelbow, 1.0, 0.0, 0.0);
	glTranslatef(0.0, 0.0, 0.0);
	glPushMatrix();
	draw_model (larm, App->smooth);

	//Hand
	glPushMatrix();
	glTranslatef(0.0, 0.0, 25.0);
	glRotatef(App->rotwrist, 1.0, 0.0, 0.0);
	glTranslatef(0.0, 0.0, 0.0);
	glPushMatrix();
	draw_model (hand, App->smooth);
	glPopMatrix();

}
Exemplo n.º 2
0
void *visualise(void *shedule) {
    struct jsp **model = shedule;

    if (init_SDL())
        pthread_exit(NULL);

    int running = 1;
    SDL_Event event;

    while (running) {
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                running = 0;
            }
        }
        pthread_mutex_lock(&mutex);
        if (*model != NULL) {
            draw_model(*model);
        }
        pthread_mutex_unlock(&mutex);
    }

    if (colors) {
        afree(colors);
    }
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    pthread_exit(NULL);
}
Exemplo n.º 3
0
void draw_morph_object(object *obj)
{
//	int save_light;
	polymodel *po;
	fix light;
	morph_data *md;

	md = find_morph_data(obj);
	Assert(md != NULL);

	Assert(obj->rtype.pobj_info.model_num < N_polygon_models);

	po=&Polygon_models[obj->rtype.pobj_info.model_num];

	light = compute_object_light(obj,NULL);

	g3_start_instance_matrix(&obj->pos,&obj->orient);
	g3_set_interp_points(robot_points);

	draw_model(po,0,obj->rtype.pobj_info.anim_angles,light,md);

	g3_done_instance();

	#ifdef NEWDEMO
	if (Newdemo_state == ND_STATE_RECORDING)
		newdemo_record_morph_frame(md);
	#endif

}
Exemplo n.º 4
0
void draw_until_settled(model *m) {
  const float max_dist = 0.001;
  bool settled = false;

  v3 center = { SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 0 };
  translate_model(m, &center);

  while(!settled) {
    step_model(m, 1);

    //Render the scene
    SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
    SDL_RenderClear(ren);
    draw_model(ren, m);
    SDL_RenderPresent(ren);

    settled = true;
    for(int i = 0; i < m->nmasses; i++)
      if(v3dist(&m->masses[i].pos, &m->masses[i].prev_pos) > max_dist) {
        settled = false;
        break;
      }
  }
  
  center.x = -center.x;
  center.y = -center.y;
  translate_model(m, &center);
}
Exemplo n.º 5
0
void stage4_lake_draw(Vector pos) {	
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, get_tex("stage4/lake")->gltex);
	
	glPushMatrix();
	glTranslatef(pos[0], pos[1]+140, pos[2]);
	glScalef(15,15,15);
	
	draw_model("lake");
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(pos[0], pos[1]+944, pos[2]+50);
	glScalef(30,30,30);
	
	glBindTexture(GL_TEXTURE_2D, get_tex("stage4/mansion")->gltex);
	
	draw_model("mansion");
	glPopMatrix();
	
	
	glDisable(GL_TEXTURE_2D);
}
Exemplo n.º 6
0
void draw_for_n(model *m, int n) {
  v3 center = { SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 0 };
  translate_model(m, &center);

  for(int i = 0; i < n; i++) {
    step_model(m, 1);

    //Render the scene
    SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
    SDL_RenderClear(ren);
    draw_model(ren, m);
    SDL_RenderPresent(ren);

  }
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
//---------------------------描画------------------------------//
//左下が(0,0), 右上が(Nx,Ny)
void Solver::draw(complex<double> *p){
	double N = max(mField->getNx(),mField->getNy());
	double ws = 2.0*MAIN_WINDOW_X/WINDOW_W/N;
	double hs = 2.0*MAIN_WINDOW_H/WINDOW_H/N;
	for (int i = mField->getNpml(); i < mField->getNpx()-mField->getNpml(); i++){
		for (int j = mField->getNpml(); j < mField->getNpy()-mField->getNpml(); j++){
			int x = i-mField->getNpml();
			int y = j-mField->getNpml();
			//Color c = color( norm(p[index(i,j)]) );
			Color c = color(30.0*p[index(i,j)].real());
			glColor3d(c.red, c.green, c.blue);
			if(j==mField->getNpy()/2 || i==mField->getNpx()/2) glColor3d(1,1,1);
			
			glRectd(x*ws-1, y*hs-1, (x+1.0)*ws-1, (y+1.0)*hs-1);
				
		}
	}

	draw_model();
}
Exemplo n.º 9
0
int mainloop(SDL_Renderer *ren, model *m) {
  SDL_Event e;
  bool quit = 0;
  while(!quit) {
    while(SDL_PollEvent(&e)) {
      if(e.type == SDL_QUIT)
        quit = true;
      if(e.type == SDL_KEYDOWN)
        quit = true;
      if(e.type == SDL_MOUSEBUTTONDOWN)
        quit = true;
    }
    //Render the scene
    SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
    SDL_RenderClear(ren);

    step_model(m, 1);
    draw_model(ren, m);

    SDL_RenderPresent(ren);
  }
  return 0;
}
Exemplo n.º 10
0
static void ltgl_display(void)
{
  GLfloat v[4];

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glPolygonMode(GL_FRONT_AND_BACK, render_parameters.polygon_mode);
  /* initialize modelview matrix */
  glLoadIdentity ();
  if (render_parameters.lighting_mode)
  {
    glEnable(GL_LIGHTING);
    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
    v[0] = 0.2;
    v[1] = 0.2;
    v[2] = 0.2;
    v[3] = 1.0;
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, v);
    v[0] = -0.5;
    v[1] = 1.0;
    v[2] = 1.0;
    v[3] = 0.0;
    glLightfv(GL_LIGHT0, GL_POSITION, v);
    glEnable(GL_LIGHT0);
  }
  else
    glDisable(GL_LIGHTING);
  /* View transformation */
  glTranslatef(-render_parameters.view_position.x, -render_parameters.view_position.y, -render_parameters.view_position.z);
  ltgl_rotate_q(&(render_parameters.view_orientation));
  /* Model transformation */
  glTranslatef(render_parameters.model_position.x, render_parameters.model_position.y, render_parameters.model_position.z);
  ltgl_rotate_q(&(render_parameters.model_orientation));
  /* draw the plant */
  draw_model(&lstr_block, &render_parameters);
  glutSwapBuffers();
}
void display(void){

	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    glPushMatrix();

    // --- Positioning the cam on azimuthal installation
    glRotatef(cam.elevation, 1.0, 0.0, 0.0);
    glRotatef(cam.azimut, 0.0, 1.0, 0.0);
    glTranslatef(-cam.pos.x, -cam.pos.y, -cam.pos.z);
    glRotatef(-90, 1.0, 0.0, 0.0);

    // --- Axes
    glPushMatrix();
    glScalef(1.0, 1.0, 1.0);
    draw_reference_frame();
    glPopMatrix();

    // --- Draw plane
    if(!mesh_loaded) {
    	glColor3f (1.0, 1.0, 0.0);
        draw_plane(10,10);
    } else draw_model();

    // --- Draw tx antennas
    for(size_t i = 0; i < txs.size(); i++) draw_tx(txs[i]);

    // --- Draw rx antennas
    for(size_t i = 0; i < rxs.size(); i++) draw_rx(rxs[i]);

    draw_rays();

    glPopMatrix();

    glutSwapBuffers();
}
Exemplo n.º 12
0
void Application::render()
{
    // Begin the scene
    check_render( device->BeginScene() );
    // Setting constants
    float time = static_cast<float>( clock() )/static_cast<float>( CLOCKS_PER_SEC );

    D3DCOLOR ambient_color = ambient_light_enabled ? SHADER_VAL_AMBIENT_COLOR : BLACK;
    D3DCOLOR point_color = point_light_enabled ? SHADER_VAL_POINT_COLOR : BLACK;
    D3DXMATRIX shadow_proj_matrix = plane->get_projection_matrix(point_light_position);

    D3DXVECTOR3 texcoord_multiplier (1.0f/target_texture->get_float_width(), 1.0f/target_texture->get_float_height(), 0);

    set_shader_matrix( SHADER_REG_VIEW_MX,        camera.get_matrix()       );
    set_shader_float ( SHADER_REG_DIFFUSE_COEF,   SHADER_VAL_DIFFUSE_COEF   );
    set_shader_color ( SHADER_REG_AMBIENT_COLOR,  ambient_color             );
    set_shader_color ( SHADER_REG_POINT_COLOR,    point_color               );
    set_shader_point ( SHADER_REG_POINT_POSITION, point_light_position      );
    set_shader_vector( SHADER_REG_ATTENUATION,    SHADER_VAL_ATTENUATION    );
    set_shader_float ( SHADER_REG_SPECULAR_COEF,  SHADER_VAL_SPECULAR_COEF  );
    set_shader_float ( SHADER_REG_SPECULAR_F,     SHADER_VAL_SPECULAR_F     );
    set_shader_point ( SHADER_REG_EYE,            camera.get_eye()          );
    set_shader_matrix( SHADER_REG_SHADOW_PROJ_MX, shadow_proj_matrix        );
    set_shader_vector( SHADER_REG_SHADOW_ATTENUATION, SHADER_VAL_SHADOW_ATTENUATION );
    
    for( unsigned i = 0; i < FILTER_REGS_COUNT; ++i )
    {
        D3DXVECTOR3 texcoord_shift( 0, 0, 0 );
        texcoord_shift.x = SHADER_VAL_FILTER_TEXCOORD_SHIFT[i].x*texcoord_multiplier.x;
        texcoord_shift.y = SHADER_VAL_FILTER_TEXCOORD_SHIFT[i].x*texcoord_multiplier.y;
        set_shader_vector( SHADER_REG_FILTER_TEXCOORD_SHIFT + i, texcoord_shift );

        set_pixel_shader_float( SHADER_REG_FILTER + i, filter[ SHADER_VAL_INDEX_FILTER[i] ]/FILTER_COEFF );
    }

    // Set render target
    target_texture->set_as_target();
    check_render( device->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, BACKGROUND_COLOR, 1.0f, 0 ) );
    // Draw Light Source
    draw_model( light_source, time, false );
    // Draw Plane
    set_render_state( D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE );
    draw_model( plane, time, false );
    // Draw shadows if point_light_enabled
    set_render_state( D3DRS_ZENABLE, FALSE );
    set_render_state( D3DRS_STENCILFUNC, D3DCMP_EQUAL );
    set_render_state( D3DRS_STENCILPASS, D3DSTENCILOP_INCRSAT );
    set_render_state( D3DRS_ALPHABLENDENABLE, TRUE );
    if ( point_light_enabled )
    {
        for ( Models::iterator iter = models.begin(); iter != models.end(); ++iter )
        {
            draw_model( *iter, time, true );
        }
    }
    // Draw models
    set_render_state( D3DRS_ZENABLE, TRUE );
    set_render_state( D3DRS_STENCILFUNC, D3DCMP_ALWAYS );
    set_render_state( D3DRS_ALPHABLENDENABLE, FALSE );
    for ( Models::iterator iter = models.begin(); iter != models.end(); ++iter )
    {
        draw_model( *iter, time, false );
    }
    // Set render target
    target_texture->unset_as_target();

    // Draw target plane
    draw_model( target_plane, time, false );

    // End the scene
    check_render( device->EndScene() );
    
    // Present the backbuffer contents to the display
    check_render( device->Present( NULL, NULL, NULL, NULL ) );
}
Exemplo n.º 13
0
void draw_model(polymodel *pm,int submodel_num,vms_angvec *anim_angles,fix light,morph_data *md)
{
	int i,mn;
	int facing;
	int sort_list[MAX_SUBMODELS],sort_n;


	//first, sort the submodels

	sort_list[0] = submodel_num;
	sort_n = 1;

	for (i=0;i<pm->n_models;i++)

		if (md->submodel_active[i] && pm->submodel_parents[i]==submodel_num) {

			facing = g3_check_normal_facing(&pm->submodel_pnts[i],&pm->submodel_norms[i]);

			if (!facing)

				sort_list[sort_n++] = i;

			else {		//put at start
				int t;

				for (t=sort_n;t>0;t--)
					sort_list[t] = sort_list[t-1];

				sort_list[0] = i;

				sort_n++;


			}

		}
	

	//now draw everything

	for (i=0;i<sort_n;i++) {

		mn = sort_list[i];

		if (mn == submodel_num) {
 			int i;

			for (i=0;i<pm->n_textures;i++)		{
				texture_list_index[i] = ObjBitmaps[ObjBitmapPtrs[pm->first_texture+i]];
				texture_list[i] = &GameBitmaps[ObjBitmaps[ObjBitmapPtrs[pm->first_texture+i]].index];
			}

#ifdef PIGGY_USE_PAGING			
			// Make sure the textures for this object are paged in...
			piggy_page_flushed = 0;
			for (i=0;i<pm->n_textures;i++)	
				PIGGY_PAGE_IN( texture_list_index[i] );
			// Hmmm... cache got flushed in the middle of paging all these in,
			// so we need to reread them all in.
			if (piggy_page_flushed)	{
				piggy_page_flushed = 0;
				for (i=0;i<pm->n_textures;i++)	
					PIGGY_PAGE_IN( texture_list_index[i] );
			}
			// Make sure that they can all fit in memory.
			Assert( piggy_page_flushed == 0 );
#endif


			g3_draw_morphing_model(&pm->model_data[pm->submodel_ptrs[submodel_num]],texture_list,anim_angles,light,&md->morph_vecs[md->submodel_startpoints[submodel_num]]);

		}
		else {

			vms_matrix orient;

			vm_angles_2_matrix(&orient,&anim_angles[mn]);

			g3_start_instance_matrix(&pm->submodel_offsets[mn],&orient);

			draw_model(pm,mn,anim_angles,light,md);

			g3_done_instance();

		}
	}

}
Exemplo n.º 14
0
void draw_enhanced_actor(actor * actor_id)
{
	int i;
	double x_pos,y_pos,z_pos;
	float x_rot,y_rot,z_rot;
	//int texture_id;
	char *cur_frame;
	float healtbar_z=0;

	bind_texture_id(actor_id->texture_id);
	cur_frame=actor_id->tmp.cur_frame;

	//now, go and find the current frame
	i=get_frame_number(actor_id->body_parts->head, cur_frame);;
	if(i >= 0)healtbar_z=actor_id->body_parts->head->offsetFrames[i].box.max_z;

	glPushMatrix();//we don't want to affect the rest of the scene
	x_pos=actor_id->tmp.x_pos;
	y_pos=actor_id->tmp.y_pos;
	z_pos=actor_id->tmp.z_pos;

	if(z_pos==0.0f)//actor is walking, as opposed to flying, get the height underneath
		z_pos=-2.2f+height_map[actor_id->tmp.y_tile_pos*tile_map_size_x*6+actor_id->tmp.x_tile_pos]*0.2f;

	glTranslatef(x_pos+0.25f, y_pos+0.25f, z_pos);

	x_rot=actor_id->tmp.x_rot;
	y_rot=actor_id->tmp.y_rot;
	z_rot=actor_id->tmp.z_rot;
	z_rot+=180;//test
	z_rot=-z_rot;
	glRotatef(z_rot, 0.0f, 0.0f, 1.0f);
	glRotatef(x_rot, 1.0f, 0.0f, 0.0f);
	glRotatef(y_rot, 0.0f, 1.0f, 0.0f);

	if(actor_id->body_parts->legs)draw_model(actor_id->body_parts->legs,cur_frame,actor_id->ghost);
	if(actor_id->body_parts->torso)draw_model(actor_id->body_parts->torso,cur_frame,actor_id->ghost);
	if(actor_id->body_parts->head)draw_model(actor_id->body_parts->head,cur_frame,actor_id->ghost);

	if(actor_id->body_parts->weapon)
		{
			int glow;
			draw_model(actor_id->body_parts->weapon,cur_frame,actor_id->ghost);
			glow=actor_id->body_parts->weapon_glow;
			if(glow!=GLOW_NONE)draw_model_halo(actor_id->body_parts->weapon,cur_frame,glow_colors[glow].r,glow_colors[glow].g,glow_colors[glow].b);
		}

	if(actor_id->body_parts->shield)draw_model(actor_id->body_parts->shield,cur_frame,actor_id->ghost);
	if(actor_id->body_parts->helmet)draw_model(actor_id->body_parts->helmet,cur_frame,actor_id->ghost);
	if(actor_id->body_parts->cape)draw_model(actor_id->body_parts->cape,cur_frame,actor_id->ghost);


	//////
	glPopMatrix();//restore the scene
	//now, draw their damage

	glPushMatrix();
	glTranslatef(x_pos+0.25f, y_pos+0.25f, z_pos);
	glRotatef(-rz, 0.0f, 0.0f, 1.0f);

	draw_actor_banner(actor_id, healtbar_z);

	glPopMatrix();//we don't want to affect the rest of the scene
	//if(!actor_id->ghost)glEnable(GL_LIGHTING);

}
Exemplo n.º 15
0
void RenderState::paintGL() {
  this->view_matrix.setToIdentity();
  // whenever content is not loaded, load the content
  if ( !this->shader_program ) { this->load_content(); }
  // enable the scene's depth mask
  glDepthMask(GL_TRUE);
  // clear the depth z = 0.0f -> 1.0f
  glClearDepth(1.0f);
  // enable the scene's depth test
  glEnable(GL_DEPTH_TEST);
  // enable cullmode CCW (counter clockwise)
  glEnable(GL_CULL_FACE);
  // clear the background color for rendering
  glClearColor(104.0/255.0, 104.0/255.0, 104.0/255.0, 1);
  // clear the color and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // transform the camera's position with respect to the rotation matrix
  QVector3D cameraPosition = camera_transformation * QVector3D(0, 0, this->mouse_zoom);

  // define the direction of the camera's up vector
  QVector3D cameraUpDirection = camera_transformation * QVector3D(0, 1.0, 0);

  // implement and transform the camera
  this->view_matrix.lookAt(cameraPosition, QVector3D(), cameraUpDirection);
  this->view_matrix.translate(this->camera_previous);

  // return the position of the ray intersection with the y-axis
  QVector3D camara_zoom = QVector3D(- this->camera_previous.x(),
                                    - this->camera_previous.y(),
                                    - this->camera_previous.z());
  //this->view_matrix.rotate(this->prev_rotation_y, 1, 0, 0);
  //this->view_matrix.rotate(this->prev_rotation_x, 0, 1, 0);
  switch ( type_of_view ) {
   case 0 : camara_zoom.setY( camara_zoom.y() + this->mouse_zoom );
   break;
   case 1 : camara_zoom.setX( camara_zoom.x() - this->mouse_zoom );
   break;
   case 2 : camara_zoom.setZ( camara_zoom.z() + this->mouse_zoom );
   break;
   case 3 : this->view_matrix.rotate(-this->mouse_relative_y_drag, 1.0, 0, 0);
            this->view_matrix.rotate(-this->mouse_relative_x_drag, 0, 1.0, 0);
           // this->view_matrix.rotate(-45-this->mouse_y, 1, 0, 0);

   break;
  }
  QVector3D Pos  = this->intersect_plane(this->raycast_direction, camara_zoom);

  // update current position
  this->current_position->setX(Pos.x());
  this->current_position->setZ(Pos.z());
  this->current_position->setY(Pos.y());

  // draw select box
  if ( (this->mousedown_left) && (this->edit_vertex_enable) ) {
    draw_flat_box(*this->clicked_position, *this->current_position);
  }

  if ( (this->mousedown_left) && (this->translate_enable) ) {
    draw_line(*this->clicked_position,
              *this->current_position,
              this->view_matrix,
              QMatrix4x4(),
              QVector3D(1.0, 1.0, 1.0));
  }

  for (int a = 0; a < CurrentScene::mesh_count(); a++) {
    QMatrix4x4 translation;
    translation.translate(*CurrentScene::get_position(a));
    draw_model(CurrentScene::mesh_draw(a),
               this->view_matrix,
               translation,
               QMatrix4x4(),
               QVector3D(0.3, 0.0, 0.0));
    draw_model_vertices(CurrentScene::mesh_draw(a),
                        this->view_matrix,
                        translation,
                        QMatrix4x4(),
                        QVector3D(1.0, 0.0, 0.0), true);

    draw_model_vertices(CurrentScene::mesh_draw(a),
                        this->view_matrix,
                        translation,
                        QMatrix4x4(),
                        QVector3D(1.0, 1.0, 1.0), false);

  }
  draw_grid();
  if ( this->add_vertex_enable && ( this->type_of_view != 3 ) ) {
    QMatrix4x4 translation;
    translation.translate(Pos);
    draw_model(this->current_mesh,this->view_matrix,
               translation,
               QMatrix4x4(),
               QVector3D());
  }
  // release the program for this frame
  this->shader_program->release();
  // disable the cullmode for the frame
  glDisable(GL_CULL_FACE);
  // disable the depthtest for the frame
  glDisable(GL_DEPTH_TEST);
  // finish up the opengl frame
  glFinish();
}