int parse_cylinder(t_env *env, char **line) { int i[2]; t_tobj tobj; t_cylinder *obj; t_list *lst; if (env->scene == NULL) return (return_print("Error, a scene must be declared first", 0)); if ((obj = (t_cylinder *)ft_memalloc(sizeof(t_obj))) == NULL || (lst = ft_lstnewfrom(obj, sizeof(*obj))) == NULL) return (return_print("malloc error", 0)); init_cylinder(env, &tobj, obj); i[0] = 0; i[1] = 0; while (line[++i[0]]) if (parse_cyl_2(line, i, set_objenv(env, (t_obj *)obj, &tobj)) == 0) return (0); transform_object((t_obj *)obj, &tobj); obj->inter = cylinder_inter; obj->normal = cylinder_normal; if (env->scene->objects == NULL) env->scene->objects = lst; else ft_lstadd(&(env->scene->objects), lst); return (i[1] == 1 ? 1 : return_print("error cylinder imcomplete", 0)); }
void CyberGloveBasic::vt_read_lowres_hand_model(char infilename[], VirtualHand hand) { int finger,joint,numobjects; FILE *inputfp; matrix4x4 totmatrix; static vec3d digitvec,scalevec; Boolean right_handed; if (hand->right_hand != NULL) right_handed = *(hand->right_hand); else right_handed = TRUE; inputfp = fopen(infilename,"r"); /* skip any comments at the beginning of the file */ skip_comments(inputfp); fscanf(inputfp,"\tTotal Number of Objects In World:%d\n",&numobjects); if (numobjects < 3) printf("WARNING in vt_read_hand_model: file contains too few objects"); vt_read_object(inputfp,&(hand->surface->forearm)); vt_set_vec3(3.5,1.0,1.5,scalevec); if (!right_handed) scalevec[VX] = -scalevec[VX]; vt_scale_matrix(scalevec,totmatrix); transform_object(&(hand->surface->forearm),totmatrix); vt_calculate_face_normals(&(hand->surface->forearm),right_handed); vt_calculate_dihedral_angles(&(hand->surface->forearm)); vt_calculate_vertex_normals(&(hand->surface->forearm)); vt_read_object(inputfp,&(hand->surface->palm)); vt_set_vec3(1.0,1.0,1.0,scalevec); if (!right_handed) scalevec[VX] = -scalevec[VX]; vt_scale_matrix(scalevec,totmatrix); transform_object(&(hand->surface->palm),totmatrix); vt_calculate_face_normals(&(hand->surface->palm),right_handed); vt_calculate_dihedral_angles(&(hand->surface->palm)); vt_calculate_vertex_normals(&(hand->surface->palm)); for (finger=THUMB; finger < FINGERS; finger++) for (joint=MCP; joint < ABDUCT; joint++) { vt_read_object(inputfp,&(hand->surface->digit[finger][joint])); vt_vec_sub3(hand->geom[finger][joint],hand->geom[finger][joint+1], digitvec); vt_set_vec3(1.0,vt_vec_length3(digitvec)/5.0,1.0,scalevec); if (!right_handed) scalevec[VX] = -scalevec[VX]; vt_scale_matrix(scalevec,totmatrix); transform_object(&(hand->surface->digit[finger][joint]),totmatrix); vt_calculate_face_normals(&(hand->surface->digit[finger][joint]), right_handed); vt_calculate_dihedral_angles(&(hand->surface->digit[finger][joint])); vt_calculate_vertex_normals(&(hand->surface->digit[finger][joint])); } fclose(inputfp); }
void CyberGloveBasic::vt_read_hand_model(char infilename[], VirtualHand hand, char *glovedir) { int finger,joint,numobjects; vec3d thumb_roll_vecs[2]; vec3d geom[5][4]; FILE *inputfp; matrix4x4 totmatrix,rotmatrix; static vec3d scalevec = {0.4475,0.4475,0.4475}; static vec3d transvec = {-0.06,4.2,0.1}; Boolean right_handed; char geomfile[100]; /* cout << "\nReading "<< infilename << " ..."; */ if (hand->right_hand != NULL) right_handed = *(hand->right_hand); else right_handed = TRUE; inputfp = fopen(infilename,"r"); /* skip any comments at the beginning of the file */ skip_comments(inputfp); fscanf(inputfp,"\tTotal Number of Objects In World:%d\n",&numobjects); if (numobjects < (1+FINGERS*ABDUCT)) printf("WARNING in vt_read_hand_model: file contains too few objects"); /* the palm and first phalanx of the thumb were created at a different */ /* scale and orientation than the rest of the model, so we use a different */ /* transform for them */ vt_rot_matrix(M_PI,'z',totmatrix); vt_mult_scale_matrix(scalevec,Postmult,totmatrix); vt_mult_trans_matrix(transvec,Postmult,totmatrix); vt_mult_rot_matrix(M_PI,'z',Postmult,totmatrix); /* Viewpoint has their hand pointing in the -y direction !@%$&*^ */ vt_rot_matrix(M_PI,'z',rotmatrix); vt_read_object(inputfp,&(hand->surface->forearm)); transform_object(&(hand->surface->forearm),rotmatrix); vt_read_object(inputfp,&(hand->surface->palm)); transform_object(&(hand->surface->palm),totmatrix); for (finger=THUMB; finger < FINGERS; finger++) for (joint=MCP; joint < ABDUCT; joint++) { vt_read_object(inputfp,&(hand->surface->digit[finger][joint])); if ((finger == THUMB) && (joint == MCP)) transform_object(&(hand->surface->digit[finger][joint]),totmatrix); else transform_object(&(hand->surface->digit[finger][joint]),rotmatrix); vt_calculate_face_normals(&(hand->surface->digit[finger][joint]), right_handed); vt_calculate_dihedral_angles(&(hand->surface->digit[finger][joint])); vt_calculate_vertex_normals(&(hand->surface->digit[finger][joint])); } /* HACK ALERT hardwired filename - LJE */ sprintf(geomfile, "%s/%s", glovedir, "hand_model.geom"); read_model_geom(geomfile,geom,thumb_roll_vecs); adjust_hand_model_geometry(geom,thumb_roll_vecs,hand); vt_calculate_face_normals(&(hand->surface->forearm),right_handed); vt_calculate_dihedral_angles(&(hand->surface->forearm)); vt_calculate_vertex_normals(&(hand->surface->forearm)); vt_calculate_face_normals(&(hand->surface->palm),right_handed); vt_calculate_dihedral_angles(&(hand->surface->palm)); vt_calculate_vertex_normals(&(hand->surface->palm)); for (finger=THUMB; finger < FINGERS; finger++) for (joint=MCP; joint < ABDUCT; joint++) { vt_calculate_face_normals(&(hand->surface->digit[finger][joint]), right_handed); vt_calculate_dihedral_angles(&(hand->surface->digit[finger][joint])); vt_calculate_vertex_normals(&(hand->surface->digit[finger][joint])); } fclose(inputfp); }
static void adjust_hand_model_geometry(vec3d geom[5][4], vec3d thumb_roll_vecs[2], VirtualHand hand) { UserGeometry user = hand->private_data->user; vec3d angles,scalevec,segvec,jointpos,handmodelpos,tempvec; matrix4x4 rotmatrix,transmatrix,scalematrix,totmatrix; float length_model_seg,length_hand_seg; int finger,joint; for (finger=THUMB; finger < FINGERS; finger++) { for (joint=MCP; joint < ABDUCT; joint++) { translation_fudge_factors(finger,joint,jointpos); angle_fudge_factors(finger,joint,angles); scale_fudge_factors(finger,joint,scalevec); /* first we move the joint to the origin */ vt_vec_add3(jointpos,geom[finger][joint],jointpos); vt_vec_neg3(jointpos,jointpos); vt_trans_matrix(jointpos,transmatrix); /* then we rotate it */ vt_vec_diff3(geom[finger][joint],geom[finger][joint+1],segvec); /* we align by rotating around z first then x */ angles[VZ] += M_PI/2.0 - atan2(segvec[VY],segvec[VX]); vt_rot_matrix(angles[VZ],'z',rotmatrix); vt_transform3(segvec,rotmatrix,segvec); angles[VX] += -atan2(segvec[VZ],segvec[VY]); vt_mult_rot_matrix(angles[VX],'x',Postmult,rotmatrix); if ((finger == THUMB) && (joint != MCP)) /* we also roll */ { vt_copy_vec3(thumb_roll_vecs[joint-1],tempvec); vt_transform3(thumb_roll_vecs[joint-1],rotmatrix, thumb_roll_vecs[joint-1]); /* after being transformed the roll vec should be perpendicular */ /* to the y-axis we assume roll vec is pointing to the inside of the */ /* thumb. NOTE: below we do not negate the value returned by atan2 */ /* this is because for the x-z plane the angle returned by atan2 */ /* is the negative of the actual angle */ angles[VY] += atan2(thumb_roll_vecs[joint-1][VZ], thumb_roll_vecs[joint-1][VX]); vt_mult_rot_matrix(angles[VY],'y',Premult,rotmatrix); } /* finally we scale it */ length_model_seg = vt_vec_length3(segvec); vt_vec_diff3(user->geom[finger][joint],user->geom[finger][joint+1],segvec); length_hand_seg = vt_vec_length3(segvec); scalevec[VY] *= length_hand_seg/length_model_seg; scalevec[VX] *= 1.8; scalevec[VZ] *= 1.8; if (user->right_hand != TRUE) scalevec[VX] = -scalevec[VX]; vt_scale_matrix(scalevec,scalematrix); vt_mult_matrix(transmatrix,rotmatrix,totmatrix); vt_mult_matrix(totmatrix,scalematrix,totmatrix); transform_object(&(hand->surface->digit[finger][joint]),totmatrix); } } /* lets do the hand now... */ vt_set_vec3(0.06,-4.21,0.0,handmodelpos); vt_vec_neg3(handmodelpos,handmodelpos); vt_trans_matrix(handmodelpos,transmatrix); /* determine scaling of hand model based on the location of the user's first */ /* knuckle of the index finger relative to the origin */ vt_set_vec3(0.06,-4.21,0.0,handmodelpos); vt_vec_diff3(handmodelpos,geom[INDEX][MCP],jointpos); if ((jointpos[VX] != 0.0) && (user->geom[INDEX][MCP][VX] != 0.0)) scalevec[VX] = fabs(user->geom[INDEX][MCP][VX]/jointpos[VX]); else scalevec[VX] = 1.0; /* can't get there by scaling! */ if ((jointpos[VY] != 0.0) && (user->geom[INDEX][MCP][VY] != 0.0)) scalevec[VY] = fabs(user->geom[INDEX][MCP][VY]/jointpos[VY]); else scalevec[VY] = 1.0; /* can't get there by scaling! */ scalevec[VX] *= 1.1; scalevec[VZ] = 1.9; if (user->right_hand != TRUE) scalevec[VX] = -scalevec[VX]; vt_scale_matrix(scalevec,scalematrix); vt_mult_matrix(transmatrix,scalematrix,totmatrix); transform_object(&(hand->surface->palm),totmatrix); /* lets do the forearm now... translation and scaling of forearm are same */ /* as hand, so we just reuse totmatrix */ transform_object(&(hand->surface->forearm),totmatrix); }
int SearObject::init(const std::string &file_name) { assert(m_initialised == false); std::string object; if (m_config.readFromFile(file_name)) { if (m_config.findItem(SECTION_model, KEY_filename)) { object = (std::string)m_config.getItem(SECTION_model, KEY_filename); } else { fprintf(stderr, "[SearObject] Error: No SearObject filename specified.\n"); return 1; } } else { fprintf(stderr, "[SearObject] Error reading %s as varconf file. Trying as SearObject file.\n", file_name.c_str()); object = file_name; } System::instance()->getFileHandler()->getFilePath(object); // Load SearObject file if (load(object)) { // Error loading object fprintf(stderr, "[SearObject] Error loading SearObject %s\n", object.c_str()); m_static_objects.clear(); return 1; } // Initialise transform matrix float matrix[4][4]; for (int j = 0; j < 4; ++j) { for (int i = 0; i < 4; ++i) { if (i == j) matrix[j][i] = 1.0f; else matrix[j][i] = 0.0f; } } bool do_transform = false; if (m_config.findItem(SECTION_model, KEY_rotation)) { const std::string &str=(std::string)m_config.getItem(SECTION_model, KEY_rotation); float w,x,y,z; sscanf(str.c_str(), "%f;%f;%f;%f", &w, &x, &y, &z); WFMath::Quaternion q(w,x,y,z); QuatToMatrix(q, matrix); do_transform = true; } if (m_config.findItem(SECTION_model, KEY_scale)) { double s = (double)m_config.getItem(SECTION_model, KEY_scale); for (int i = 0; i < 4; ++i) matrix[i][i] *= s; do_transform = true; } if (do_transform) { transform_object(m_static_objects, matrix); } bool ignore_minus_z = false; Scaling scale = SCALE_NONE; Alignment align = ALIGN_NONE; bool process_model = false; if (m_config.findItem(SECTION_model, KEY_ignore_minus_z)) { if ((bool)m_config.getItem(SECTION_model, KEY_ignore_minus_z)) { process_model = true; ignore_minus_z = true; } } if (m_config.findItem(SECTION_model, KEY_z_align)) { if ((bool)m_config.getItem(SECTION_model, KEY_z_align)) { process_model = true; align = ALIGN_Z; } } if (m_config.findItem(SECTION_model, KEY_align_mass)) { if ((bool)m_config.getItem(SECTION_model, KEY_align_mass)) { process_model = true; align = ALIGN_CENTRE_MASS; } } if (m_config.findItem(SECTION_model, KEY_align_bbox_hc)) { if ((bool)m_config.getItem(SECTION_model, KEY_align_bbox_hc)) { process_model = true; align = ALIGN_BBOX_HC; } } if (m_config.findItem(SECTION_model, KEY_align_bbox_lc)) { if ((bool)m_config.getItem(SECTION_model, KEY_align_bbox_lc)) { process_model = true; align = ALIGN_BBOX_LC; } } if (m_config.findItem(SECTION_model, KEY_align_extent)) { if ((bool)m_config.getItem(SECTION_model, KEY_align_extent)) { process_model = true; align = ALIGN_CENTRE_EXTENT; } } if (m_config.findItem(SECTION_model, KEY_scale_isotropic)) { if ((bool)m_config.getItem(SECTION_model, KEY_scale_isotropic)) { process_model = true; scale = SCALE_ISOTROPIC; } } else if (m_config.findItem(SECTION_model, KEY_scale_isotropic_x)) { if ((bool)m_config.getItem(SECTION_model, KEY_scale_isotropic_x)) { process_model = true; scale = SCALE_ISOTROPIC_Z; } } else if (m_config.findItem(SECTION_model, KEY_scale_isotropic_y)) { if ((bool)m_config.getItem(SECTION_model, KEY_scale_isotropic_y)) { process_model = true; scale = SCALE_ISOTROPIC_Y; } } else if (m_config.findItem(SECTION_model, KEY_scale_isotropic_z)) { if ((bool)m_config.getItem(SECTION_model, KEY_scale_isotropic_z)) { process_model = true; scale = SCALE_ISOTROPIC_Z; } } if (m_config.findItem(SECTION_model, KEY_scale_anisotropic)) { if ((bool)m_config.getItem(SECTION_model, KEY_scale_anisotropic)) { process_model = true; scale = SCALE_ANISOTROPIC; } } if (process_model == true) { scale_object(m_static_objects, scale, align, ignore_minus_z); } contextCreated(); m_initialised = true; return 0; }