示例#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
文件: gl_light.c 项目: prophile/dim3
void gl_lights_build_from_model(model_draw *draw,view_glsl_light_list_type *light_list)
{
	int					n,cx,cy,cz,sz,idx;
	float				fx,fy,fz;
	d3pnt				pnt,min,max;
	matrix_type			mat;
	
		// need to move model if no rot on

	memmove(&pnt,&draw->pnt,sizeof(d3pnt));
		
	if (draw->no_rot.on) {
		matrix_rotate_y(&mat,draw->no_rot.ang.y);

		fx=(float)(pnt.x-draw->no_rot.center.x);
		fy=(float)(pnt.y-draw->no_rot.center.y);
		fz=(float)(pnt.z-draw->no_rot.center.z);
		
		matrix_vertex_multiply(&mat,&fx,&fy,&fz);
		
		pnt.x=((int)fx)+draw->no_rot.center.x;
		pnt.y=((int)fy)+draw->no_rot.center.y;
		pnt.z=((int)fz)+draw->no_rot.center.z;
	}

		// get model bounds

	sz=draw->size.x>>1;
	min.x=pnt.x-sz;
	max.x=pnt.x+sz;

	sz=draw->size.z>>1;
	min.z=pnt.z-sz;
	max.z=pnt.z+sz;

	min.y=pnt.y-draw->size.y;
	max.y=pnt.y;

		// any rotations

	cx=pnt.x+draw->center.x;
	cy=pnt.y+draw->center.y;
	cz=pnt.z+draw->center.z;

	rotate_point(&min.x,&min.y,&min.z,cx,cy,cz,draw->rot.x,draw->rot.y,draw->rot.z);
	rotate_point(&max.x,&max.y,&max.z,cx,cy,cz,draw->rot.x,draw->rot.y,draw->rot.z);

	gl_lights_build_from_box(&pnt,&min,&max,light_list);

		// do any tints

	for (n=0;n!=max_view_lights_per_poly;n++) {
		idx=n*3;

		light_list->col[idx]*=draw->tint.r;
		light_list->col[idx+1]*=draw->tint.g;
		light_list->col[idx+2]*=draw->tint.b;
	}

}
示例#3
0
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
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;
	}
}
示例#5
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);
}
示例#6
0
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);
}
示例#7
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
}
示例#8
0
void rotate_2D_point_center(int *x,int *z,float ang_y)
{
	float			fx,fy,fz;
	matrix_type		mat;
	
	matrix_rotate_y(&mat,ang_y);
	
	fx=(float)*x;
	fy=0;
	fz=(float)*z;
	matrix_vertex_multiply(&mat,&fx,&fy,&fz);
	*x=(int)fx;
	*z=(int)fz;
}
示例#9
0
void rotate_2D_point(int *x,int *z,int cx,int cz,float ang_y)
{
	float			fx,fy,fz;
	matrix_type		mat;
	
	matrix_rotate_y(&mat,ang_y);
	
	fx=(float)((*x)-cx);
	fy=0;
	fz=(float)((*z)-cz);
	matrix_vertex_multiply(&mat,&fx,&fy,&fz);
	
	*x=(int)fx+cx;
	*z=(int)fz+cz;
}
示例#10
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);
}
示例#11
0
void rotate_2D_polygon(int ptsz,int *x,int *z,int cx,int cz,float ang_y)
{
	int					n;
	int					*px,*pz;
	float				fx,fy,fz;
	matrix_type			mat;
	
	matrix_rotate_y(&mat,ang_y);
	
	px=x;
	pz=z;
	
	for (n=0;n<ptsz;n++) {
		fx=(float)((*px)-cx);
		fy=0;
		fz=(float)((*pz)-cz);
		matrix_vertex_multiply(&mat,&fx,&fy,&fz);
		*px++=(int)fx+cx;
		*pz++=(int)fz+cz;
	}
}
示例#12
0
void rotate_2D_line(int *lx,int *lz,int *rx,int *rz,int cx,int cz,float ang_y)
{
	float			fx,fy,fz;
	matrix_type		mat;
	
	matrix_rotate_y(&mat,ang_y);
	
	fx=(float)((*lx)-cx);
	fy=0;
	fz=(float)((*lz)-cz);
	matrix_vertex_multiply(&mat,&fx,&fy,&fz);
	*lx=(int)fx+cx;
	*lz=(int)fz+cz;
	
	fx=(float)((*rx)-cx);
	fy=0;
	fz=(float)((*rz)-cz);
	matrix_vertex_multiply(&mat,&fx,&fy,&fz);
	*rx=(int)fx+cx;
	*rz=(int)fz+cz;
}
示例#13
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;
}
示例#14
0
static void	auto_rotate_object(void)
{
	matrix_rotate_y(g_scop.model_matrix, 0.001f);
}
示例#15
0
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);
}
示例#16
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);
}
示例#17
0
int main(int argc, char *argv[]){
	//glfwSetKeyCallback(window, &keypress);
	GLFWwindow *window;
	GLuint VAO, VBO;
	GLuint program;
	GLuint crate;

	matrix camera, perspective, rotate, scale, translate;
	GLuint l_camera, l_rotate, l_scale, l_translate, l_time, l_perspective;
	float time;
	
	// init window
	window = dg_window(1920-192, 1080-108, "OpenGL Experiment");

	// init shaders
	dg_program(&program);
	  dg_attach("vertex.glsl", GL_VERTEX_SHADER);
	  dg_attach("fragment.glsl", GL_FRAGMENT_SHADER);
	dg_compile();
	
	// init texture
	crate = dg_texture("crate.jpg");

	// init model
	glGenBuffers(1, &VBO);
	glGenVertexArrays(1, &VAO);
	glBindVertexArray(VAO);
	glEnable(GL_DEPTH_TEST);
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, sizeof(MODEL_CUBE), MODEL_CUBE, GL_STATIC_DRAW);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(0));
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(3*sizeof(GLfloat)));
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glBindVertexArray(0);

	// locate shader variables
	l_scale = glGetUniformLocation(program, "scale");
	l_camera = glGetUniformLocation(program, "camera");
	l_rotate = glGetUniformLocation(program, "rotate");
	l_translate = glGetUniformLocation(program, "translate");
	l_perspective = glGetUniformLocation(program, "perspective");
	
	// init matrices
	matrix_perspective(&perspective, 90.0f, 90.0f, 0.1f, 100.0f);
	matrix_identity(&rotate);
	matrix_identity(&scale);
	matrix_identity(&translate);
	
	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // uncomment for wireframe

	while(!glfwWindowShouldClose(window)){
		glfwPollEvents();
		time = (float)(glfwGetTime() * 100);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

		//eye target up
		matrix_camera(&camera,
			// position 
			0.0f, 0.0f, 0.0f,
			// angle
			0.0f, 0.0f, 0.0f
		);
		
		glUseProgram(program);
		
		// send to gpu
		glUniform1f(l_time, time);
		glUniformMatrix4fv(l_camera, 1, GL_TRUE, camera.data);
		glUniformMatrix4fv(l_perspective, 1, GL_TRUE, perspective.data);
		
		// bind model
		glBindVertexArray(VAO);

			// calculate transformations
			matrix_scale(&scale, 1.0f, 1.0f, 1.0f);
			matrix_rotate_y(&rotate, time);
			matrix_translate(&translate, 0.0f, 0.0f, -1.0f);

			// send to gpu
			glUniformMatrix4fv(l_scale, 1, GL_TRUE, scale.data);
			glUniformMatrix4fv(l_rotate, 1, GL_TRUE, rotate.data);
			glUniformMatrix4fv(l_translate, 1, GL_TRUE, translate.data);
				
			// texture
			glBindTexture(GL_TEXTURE_2D, crate);

			// draw
			glDrawArrays(GL_TRIANGLES, 0, 36);

		// unbind model VAO
		glBindVertexArray(0);
		
		glfwSwapBuffers(window);
	}
	
	glfwTerminate();

	return EXIT_SUCCESS;
}
示例#18
0
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);
}