Пример #1
0
static void lakka_draw_icon(lakka_handle_t *lakka,
      GLuint texture, float x, float y,
      float alpha, float rotation, float scale)
{
   struct gl_coords coords;
   if (!lakka)
      return;

   if (alpha > lakka->global_alpha)
      alpha = lakka->global_alpha;

   if (alpha == 0)
      return;

   gl_t *gl = (gl_t*)driver_video_resolve(NULL);

   if (!gl)
      return;

   if (x < -lakka->icon_size || x > gl->win_width + lakka->icon_size
         || y < -lakka->icon_size || y > gl->win_height + lakka->icon_size)
      return;

   GLfloat color[] = {
      1.0f, 1.0f, 1.0f, alpha,
      1.0f, 1.0f, 1.0f, alpha,
      1.0f, 1.0f, 1.0f, alpha,
      1.0f, 1.0f, 1.0f, alpha,
   };

   if (gl->shader && gl->shader->use)
      gl->shader->use(gl, GL_SHADER_STOCK_BLEND);

   glViewport(x, gl->win_height - y, lakka->icon_size, lakka->icon_size);

   coords.vertices = 4;
   coords.vertex = lakka_vertex;
   coords.tex_coord = lakka_tex_coord;
   coords.lut_tex_coord = lakka_tex_coord;
   coords.color = color;
   glBindTexture(GL_TEXTURE_2D, texture);

   math_matrix mymat;

   math_matrix mrot;
   matrix_rotate_z(&mrot, rotation);
   matrix_multiply(&mymat, &mrot, &gl->mvp_no_rot);

   math_matrix mscal;
   matrix_scale(&mscal, scale, scale, 1);
   matrix_multiply(&mymat, &mscal, &mymat);

   gl->shader->set_coords(&coords);
   gl->shader->set_mvp(gl, &mymat);

   glEnable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   glDisable(GL_BLEND);
}
Пример #2
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;
}
Пример #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
void matrix_init_orthographic(float *m, float left, float right, float bottom, float top, float near, float far)
{
	float mo[4*4], mp[4*4];

	mo[0x0] = 2.0f/(right-left);
	mo[0x1] = 0.0f;
	mo[0x2] = 0.0f;
	mo[0x3] = -(right+left)/(right-left);

	mo[0x4] = 0.0f;
	mo[0x5] = 2.0f/(top-bottom);
	mo[0x6] = 0.0f;
	mo[0x7] = -(top+bottom)/(top-bottom);

	mo[0x8] = 0.0f;
	mo[0x9] = 0.0f;
	mo[0xA] = -2.0f/(far-near);
	mo[0xB] = (far+near)/(far-near);

	mo[0xC] = 0.0f;
	mo[0xD] = 0.0f;
	mo[0xE] = 0.0f;
	mo[0xF] = 1.0f;

	matrix_identity4x4(mp);
	mp[0xA] = 0.5;
	mp[0xB] = -0.5;

	//Convert Z [-1, 1] to [-1, 0] (PICA shiz)
	matrix_mult4x4(mp, mo, m);
	// Rotate 180 degrees
	matrix_rotate_z(m, M_PI);
	// Swap X and Y axis
	matrix_swap_xy(m);
}
Пример #6
0
void lakka_draw_icon(GLuint texture, float x, float y, float alpha, float rotation, float scale)
{
   GLfloat color[] = {
      1.0f, 1.0f, 1.0f, alpha,
      1.0f, 1.0f, 1.0f, alpha,
      1.0f, 1.0f, 1.0f, alpha,
      1.0f, 1.0f, 1.0f, alpha,
   };

   static const GLfloat vtest[] = {
      0, 0,
      1, 0,
      0, 1,
      1, 1
   };

   gl_t *gl = (gl_t*)driver.video_data;

   if (!gl)
      return;
   
   if (alpha > global_alpha)
      alpha = global_alpha;

   glViewport(x, gl->win_height - y, dim, dim);

   glEnable(GL_BLEND);

   gl->coords.vertex = vtest;
   gl->coords.tex_coord = vtest;
   gl->coords.color = color;
   glBindTexture(GL_TEXTURE_2D, texture);

   if (gl->shader && gl->shader->use)
      gl->shader->use(gl, GL_SHADER_STOCK_BLEND);

   math_matrix mymat;

   math_matrix mrot;
   matrix_rotate_z(&mrot, rotation);
   matrix_multiply(&mymat, &mrot, &gl->mvp_no_rot);

   math_matrix mscal;
   matrix_scale(&mscal, scale, scale, 1);
   matrix_multiply(&mymat, &mscal, &mymat);

   gl->coords.vertices = 4;
   gl_shader_set_coords(gl, &gl->coords, &mymat);

   glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   glDisable(GL_BLEND);

   gl->coords.vertex = gl->vertex_ptr;
   gl->coords.tex_coord = gl->tex_coords;
   gl->coords.color = gl->white_color_ptr;
}
Пример #7
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);
}
Пример #8
0
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
}
Пример #9
0
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);
}
Пример #10
0
static void lakka_draw_fbo(void)
{
   gl_t *gl = (gl_t*)driver_video_resolve(NULL);
   if (!gl)
      return;

   struct gl_coords coords;
   coords.vertices = 4;
   coords.vertex = lakka_vertex;
   coords.tex_coord = lakka_vertex;
   coords.color = gl->white_color_ptr;
   glBindTexture(GL_TEXTURE_2D, lakka->fbo_color);

   math_matrix mymat;

   math_matrix mrot;
   matrix_rotate_z(&mrot, 0);
   matrix_multiply(&mymat, &mrot, &gl->mvp_no_rot);

   math_matrix mscal;
   matrix_scale(&mscal, lakka->global_scale, lakka->global_scale, 1);
   matrix_multiply(&mymat, &mscal, &mymat);

   gl->shader->set_coords(&coords);
   gl->shader->set_mvp(gl, &mymat);

   glEnable(GL_BLEND);

   // shadow
   glViewport(2, -2, gl->win_width, gl->win_height);
   glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
   glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   glViewport(0, 0, gl->win_width, gl->win_height);

   glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
   glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

   glDisable(GL_BLEND);
}
Пример #11
0
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;
}
Пример #12
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);
}
Пример #13
0
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);
}