void ObjRotate (obj_type_ptr p_object,int p_angle_x,int p_angle_y,int p_angle_z) { matrix_4x4_type l_matrix, l_res; //Range control if (p_angle_x<0) p_angle_x=3600+p_angle_x; if (p_angle_y<0) p_angle_y=3600+p_angle_y; if (p_angle_z<0) p_angle_z=3600+p_angle_z; if (p_angle_x<0 || p_angle_x>3600) p_angle_x=0; if (p_angle_y<0 || p_angle_y>3600) p_angle_y=0; if (p_angle_z<0 || p_angle_z>3600) p_angle_z=0; if (p_angle_x) { //The object matrix is multiplied by the X rotation matrix MatrIdentity_4x4(l_matrix); l_matrix[1][1]=(matr_cos_table[p_angle_x]); l_matrix[1][2]=(matr_sin_table[p_angle_x]); l_matrix[2][1]=(-matr_sin_table[p_angle_x]); l_matrix[2][2]=(matr_cos_table[p_angle_x]); MatrMul_4x4_4x4(l_matrix,p_object->matrix,l_res); MatrCopy_4x4(p_object->matrix,l_res); } if (p_angle_y) { // ...by the Y rotation matrix MatrIdentity_4x4(l_matrix); l_matrix[0][0]=(matr_cos_table[p_angle_y]); l_matrix[0][2]=(-matr_sin_table[p_angle_y]); l_matrix[2][0]=(matr_sin_table[p_angle_y]); l_matrix[2][2]=(matr_cos_table[p_angle_y]); MatrMul_4x4_4x4(l_matrix,p_object->matrix,l_res); MatrCopy_4x4(p_object->matrix,l_res); } if (p_angle_z) { // ...by the Z rotation matrix MatrIdentity_4x4(l_matrix); l_matrix[0][0]=(matr_cos_table[p_angle_z]); l_matrix[0][1]=(matr_sin_table[p_angle_z]); l_matrix[1][0]=(-matr_sin_table[p_angle_z]); l_matrix[1][1]=(matr_cos_table[p_angle_z]); MatrMul_4x4_4x4(l_matrix,p_object->matrix,l_res); MatrCopy_4x4(p_object->matrix,l_res); } }
char ObjLoad(char *p_object_name, char *p_texture_name, float p_pos_x, float p_pos_y, float p_pos_z, int p_rot_x, int p_rot_y, int p_rot_z) { if (Load3DS (&object[obj_qty],p_object_name)==0) return(0); //Object loading object[obj_qty].id_texture=LoadBMP(p_texture_name); // The Function LoadBitmap() returns the current texture ID ObjCalcNormals(&object[obj_qty]); //Once we have all the object data we need to calculate all the normals of the object's vertices MatrIdentity_4x4(object[obj_qty].matrix); //Object matrix init ObjPosition(&object[obj_qty], p_pos_x, p_pos_y, p_pos_z); // Object initial position ObjRotate(&object[obj_qty], p_rot_x, p_rot_y, p_rot_z); // Object initial rotation obj_qty++; // Let's increase the object number and get ready to load another object! return (1); // If all is ok then return 1 }
/*************************************************** * SUBROUTINE ObjScale(obj_type_ptr p_object) * This function scales the specified object * Input parameters: p_object = object *******************************************************/ void ObjScale(obj_type_ptr p_object,float s_x,float s_y,float s_z) { int j,k; matrix_4x4_type l_matrix, l_res; MatrIdentity_4x4(l_matrix); l_matrix[0][0]=s_x; l_matrix[1][1]=s_y; l_matrix[2][2]=s_z; //The object matrix is multiplied by a scalar matrix MatrMul_4x4_4x4(l_matrix,p_object->matrix,l_res); for(j=0;j<4;j++) for(k=0;k<4;k++) p_object->matrix[j][k]=l_res[j][k]; }
void ObjTranslate (obj_type_ptr p_object,float p_x,float p_y,float p_z) { int j,k; matrix_4x4_type l_matrix, l_res; MatrIdentity_4x4(l_matrix); l_matrix[3][0]=p_x; l_matrix[3][1]=p_y; l_matrix[3][2]=p_z; //The object matrix is multiplied by a translation matrix MatrMul_4x4_4x4(l_matrix,p_object->matrix,l_res); for(j=0;j<4;j++) for(k=0;k<4;k++) p_object->matrix[j][k]=l_res[j][k]; }