예제 #1
0
void select_model_get_drag_direction(d3pnt *pnt)
{
	float			fx,fy,fz;
	matrix_type		mat;
	
	fx=(float)pnt->x;
	fy=(float)pnt->y;
	fz=(float)pnt->z;

	if (state.model.ang.x!=0) {
		matrix_rotate_x(&mat,state.model.ang.x);
		matrix_vertex_multiply(&mat,&fx,&fy,&fz);
	}
	
	if (state.model.ang.y!=0) {
		matrix_rotate_y(&mat,angle_add(state.model.ang.y,180.0f));
		matrix_vertex_multiply(&mat,&fx,&fy,&fz);
	}
	
	if (state.model.ang.z!=0) {
		matrix_rotate_z(&mat,state.model.ang.z);
		matrix_vertex_multiply(&mat,&fx,&fy,&fz);
	}
	
	pnt->x=(int)fx;
	pnt->y=(int)fy;
	pnt->z=(int)fz;
}
예제 #2
0
파일: model_util_size.c 프로젝트: rzel/dim3
void model_get_view_complex_bounding_box(model_type *model,d3pnt *pnt,d3ang *ang,float resize,int *px,int *py,int *pz)
{
    int				n,yadd,sz;
	float			fx,fy,fz;
	matrix_type		rot_x_mat,rot_z_mat,rot_y_mat;
	
    sz=(int)((float)(model->view_box.size.x>>1)*resize);
    px[0]=px[3]=px[4]=px[7]=-sz;
    px[1]=px[2]=px[5]=px[6]=sz;
    
	yadd=model->view_box.size.y>>1;
	
    py[4]=py[5]=py[6]=py[7]=(int)(((float)yadd)*resize)-yadd;
    py[0]=py[1]=py[2]=py[3]=-(int)((float)(model->view_box.size.y+yadd)*resize)-yadd;
    
    sz=(int)((float)(model->view_box.size.z>>1)*resize);
    pz[0]=pz[1]=pz[4]=pz[5]=-sz;
    pz[2]=pz[3]=pz[6]=pz[7]=sz;

	matrix_rotate_x(&rot_x_mat,ang->x);
	matrix_rotate_z(&rot_z_mat,ang->z);
	matrix_rotate_y(&rot_y_mat,ang->y);

	for (n=0;n!=8;n++) {
		fx=(float)px[n];
		fy=(float)py[n];
		fz=(float)pz[n];
		matrix_vertex_multiply(&rot_x_mat,&fx,&fy,&fz);
		matrix_vertex_multiply(&rot_z_mat,&fx,&fy,&fz);
		matrix_vertex_multiply(&rot_y_mat,&fx,&fy,&fz);
		px[n]=((int)fx)+pnt->x;
		py[n]=((int)fy)+pnt->y;
		pz[n]=((int)fz)+pnt->z;
	}
}
예제 #3
0
파일: map_view_handle.c 프로젝트: rzel/dim3
void view_handle_create_single_rot_handle(d3pnt *pnt,d3vct *vct,d3ang *ang,d3pnt *hand_pnt)
{
	matrix_type		mat;

		// rotations
	
	if (ang!=NULL) {
		if (ang->x!=0) {
			matrix_rotate_x(&mat,ang->x);
			matrix_vertex_multiply(&mat,&vct->x,&vct->y,&vct->z);
		}
		
		if (ang->y!=0) {
			matrix_rotate_y(&mat,ang->y);
			matrix_vertex_multiply(&mat,&vct->x,&vct->y,&vct->z);
		}
		
		if (ang->z!=0) {
			matrix_rotate_z(&mat,ang->z);
			matrix_vertex_multiply(&mat,&vct->x,&vct->y,&vct->z);
		}
	}

		// make point

	hand_pnt->x=pnt->x+(int)vct->x;
	hand_pnt->y=pnt->y+(int)vct->y;
	hand_pnt->z=pnt->z+(int)vct->z;
}
예제 #4
0
static void	user_rotate(float pos_x, float pos_y)
{
	if (g_scop.prev_mouse_pos.x < 0)
		return ;
	matrix_rotate_y(g_scop.model_matrix,
		(g_scop.prev_mouse_pos.x - pos_x) / 500.0f);
	matrix_rotate_x(g_scop.model_matrix,
		(g_scop.prev_mouse_pos.y - pos_y) / 500.0f);
}
예제 #5
0
파일: view_draw_debug.c 프로젝트: rzel/dim3
void view_draw_debug_bounding_box(d3pnt *pnt,d3ang *ang,d3pnt *size)
{
	int				n,xsz,zsz,px[8],py[8],pz[8];
	float			fx,fy,fz;
	matrix_type		rot_x_mat,rot_y_mat,rot_z_mat;
	d3col			col;

		// bounding box

	xsz=size->x>>1;
	zsz=size->z>>1;

	px[0]=px[1]=px[4]=px[5]=-xsz;
	px[2]=px[3]=px[6]=px[7]=xsz;

	py[0]=py[1]=py[2]=py[3]=-size->y;
	py[4]=py[5]=py[6]=py[7]=0;

	pz[1]=pz[2]=pz[5]=pz[6]=-zsz;
	pz[0]=pz[3]=pz[4]=pz[7]=zsz;

	matrix_rotate_x(&rot_x_mat,ang->x);
	matrix_rotate_z(&rot_z_mat,ang->z);
	matrix_rotate_y(&rot_y_mat,ang->y);

	for (n=0;n!=8;n++) {
		fx=(float)px[n];
		fy=(float)py[n];
		fz=(float)pz[n];
		
		matrix_vertex_multiply(&rot_x_mat,&fx,&fy,&fz);
		matrix_vertex_multiply(&rot_z_mat,&fx,&fy,&fz);
		matrix_vertex_multiply(&rot_y_mat,&fx,&fy,&fz);
		
		px[n]=(int)fx;
		py[n]=(int)fy;
		pz[n]=(int)fz;
	}
	
	for (n=0;n!=8;n++) {
		px[n]=px[n]+pnt->x;
		py[n]=py[n]+pnt->y;
		pz[n]=pz[n]+pnt->z;
	}

		// draw box

	col.r=col.g=0.2f;
	col.b=1.0f;

	glLineWidth(2.0f);
	view_primitive_3D_line_cube(&col,1.0f,px,py,pz);
	glLineWidth(1.0f);
}
예제 #6
0
파일: ohm2013.c 프로젝트: sandb/ohm2013
static void
draw(void)
{
   GLfloat mat[16], projection[16];

   struct cube c;
   /* Set modelview/projection matrix */
   matrix_make_unity(mat);
   matrix_rotate_x(view_rotx, mat);
   matrix_rotate_y(view_roty, mat);
   matrix_rotate_z(view_rotz, mat);
   matrix_translate(0.0, 0.0, view_transz, mat);
   matrix_scale(view_scale, view_scale, view_scale, mat);

   matrix_make_projection(0.9, projection);

   //print_matrix(mat);

   glUniformMatrix4fv(u_projection, 1, GL_FALSE, projection);

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   start_cube();

   int a;
   for (a = 0; a < N_CUBES; a++) {
//      print_cube(&cubes[a]);
      update_cube(&cubes[a]);
      draw_a_cube(&cubes[a], mat);
      printf("a=%d\n",a);
      print_cube(&cubes[a]);
   }
   /*
   GLfloat i,j,k;
   #define LOW -4.0
   #define HIGH 4.0
   #define STEP 2.0
   for (i = LOW; i < HIGH; i += STEP) {
       for (j = LOW; j < HIGH; j += STEP) {
          for (k = HIGH+10.0; k > LOW+10.0; k -= STEP) {
             draw_cube(i, j, k, 0.0, 0.0, 0.0, 1.0, mat);
          }
       }
   }
   #undef LOW
   #undef HIGH
   #undef STEP
   */
   end_cube();
   #undef N
}
예제 #7
0
파일: ohm2013.c 프로젝트: sandb/ohm2013
void
draw_cube(GLfloat x, GLfloat y, GLfloat z, GLfloat rx, GLfloat ry, GLfloat rz, GLfloat scale, GLfloat *m) 
{
   GLfloat mat[16];
   memcpy(mat, m, sizeof(mat));

   matrix_scale(scale, scale, scale, mat);
   matrix_translate(x, y, z, mat);
   matrix_rotate_z(rz, mat);
   matrix_rotate_y(ry, mat);
   matrix_rotate_x(rx, mat);

   glUniformMatrix4fv(u_matrix, 1, GL_FALSE, mat);
   
   glDrawArrays(GL_TRIANGLE_STRIP, 0, N);
}
예제 #8
0
파일: positions.c 프로젝트: prophile/dim3
void model_get_point_position(model_draw_setup *draw_setup,int *x,int *y,int *z)
{
	int					cx,cy,cz;
	float				fx,fy,fz;
	matrix_type			rot_x_mat,rot_z_mat,rot_y_mat,sway_mat;
	
	fx=(float)*x;
	fz=(float)*z;
	fy=(float)*y;
	
		// sway
		
	matrix_rotate_zyx(&sway_mat,draw_setup->sway.x,draw_setup->sway.y,draw_setup->sway.z);
	matrix_vertex_multiply(&sway_mat,&fx,&fy,&fz);
		
		// rotate
		
	cx=draw_setup->center.x;
	cy=draw_setup->center.y;
	cz=draw_setup->center.z;
		
	fx-=(float)cx;
	fy-=(float)cy;
	fz-=(float)cz;
	
	matrix_rotate_x(&rot_x_mat,draw_setup->ang.x);
	matrix_rotate_z(&rot_z_mat,draw_setup->ang.z);
	matrix_rotate_y(&rot_y_mat,draw_setup->ang.y);
		
	matrix_vertex_multiply(&rot_x_mat,&fx,&fy,&fz);
	matrix_vertex_multiply(&rot_z_mat,&fx,&fy,&fz);
	matrix_vertex_multiply(&rot_y_mat,&fx,&fy,&fz);

	*x=(int)(fx+draw_setup->move.x)+cx;
	*y=(int)(fy+draw_setup->move.y)+cy;
	*z=(int)(fz+draw_setup->move.z)+cz;
}
예제 #9
0
파일: view_rtl_effect.c 프로젝트: rzel/dim3
void view_dim3rtl_effect_mesh_ring_update(effect_type *effect,int count,int image_offset)
{
	int						n,k,life_tick,idx,
							material_id;
	short					*polys,*vk;
	float					mx,my,mz,fx,fy,fz,
							outer_sz,inner_sz,rd,
							color_dif,alpha,gx,gy,g_size,
							f_count,f_tick;
	float					*vp,*uv;
	d3pnt					pnt;
	rtlColor				col;
	iface_ring_type			*ring;
	ring_effect_data		*eff_ring;
	matrix_type				mat_x,mat_y,mat_z;
	
	eff_ring=&effect->data.ring;
	ring=&iface.ring_list.rings[eff_ring->ring_idx];
	
		// get size
		
	life_tick=effect->life_tick;

	f_tick=(float)life_tick;
	f_count=(float)count;
	
	outer_sz=(float)(ring->end_outer_size-ring->start_outer_size);
	outer_sz=((outer_sz*f_count)/f_tick)+(float)ring->start_outer_size;

	inner_sz=(float)(ring->end_inner_size-ring->start_inner_size);
	inner_sz=((inner_sz*f_count)/f_tick)+(float)ring->start_inner_size;

		// setup images
		
	effect_image_animate_get_uv(count,image_offset,&ring->animate,&gx,&gy,&g_size);
	
		// position and ring rotation

	ring_draw_position(effect,count,&pnt);

	mx=(float)pnt.x;
	my=(float)pnt.y;
	mz=(float)pnt.z;

	fx=f_count*ring->rot.x;
	fx+=(fx*ring->rot_accel.x);
	fx=angle_add(eff_ring->ang.x,fx);

	fy=f_count*ring->rot.y;
	fy+=(fy*ring->rot_accel.y);
	fy=angle_add(eff_ring->ang.y,fy);

	fz=f_count*ring->rot.z;
	fz+=(fz*ring->rot_accel.z);
	fz=angle_add(eff_ring->ang.z,fz);

	matrix_rotate_x(&mat_x,-fx);
	matrix_rotate_z(&mat_z,fz);
	matrix_rotate_y(&mat_y,fy);

		// create the ring vertexes

	rtlSceneMeshMapVertexPointer(view_rtl_draw_scene_id,effect->rtl_mesh_id,(void**)&vp);
	rtlSceneMeshMapUVPointer(view_rtl_draw_scene_id,effect->rtl_mesh_id,(void**)&uv);

	for (n=0;n!=360;n+=10) {
		rd=((float)n)*ANG_to_RAD;

			// outer

		fx=cosf(rd)*outer_sz;
		fy=-(sinf(rd)*outer_sz);
		fz=0.0f;

		matrix_vertex_multiply(&mat_x,&fx,&fy,&fz);
		matrix_vertex_multiply(&mat_z,&fx,&fy,&fz);
		matrix_vertex_multiply(&mat_y,&fx,&fy,&fz);

		*vp++=mx+fx;
		*vp++=my+fy;
		*vp++=mz+fz;

		*uv++=gx+(g_size*((fx+outer_sz)/(outer_sz*2.0f)));
		*uv++=gy+(g_size*((fy+outer_sz)/(outer_sz*2.0f)));

			// inner

		fx=cosf(rd)*inner_sz;
		fy=-(sinf(rd)*inner_sz);
		fz=0.0f;

		matrix_vertex_multiply(&mat_x,&fx,&fy,&fz);
		matrix_vertex_multiply(&mat_z,&fx,&fy,&fz);
		matrix_vertex_multiply(&mat_y,&fx,&fy,&fz);

		*vp++=mx+fx;
		*vp++=my+fy;
		*vp++=mz+fz;

		*uv++=gx+(g_size*((fx+outer_sz)/(outer_sz*2.0f)));
		*uv++=gy+(g_size*((fy+outer_sz)/(outer_sz*2.0f)));
	}

	rtlSceneMeshUnMapVertexPointer(view_rtl_draw_scene_id,effect->rtl_mesh_id);
	rtlSceneMeshUnMapUVPointer(view_rtl_draw_scene_id,effect->rtl_mesh_id);

		// create the polys
		// last one needs to wrap around to beginning

	material_id=ring->rtl_material_id;

	polys=(short*)malloc(sizeof(short)*(36*10));
	vk=polys;

	idx=0;

	for (n=0;n!=36;n++) {
		*vk++=4;
		*vk++=material_id;

		*vk++=idx;
		*vk++=idx;

		*vk++=idx+1;
		*vk++=idx+1;

		if (n!=35) {
			k=idx+2;
		}
		else {
			k=0;
		}

		*vk++=k+1;
		*vk++=k+1;

		*vk++=k;
		*vk++=k;
		
		idx+=2;
	}

	rtlSceneMeshSetPoly(view_rtl_draw_scene_id,effect->rtl_mesh_id,RL_MESH_FORMAT_POLY_SHORT_VERTEX_UV,36,polys);
	free(polys);

		// set color and alpha

	color_dif=ring->end_color.r-ring->start_color.r;
    col.r=ring->start_color.r+((color_dif*f_count)/f_tick);
	color_dif=ring->end_color.g-ring->start_color.g;
    col.g=ring->start_color.g+((color_dif*f_count)/f_tick);
	color_dif=ring->end_color.b-ring->start_color.b;
    col.b=ring->start_color.b+((color_dif*f_count)/f_tick);

	alpha=ring->end_alpha-ring->start_alpha;
	col.a=((alpha*f_count)/f_tick)+ring->start_alpha;

	rtlSceneMeshSetPolyColorAll(view_rtl_draw_scene_id,effect->rtl_mesh_id,&col);
}
예제 #10
0
파일: view_rtl_effect.c 프로젝트: rzel/dim3
void view_dim3rtl_effect_mesh_particle_update(effect_type *effect,int count,int image_offset)
{
	int						n,k,idx,particle_count,quad_count,
							ntrail,pixel_dif,material_id;
	short					*polys,*vk;
	float					gravity,gx,gy,g_size,pixel_sz,f,trail_step,
							alpha_dif,color_dif,f_count,f_tick;
	float					*vp,*uv;
	d3pnt					pnt;
	d3ang					*rot_ang,rang;
	rtlColor				col;
	iface_particle_type		*particle;
	particle_effect_data	*eff_particle;
	matrix_type				pixel_x_mat,pixel_y_mat;

		// have a mesh?

	if (effect->rtl_mesh_id==-1) return;

		// get particle
	
	eff_particle=&effect->data.particle;
	particle=&iface.particle_list.particles[eff_particle->particle_idx];

	f_count=(float)count;

		// position
	
	particle_draw_position(effect,count,&pnt);
	
		// particle move rotation
		// we can have rotations from being attached to a bone of a model
		// or the timed rotations from the particle setup
		// we only want to set these up if the rotation is necessary as it
		// saves time over thousands of particles
		
	rot_ang=NULL;

	if (eff_particle->rot.on) {
		rang.x=eff_particle->rot.ang.x;
		rang.y=eff_particle->rot.ang.y;
		rang.z=eff_particle->rot.ang.z;
		rot_ang=&rang;
	}

	if ((particle->rot.x!=0.0f) || (particle->rot.y!=0.0f) || (particle->rot.z!=0.0f)) {

		if (rot_ang==NULL) {
			rang.x=rang.y=rang.z=0.0f;
			rot_ang=&rang;
		}

		f=f_count*particle->rot.x;
		f+=(f*particle->rot_accel.x);
		rot_ang->x=angle_add(rot_ang->x,f);

		f=f_count*particle->rot.y;
		f+=(f*particle->rot_accel.y);
		rot_ang->y=angle_add(rot_ang->y,f);

		f=f_count*particle->rot.z;
		f+=(f*particle->rot_accel.z);
		rot_ang->z=angle_add(rot_ang->z,f);
	}

		// particle billboard rotation
		
	matrix_rotate_x(&pixel_x_mat,view.render->camera.ang.x);
	matrix_rotate_y(&pixel_y_mat,view.render->camera.ang.y);
	
		// reverse
		
	if (particle->reverse) count=(effect->life_tick-count);

		// setup size

	f_tick=(float)effect->life_tick;
		
	pixel_dif=particle->end_pixel_size-particle->start_pixel_size;
    pixel_sz=(float)(particle->start_pixel_size+((pixel_dif*count)/effect->life_tick));
	
		// setup images
		
	effect_image_animate_get_uv(count,image_offset,&particle->animate,&gx,&gy,&g_size);

		// reduce x/z/y movement and add in offset
		
	count=count/10;

		// construct meshes
		// each particle is a quad

	quad_count=particle->count*(particle->trail_count+1);

	rtlSceneMeshMapVertexPointer(view_rtl_draw_scene_id,effect->rtl_mesh_id,(void**)&vp);
	rtlSceneMeshMapUVPointer(view_rtl_draw_scene_id,effect->rtl_mesh_id,(void**)&uv);

		// setup the vertexes

	particle_count=particle->count;
	ntrail=particle->trail_count+1;
	
	trail_step=particle->trail_step;
	f_count=(float)count;
		
	for (n=0;n!=ntrail;n++) {

			// get gravity

		gravity=particle_get_gravity(particle,count);

			// create mesh quads
			
		view_dim3rtl_effect_mesh_particle_quad(vp,uv,&pnt,rot_ang,pixel_sz,&pixel_x_mat,&pixel_y_mat,gravity,f_count,particle_count,particle->pieces[eff_particle->variation_idx],gx,gy,g_size);

		vp+=((particle->count*3)*4);
		uv+=((particle->count*2)*4);

			// reduce pixel sizes and counts for trails
			
		pixel_sz=pixel_sz*particle->reduce_pixel_fact;
		f_count-=trail_step;
	}

	rtlSceneMeshUnMapVertexPointer(view_rtl_draw_scene_id,effect->rtl_mesh_id);
	rtlSceneMeshUnMapUVPointer(view_rtl_draw_scene_id,effect->rtl_mesh_id);

		// build the polygons

	material_id=particle->rtl_material_id;

	polys=(short*)malloc(sizeof(short)*(quad_count*10));
	vk=polys;

	idx=0;

	for (n=0;n!=quad_count;n++) {
		*vk++=4;
		*vk++=material_id;
		for (k=0;k!=4;k++) {
			*vk++=idx;
			*vk++=idx;
			idx++;
		}
	}

	rtlSceneMeshSetPoly(view_rtl_draw_scene_id,effect->rtl_mesh_id,RL_MESH_FORMAT_POLY_SHORT_VERTEX_UV,quad_count,polys);
	free(polys);
	
		// setup color and alpha
		
	color_dif=particle->end_color.r-particle->start_color.r;
    col.r=particle->start_color.r+((color_dif*f_count)/f_tick);
	color_dif=particle->end_color.g-particle->start_color.g;
    col.g=particle->start_color.g+((color_dif*f_count)/f_tick);
	color_dif=particle->end_color.b-particle->start_color.b;
    col.b=particle->start_color.b+((color_dif*f_count)/f_tick);

	alpha_dif=particle->end_alpha-particle->start_alpha;
    col.a=particle->start_alpha+((alpha_dif*f_count)/f_tick);

	rtlSceneMeshSetPolyColorAll(view_rtl_draw_scene_id,effect->rtl_mesh_id,&col);
}
예제 #11
0
파일: view_draw.c 프로젝트: prophile/dim3
void view_draw_debug_bounding_box(obj_type *obj)
{
	int				n,xsz,ysz,zsz,px[8],py[8],pz[8];
	float			fx,fy,fz;
	matrix_type		rot_x_mat,rot_y_mat,rot_z_mat;
	model_type		*mdl;
	
	mdl=model_find_uid(obj->draw.uid);
	if (mdl==NULL) return;

		// bounding box

	xsz=obj->size.x>>1;
	zsz=obj->size.z>>1;
	
	ysz=obj->size.y;
	if (obj->duck.mode!=dm_stand) ysz-=obj->duck.y_move;

	px[0]=px[1]=px[4]=px[5]=-xsz;
	px[2]=px[3]=px[6]=px[7]=xsz;

	py[0]=py[1]=py[2]=py[3]=-ysz;
	py[4]=py[5]=py[6]=py[7]=0;

	pz[1]=pz[2]=pz[5]=pz[6]=-zsz;
	pz[0]=pz[3]=pz[4]=pz[7]=zsz;

	matrix_rotate_x(&rot_x_mat,obj->draw.setup.ang.x);
	matrix_rotate_z(&rot_z_mat,obj->draw.setup.ang.z);
	matrix_rotate_y(&rot_y_mat,obj->draw.setup.ang.y);

	for (n=0;n!=8;n++) {
		fx=(float)(px[n]-mdl->center.x);
		fy=(float)(py[n]-mdl->center.y);
		fz=(float)(pz[n]-mdl->center.z);
		
		matrix_vertex_multiply(&rot_x_mat,&fx,&fy,&fz);
		matrix_vertex_multiply(&rot_z_mat,&fx,&fy,&fz);
		matrix_vertex_multiply(&rot_y_mat,&fx,&fy,&fz);
		
		px[n]=((int)fx)+mdl->center.x;
		py[n]=((int)fy)+mdl->center.y;
		pz[n]=((int)fz)+mdl->center.z;
	}
	
	for (n=0;n!=8;n++) {
		px[n]=px[n]+obj->pnt.x;
		py[n]=py[n]+obj->pnt.y;
		pz[n]=pz[n]+obj->pnt.z;
	}

		// draw box

	glColor4f(0.2f,0.2f,1.0f,1.0f);
	glLineWidth(2.0f);

	glBegin(GL_LINE_LOOP);
	glVertex3i(px[0],py[0],pz[0]);
	glVertex3i(px[1],py[1],pz[1]);
	glVertex3i(px[2],py[2],pz[2]);
	glVertex3i(px[3],py[3],pz[3]);
	glEnd();

	glBegin(GL_LINE_LOOP);
	glVertex3i(px[4],py[4],pz[4]);
	glVertex3i(px[5],py[5],pz[5]);
	glVertex3i(px[6],py[6],pz[6]);
	glVertex3i(px[7],py[7],pz[7]);
	glEnd();

	glBegin(GL_LINES);
	glVertex3i(px[0],py[0],pz[0]);
	glVertex3i(px[4],py[4],pz[4]);
	glVertex3i(px[1],py[1],pz[1]);
	glVertex3i(px[5],py[5],pz[5]);
	glVertex3i(px[2],py[2],pz[2]);
	glVertex3i(px[6],py[6],pz[6]);
	glVertex3i(px[3],py[3],pz[3]);
	glVertex3i(px[7],py[7],pz[7]);
	glEnd();

	glLineWidth(1.0f);

	glColor4f(0.0f,0.0f,0.0f,1.0f);
}