这篇教程C++ vm_vec_scale函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中vm_vec_scale函数的典型用法代码示例。如果您正苦于以下问题:C++ vm_vec_scale函数的具体用法?C++ vm_vec_scale怎么用?C++ vm_vec_scale使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了vm_vec_scale函数的22个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: scale_matrix//performs aspect scaling on global view matrixvoid scale_matrix(void){ Unscaled_matrix = View_matrix; //so we can use unscaled if we want Matrix_scale = Window_scale; if (View_zoom <= 1.0) //zoom in by scaling z Matrix_scale.xyz.z = Matrix_scale.xyz.z*View_zoom; else { //zoom out by scaling x&y float s = (float)1.0 / View_zoom; Matrix_scale.xyz.x = Matrix_scale.xyz.x*s; Matrix_scale.xyz.y = Matrix_scale.xyz.y*s; } //now scale matrix elements vm_vec_scale(&View_matrix.vec.rvec,Matrix_scale.xyz.x ); vm_vec_scale(&View_matrix.vec.uvec,Matrix_scale.xyz.y ); vm_vec_scale(&View_matrix.vec.fvec,Matrix_scale.xyz.z );}
开发者ID:chief1983,项目名称:Imperial-Alliance,代码行数:26,
示例2: set_chase_matrix// ---------------------------------------------------------------------------------------------------// Do chase mode.// View current segment (Cursegp) from the previous segment.void set_chase_matrix(segment *sp){ int v; vms_vector forvec = ZERO_VECTOR, upvec; vms_vector tv = ZERO_VECTOR; segment *psp; // move back two segments, if possible, else move back one, if possible, else use current if (IS_CHILD(sp->children[WFRONT])) { psp = &Segments[sp->children[WFRONT]]; if (IS_CHILD(psp->children[WFRONT])) psp = &Segments[psp->children[WFRONT]]; } else psp = sp; for (v=0; v<MAX_VERTICES_PER_SEGMENT; v++) vm_vec_add2(&forvec,&Vertices[sp->verts[v]]); vm_vec_scale(&forvec,F1_0/MAX_VERTICES_PER_SEGMENT); for (v=0; v<MAX_VERTICES_PER_SEGMENT; v++) vm_vec_add2(&tv,&Vertices[psp->verts[v]]); vm_vec_scale(&tv,F1_0/MAX_VERTICES_PER_SEGMENT); Ed_view_target = forvec; vm_vec_sub2(&forvec,&tv); extract_up_vector_from_segment(psp,&upvec); if (!((forvec.x == 0) && (forvec.y == 0) && (forvec.z == 0))) vm_vector_2_matrix(&LargeView.ev_matrix,&forvec,&upvec,NULL);}
开发者ID:CDarrow,项目名称:Spectator-JinX,代码行数:35,
示例3: scale_matrix//performs aspect scaling on global view matrixstatic void scale_matrix(void){ Unscaled_matrix = View_matrix; //so we can use unscaled if we want Matrix_scale = Window_scale; if (View_zoom <= f1_0) //zoom in by scaling z Matrix_scale.z = fixmul(Matrix_scale.z,View_zoom); else { //zoom out by scaling x&y fix s = fixdiv(f1_0,View_zoom); Matrix_scale.x = fixmul(Matrix_scale.x,s); Matrix_scale.y = fixmul(Matrix_scale.y,s); } //now scale matrix elements vm_vec_scale(View_matrix.rvec,Matrix_scale.x); vm_vec_scale(View_matrix.uvec,Matrix_scale.y); vm_vec_scale(View_matrix.fvec,Matrix_scale.z);}
开发者ID:dxx-rebirth,项目名称:dxx-rebirth,代码行数:26,
示例4: nav_warpvoid nav_warp(bool prewarp=false){ /* ok... find our end distance - norm1 is still a unit vector in the direction from the flight leader to the navpoint */ vec3d targetPos, tpos=Autopilot_flight_leader->pos, pos, velocity; /* calculate a vector that we can use to make a path from the flight leader's location to the nav point */ vm_vec_sub(&pos, Navs[CurrentNav].GetPosition(), &Autopilot_flight_leader->pos); vm_vec_normalize(&pos); velocity = pos; // make a copy for later when we do setup veleocity vector vm_vec_scale(&pos, 250.0f); // we move by increments of 250 /* using the vector of the flight leaders's path, simulate moving the flight along this path by checking the autopilot conditions as specific intervals along the path*/ while (CanAutopilot(tpos)) { vm_vec_add(&tpos, &tpos, &pos); } vm_vec_sub(&targetPos, &tpos, &Autopilot_flight_leader->pos); /* targetPos is actually a vector that describes the exact 3D movement that the flgith leader needs to execute to reach the location that the auto pilot is to shut off */ // Check if we are actually just setting up for the cinimatic shot of the // flight flying on autopilot. Only jump halfway. Also we also need to // put the camera in the correct position to show the player this cinimatic if (prewarp) { vm_vec_scale(&targetPos, 0.5); vm_vec_add(&cameraPos, &cameraPos, &targetPos); } /* calcuate the speed that everyone is supposed to be going so that there is no need for anyone to accelerate or decelerate (most obvious with the player's fighter slowing down as it changes the camera pan speed). */ Assert( Ai_info[Ships[Autopilot_flight_leader->instance].ai_index].waypoint_speed_cap > 0 ); vm_vec_scale(&velocity, (float)Ai_info[Ships[Autopilot_flight_leader->instance].ai_index].waypoint_speed_cap); // Find all ships that are supposed to autopilot with the player and move them // to the cinimatic location or the final destination for (int i = 0; i < MAX_SHIPS; i++) { if (Ships[i].objnum != -1 && (Ships[i].flags2 & SF2_NAVPOINT_CARRY || (Ships[i].wingnum != -1 && Wings[Ships[i].wingnum].flags & WF_NAV_CARRY))) { vm_vec_add(&Objects[Ships[i].objnum].pos, &Objects[Ships[i].objnum].pos, &targetPos); Objects[Ships[i].objnum].phys_info.vel = velocity; } } // retime all collision pairs obj_collide_retime_cached_pairs();}
开发者ID:derek-yeung,项目名称:fs2open.github.com,代码行数:56,
示例5: ObjectMoveDown// ------------------------------------------------------------------------------------------------------int ObjectMoveDown(void){ object *obj; vms_vector uvec; vms_vector newpos; if (Cur_object_index == -1) { editor_status("No current object, cannot move."); return 1; } obj = &Objects[Cur_object_index]; extract_up_vector_from_segment(&Segments[obj->segnum], &uvec); vm_vec_normalize(&uvec); vm_vec_sub(&newpos, &obj->pos, vm_vec_scale(&uvec, OBJ_SCALE)); if (!verify_object_seg(obj, &newpos)) obj->pos = newpos; Update_flags |= UF_WORLD_CHANGED; return 1;}
开发者ID:devint1,项目名称:descent-win,代码行数:26,
示例6: physics_apply_whackvoid physics_apply_whack(vec3d *impulse, vec3d *pos, physics_info *pi, matrix *orient, float mass){ vec3d local_torque, torque;// vec3d npos; // Detect null vector. if ((fl_abs(impulse->xyz.x) <= WHACK_LIMIT) && (fl_abs(impulse->xyz.y) <= WHACK_LIMIT) && (fl_abs(impulse->xyz.z) <= WHACK_LIMIT)) return; // first do the rotational velocity // calculate the torque on the body based on the point on the // object that was hit and the momentum being applied to the object vm_vec_crossprod(&torque, pos, impulse); vm_vec_rotate ( &local_torque, &torque, orient ); vec3d delta_rotvel; vm_vec_rotate( &delta_rotvel, &local_torque, &pi->I_body_inv ); vm_vec_scale ( &delta_rotvel, (float) ROTVEL_WHACK_CONST ); vm_vec_add2( &pi->rotvel, &delta_rotvel ); //mprintf(("Whack: %7.3f %7.3f %7.3f/n", pi->rotvel.xyz.x, pi->rotvel.xyz.y, pi->rotvel.xyz.z)); // instant whack on the velocity // reduce damping on all axes pi->flags |= PF_REDUCED_DAMP; update_reduced_damp_timestamp( pi, vm_vec_mag(impulse) ); // find time for shake from weapon to end int dtime = timestamp_until(pi->afterburner_decay); if (dtime < WEAPON_SHAKE_TIME) { pi->afterburner_decay = timestamp( WEAPON_SHAKE_TIME ); } // Goober5000 - pi->mass should probably be just mass, as specified in the header vm_vec_scale_add2( &pi->vel, impulse, 1.0f / mass ); if (!(pi->flags & PF_USE_VEL) && (vm_vec_mag_squared(&pi->vel) > MAX_SHIP_SPEED*MAX_SHIP_SPEED)) { // Get DaveA nprintf(("Physics", "speed reset in physics_apply_whack [speed: %f]/n", vm_vec_mag(&pi->vel))); vm_vec_normalize(&pi->vel); vm_vec_scale(&pi->vel, (float)RESET_SHIP_SPEED); } vm_vec_rotate( &pi->prev_ramp_vel, &pi->vel, orient ); // set so velocity will ramp starting from current speed // ramped velocity is now affected by collision}
开发者ID:DahBlount,项目名称:Freespace-Open-Swifty,代码行数:45,
示例7: supernova_do_particlesvoid supernova_do_particles(){ int idx; vec3d a, b, ta, tb; vec3d norm, sun_temp; // no player ship if((Player_obj == NULL) || (Player_ship == NULL)) { return; } // timestamp if((Supernova_particle_stamp == -1) || timestamp_elapsed(Supernova_particle_stamp)) { Supernova_particle_stamp = timestamp(sn_particles); // get particle norm stars_get_sun_pos(0, &sun_temp); vm_vec_add2(&sun_temp, &Player_obj->pos); vm_vec_sub(&norm, &Player_obj->pos, &sun_temp); vm_vec_normalize(&norm); particle_emitter whee; whee.max_life = 1.0f; whee.min_life = 0.6f; whee.max_vel = 50.0f; whee.min_vel = 25.0f; whee.normal_variance = 0.75f; whee.num_high = 5; whee.num_low = 2; whee.min_rad = 0.5f; whee.max_rad = 1.25f; // emit for(idx=0; idx<10; idx++) { if ( Cmdline_old_collision_sys ) { submodel_get_two_random_points(Ship_info[Player_ship->ship_info_index].model_num, 0, &ta, &tb); } else { submodel_get_two_random_points_better(Ship_info[Player_ship->ship_info_index].model_num, 0, &ta, &tb); } // rotate into world space vm_vec_unrotate(&a, &ta, &Player_obj->orient); vm_vec_add2(&a, &Player_obj->pos); whee.pos = a; whee.vel = norm; vm_vec_scale(&whee.vel, 30.0f); vm_vec_add2(&whee.vel, &Player_obj->phys_info.vel); whee.normal = norm; particle_emit(&whee, PARTICLE_FIRE, 0); vm_vec_unrotate(&b, &tb, &Player_obj->orient); vm_vec_add2(&b, &Player_obj->pos); whee.pos = b; particle_emit(&whee, PARTICLE_FIRE, 0); } }}
开发者ID:DahBlount,项目名称:Freespace-Open-Swifty,代码行数:57,
示例8: extract_vector_from_segment_side// ------------------------------------------------------------------------------------------// Extract a vector from a segment. The vector goes from the start face to the end face.// The point on each face is the average of the four points forming the face.void extract_vector_from_segment_side(segment *sp, int side, vms_vector *vp, int vla, int vlb, int vra, int vrb){ vms_vector v1, v2; vm_vec_sub(&v1,&Vertices[sp->verts[Side_to_verts[side][vra]]],&Vertices[sp->verts[Side_to_verts[side][vla]]]); vm_vec_sub(&v2,&Vertices[sp->verts[Side_to_verts[side][vrb]]],&Vertices[sp->verts[Side_to_verts[side][vlb]]]); vm_vec_add(vp, &v1, &v2); vm_vec_scale(vp, F1_0/2);}
开发者ID:stephengeorgewest,项目名称:diiscent,代码行数:13,
示例9: dock_calc_docked_center_of_massvoid dock_calc_docked_center_of_mass(vec3d *dest, object *objp){ vm_vec_zero(dest); dock_function_info dfi; dfi.maintained_variables.vecp_value = dest; dock_evaluate_all_docked_objects(objp, &dfi, dock_calc_docked_center_of_mass_helper); // overall center of mass = weighted sum of centers of mass divided by total mass vm_vec_scale(dest, (1.0f / dfi.maintained_variables.float_value));}
开发者ID:Admiral-MS,项目名称:fs2open.github.com,代码行数:12,
示例10: dock_calc_docked_centervoid dock_calc_docked_center(vec3d *dest, object *objp){ vm_vec_zero(dest); dock_function_info dfi; dfi.maintained_variables.vecp_value = dest; dock_evaluate_all_docked_objects(objp, &dfi, dock_calc_docked_center_helper); // overall center = sum of centers divided by sum of objects vm_vec_scale(dest, (1.0f / (float) dfi.maintained_variables.int_value));}
开发者ID:Admiral-MS,项目名称:fs2open.github.com,代码行数:12,
示例11: Assertobject *object_create_debris(object *parent, int subobj_num){ int objnum; object *obj; polymodel *po; Assert((parent->type == OBJ_ROBOT) || (parent->type == OBJ_PLAYER) ); objnum = obj_create(OBJ_DEBRIS,0,parent->segnum,&parent->pos, &parent->orient,Polygon_models[parent->rtype.pobj_info.model_num].submodel_rads[subobj_num], CT_DEBRIS,MT_PHYSICS,RT_POLYOBJ); if ((objnum < 0 ) && (Highest_object_index >= MAX_OBJECTS-1)) { mprintf((1, "Can't create object in object_create_debris./n")); Int3(); return NULL; } if ( objnum < 0 ) return NULL; // Not enough debris slots! obj = &Objects[objnum]; Assert(subobj_num < 32); //Set polygon-object-specific data obj->rtype.pobj_info.model_num = parent->rtype.pobj_info.model_num; obj->rtype.pobj_info.subobj_flags = 1<<subobj_num; obj->rtype.pobj_info.tmap_override = parent->rtype.pobj_info.tmap_override; //Set physics data for this object po = &Polygon_models[obj->rtype.pobj_info.model_num]; obj->mtype.phys_info.velocity.x = RAND_MAX/2 - rand(); obj->mtype.phys_info.velocity.y = RAND_MAX/2 - rand(); obj->mtype.phys_info.velocity.z = RAND_MAX/2 - rand(); vm_vec_normalize_quick(&obj->mtype.phys_info.velocity); vm_vec_scale(&obj->mtype.phys_info.velocity,i2f(10 + (30 * rand() / RAND_MAX))); vm_vec_add2(&obj->mtype.phys_info.velocity,&parent->mtype.phys_info.velocity); vm_vec_make(&obj->mtype.phys_info.rotvel,10*0x2000/3,10*0x4000/3,10*0x7000/3); vm_vec_zero(&obj->mtype.phys_info.rotthrust); obj->lifeleft = DEBRIS_LIFE; obj->mtype.phys_info.mass = fixmuldiv(parent->mtype.phys_info.mass,obj->size,parent->size); obj->mtype.phys_info.drag = 0; //fl2f(0.2); //parent->mtype.phys_info.drag; return obj;}
开发者ID:devint1,项目名称:descent-win,代码行数:52,
示例12: create_view_matrixstatic matrix4 create_view_matrix(const vec3d *pos, const matrix *orient){ vec3d scaled_pos; vec3d inv_pos; matrix scaled_orient = *orient; matrix inv_orient; vm_vec_copy_scale(&scaled_pos, pos, -1.0f); vm_vec_scale(&scaled_orient.vec.fvec, -1.0f); vm_copy_transpose(&inv_orient, &scaled_orient); vm_vec_rotate(&inv_pos, &scaled_pos, &scaled_orient); matrix4 out; vm_matrix4_set_transform(&out, &inv_orient, &inv_pos); return out;}
开发者ID:mirakus-0f-tyr,项目名称:fs2open.github.com,代码行数:18,
示例13: collide_predict_large_ship// Return true if objp will collide with some large object.// Don't check for an object this ship is docked to.int collide_predict_large_ship(object *objp, float distance){ object *objp2; vec3d cur_pos, goal_pos; ship_info *sip; sip = &Ship_info[Ships[objp->instance].ship_info_index]; cur_pos = objp->pos; vm_vec_scale_add(&goal_pos, &cur_pos, &objp->orient.vec.fvec, distance); for ( objp2 = GET_FIRST(&obj_used_list); objp2 != END_OF_LIST(&obj_used_list); objp2 = GET_NEXT(objp2) ) { if ((objp != objp2) && (objp2->type == OBJ_SHIP)) { if (Ship_info[Ships[objp2->instance].ship_info_index].flags & (SIF_BIG_SHIP | SIF_HUGE_SHIP)) { if (dock_check_find_docked_object(objp, objp2)) continue; if (cpls_aux(&goal_pos, objp2, objp)) return 1; } } else if (!(sip->flags & (SIF_BIG_SHIP | SIF_HUGE_SHIP)) && (objp2->type == OBJ_ASTEROID)) { if (vm_vec_dist_quick(&objp2->pos, &objp->pos) < (distance + objp2->radius)*2.5f) { vec3d pos, delvec; int count; float d1; d1 = 2.5f * distance + objp2->radius; count = (int) (d1/(objp2->radius + objp->radius)); // Scale up distance, else looks like there would be a collision. pos = cur_pos; vm_vec_normalized_dir(&delvec, &goal_pos, &cur_pos); vm_vec_scale(&delvec, d1/count); for (; count>0; count--) { if (vm_vec_dist_quick(&pos, &objp2->pos) < objp->radius + objp2->radius) return 1; vm_vec_add2(&pos, &delvec); } } } } return 0;}
开发者ID:achilleas-k,项目名称:fs2open.github.com,代码行数:46,
示例14: set_view_target_from_segment// ---------------------------------------------------------------------------------------------------void set_view_target_from_segment(segment *sp){ vms_vector tv = ZERO_VECTOR; int v; if (Funky_chase_mode) { //set_chase_matrix(sp); } else { for (v=0; v<MAX_VERTICES_PER_SEGMENT; v++) vm_vec_add2(&tv,&Vertices[sp->verts[v]]); vm_vec_scale(&tv,F1_0/MAX_VERTICES_PER_SEGMENT); Ed_view_target = tv; } Update_flags |= UF_VIEWPOINT_MOVED;}
开发者ID:Foran,项目名称:dxx-rebirth,代码行数:22,
示例15: vm_vec_normalize// radar is damaged, so make blips dance aroundvoid HudGaugeRadarDradis::blipDrawDistorted(blip *b, vec3d *pos, float alpha){ float temp_scale; float dist = vm_vec_normalize(pos); vec3d out; float distortion_angle=20; // maybe alter the effect if EMP is active if (emp_active_local()) { temp_scale = emp_current_intensity(); dist *= frand_range(MAX(0.75f, 0.75f*temp_scale), MIN(1.25f, 1.25f*temp_scale)); distortion_angle *= frand_range(-3.0f,3.0f)*frand_range(0.0f, temp_scale); if (dist > 1.0f) dist = 1.0f; if (dist < 0.1f) dist = 0.1f; } vm_vec_random_cone(&out, pos, distortion_angle); vm_vec_scale(&out, dist); drawContact(&out, -1, unknown_contact_icon, b->dist, alpha, 1.0f);}
开发者ID:DahBlount,项目名称:Freespace-Open-Swifty,代码行数:24,
示例16: physics_collide_whackvoid physics_collide_whack( vec3d *impulse, vec3d *world_delta_rotvel, physics_info *pi, matrix *orient, bool is_landing ){ vec3d body_delta_rotvel; // Detect null vector. if ((fl_abs(impulse->xyz.x) <= WHACK_LIMIT) && (fl_abs(impulse->xyz.y) <= WHACK_LIMIT) && (fl_abs(impulse->xyz.z) <= WHACK_LIMIT)) return; vm_vec_rotate( &body_delta_rotvel, world_delta_rotvel, orient );// vm_vec_scale( &body_delta_rotvel, (float) ROTVEL_COLLIDE_WHACK_CONST ); vm_vec_add2( &pi->rotvel, &body_delta_rotvel ); update_reduced_damp_timestamp( pi, vm_vec_mag(impulse) ); // find time for shake from weapon to end if (!is_landing) { int dtime = timestamp_until(pi->afterburner_decay); if (dtime < WEAPON_SHAKE_TIME) { pi->afterburner_decay = timestamp( WEAPON_SHAKE_TIME ); } } pi->flags |= PF_REDUCED_DAMP; vm_vec_scale_add2( &pi->vel, impulse, 1.0f / pi->mass ); // check that collision does not give ship too much speed // reset if too high if (!(pi->flags & PF_USE_VEL) && (vm_vec_mag_squared(&pi->vel) > MAX_SHIP_SPEED*MAX_SHIP_SPEED)) { // Get DaveA nprintf(("Physics", "speed reset in physics_collide_whack [speed: %f]/n", vm_vec_mag(&pi->vel))); vm_vec_normalize(&pi->vel); vm_vec_scale(&pi->vel, (float)RESET_SHIP_SPEED); } vm_vec_rotate( &pi->prev_ramp_vel, &pi->vel, orient ); // set so velocity will ramp starting from current speed // ramped velocity is now affected by collision // rotate previous ramp velocity (in model coord) to be same as vel (in world coords)}
开发者ID:DahBlount,项目名称:Freespace-Open-Swifty,代码行数:36,
示例17: timestamp_rand// blip is for a target immune to sensors, so cause to flicker in/out with mild distortionvoid HudGaugeRadarDradis::blipDrawFlicker(blip *b, vec3d *pos, float alpha){ int flicker_index; float dist=vm_vec_normalize(pos); vec3d out; float distortion_angle=10; if ((b-Blips) & 1) flicker_index=0; else flicker_index=1; if (timestamp_elapsed(Radar_flicker_timer[flicker_index])) { Radar_flicker_timer[flicker_index] = timestamp_rand(50,1000); Radar_flicker_on[flicker_index] ^= 1; } if (!Radar_flicker_on[flicker_index]) return; if (rand() & 1) { distortion_angle *= frand_range(0.1f,2.0f); dist *= frand_range(0.75f, 1.25f); if (dist > 1.0f) dist = 1.0f; if (dist < 0.1f) dist = 0.1f; } vm_vec_random_cone(&out,pos,distortion_angle); vm_vec_scale(&out,dist); drawContact(&out, -1, unknown_contact_icon, b->dist, alpha, 1.0f);}
开发者ID:DahBlount,项目名称:Freespace-Open-Swifty,代码行数:37,
示例18: _do_slew_movementint _do_slew_movement(object *obj, int check_keys, int check_joy ){ int moved = 0; vms_vector svel, movement; //scaled velocity (per this frame) vms_matrix rotmat,new_pm; int joy_x,joy_y,btns; int joyx_moved,joyy_moved; vms_angvec rotang; if (keyd_pressed[KEY_PAD5]) vm_vec_zero(&obj->phys_info.velocity); if (check_keys) { obj->phys_info.velocity.x += VEL_SPEED * (key_down_time(KEY_PAD9) - key_down_time(KEY_PAD7)); obj->phys_info.velocity.y += VEL_SPEED * (key_down_time(KEY_PADMINUS) - key_down_time(KEY_PADPLUS)); obj->phys_info.velocity.z += VEL_SPEED * (key_down_time(KEY_PAD8) - key_down_time(KEY_PAD2)); rotang.pitch = (key_down_time(KEY_LBRACKET) - key_down_time(KEY_RBRACKET))/ROT_SPEED; rotang.bank = (key_down_time(KEY_PAD1) - key_down_time(KEY_PAD3))/ROT_SPEED; rotang.head = (key_down_time(KEY_PAD6) - key_down_time(KEY_PAD4))/ROT_SPEED; } else rotang.pitch = rotang.bank = rotang.head = 0; //check for joystick movement if (check_joy && joy_present) { joy_get_pos(&joy_x,&joy_y); btns=joy_get_btns(); joyx_moved = (abs(joy_x - old_joy_x)>JOY_NULL); joyy_moved = (abs(joy_y - old_joy_y)>JOY_NULL); if (abs(joy_x) < JOY_NULL) joy_x = 0; if (abs(joy_y) < JOY_NULL) joy_y = 0; if (btns) if (!rotang.pitch) rotang.pitch = fixmul(-joy_y * 512,FrameTime); else; else if (joyy_moved) obj->phys_info.velocity.z = -joy_y * 8192; if (!rotang.head) rotang.head = fixmul(joy_x * 512,FrameTime); if (joyx_moved) old_joy_x = joy_x; if (joyy_moved) old_joy_y = joy_y; } moved = rotang.pitch | rotang.bank | rotang.head; vm_angles_2_matrix(&rotmat,&rotang); vm_matrix_x_matrix(&new_pm,&obj->orient,&rotmat); obj->orient = new_pm; vm_transpose_matrix(&new_pm); //make those columns rows moved |= obj->phys_info.velocity.x | obj->phys_info.velocity.y | obj->phys_info.velocity.z; svel = obj->phys_info.velocity; vm_vec_scale(&svel,FrameTime); //movement in this frame vm_vec_rotate(&movement,&svel,&new_pm); vm_vec_add2(&obj->pos,&movement); moved |= (movement.x || movement.y || movement.z); return moved;}
开发者ID:NonCreature0714,项目名称:descent,代码行数:66,
示例19: do_endlevel_flythroughdo_endlevel_flythrough(int n){ object *obj; segment *pseg; int old_player_seg; flydata = &fly_objects[n]; obj = flydata->obj; old_player_seg = obj->segnum; //move the player for this frame if (!flydata->first_time) { vm_vec_scale_add2(&obj->pos,&flydata->step,FrameTime); angvec_add2_scale(&flydata->angles,&flydata->angstep,FrameTime); vm_angles_2_matrix(&obj->orient,&flydata->angles); } //check new player seg update_object_seg(obj); pseg = &Segments[obj->segnum]; if (flydata->first_time || obj->segnum != old_player_seg) { //moved into new seg vms_vector curcenter,nextcenter; fix step_size,seg_time; short entry_side,exit_side; //what sides we entry and leave through vms_vector dest_point; //where we are heading (center of exit_side) vms_angvec dest_angles; //where we want to be pointing vms_matrix dest_orient; int up_side; //find new exit side if (!flydata->first_time) { entry_side = matt_find_connect_side(obj->segnum,old_player_seg); exit_side = Side_opposite[entry_side]; } if (flydata->first_time || entry_side==-1 || pseg->children[exit_side]==-1) exit_side = find_exit_side(obj); { //find closest side to align to fix d,largest_d=-f1_0; int i; for (i=0;i<6;i++) { #ifdef COMPACT_SEGS vms_vector v1; get_side_normal(pseg, i, 0, &v1 ); d = vm_vec_dot(&v1,&flydata->obj->orient.uvec); #else d = vm_vec_dot(&pseg->sides[i].normals[0],&flydata->obj->orient.uvec); #endif if (d > largest_d) {largest_d = d; up_side=i;} } } //update target point & angles compute_center_point_on_side(&dest_point,pseg,exit_side); //update target point and movement points //offset object sideways if (flydata->offset_frac) { int s0=-1,s1,i; vms_vector s0p,s1p; fix dist; for (i=0;i<6;i++) if (i!=entry_side && i!=exit_side && i!=up_side && i!=Side_opposite[up_side]) if (s0==-1) s0 = i; else s1 = i; compute_center_point_on_side(&s0p,pseg,s0); compute_center_point_on_side(&s1p,pseg,s1); dist = fixmul(vm_vec_dist(&s0p,&s1p),flydata->offset_frac); if (dist-flydata->offset_dist > MAX_SLIDE_PER_SEGMENT) dist = flydata->offset_dist + MAX_SLIDE_PER_SEGMENT; flydata->offset_dist = dist; vm_vec_scale_add2(&dest_point,&obj->orient.rvec,dist); } vm_vec_sub(&flydata->step,&dest_point,&obj->pos); step_size = vm_vec_normalize_quick(&flydata->step); vm_vec_scale(&flydata->step,flydata->speed); compute_segment_center(&curcenter,pseg);//.........这里部分代码省略.........
开发者ID:NonCreature0714,项目名称:descent,代码行数:101,
示例20: physics_apply_shockvoid physics_apply_shock(vec3d *direction_vec, float pressure, physics_info *pi, matrix *orient, vec3d *min, vec3d *max, float radius){ vec3d normal; vec3d local_torque, temp_torque, torque; vec3d impact_vec; vec3d area; vec3d sin; if (radius > MAX_RADIUS) { return; } vm_vec_normalize_safe ( direction_vec ); area.xyz.x = (max->xyz.y - min->xyz.z) * (max->xyz.z - min->xyz.z); area.xyz.y = (max->xyz.x - min->xyz.x) * (max->xyz.z - min->xyz.z); area.xyz.z = (max->xyz.x - min->xyz.x) * (max->xyz.y - min->xyz.y); normal.xyz.x = vm_vec_dotprod( direction_vec, &orient->vec.rvec ); normal.xyz.y = vm_vec_dotprod( direction_vec, &orient->vec.uvec ); normal.xyz.z = vm_vec_dotprod( direction_vec, &orient->vec.fvec ); sin.xyz.x = fl_sqrt( fl_abs(1.0f - normal.xyz.x*normal.xyz.x) ); sin.xyz.y = fl_sqrt( fl_abs(1.0f - normal.xyz.y*normal.xyz.y) ); sin.xyz.z = fl_sqrt( fl_abs(1.0f - normal.xyz.z*normal.xyz.z) ); vm_vec_make( &torque, 0.0f, 0.0f, 0.0f ); // find the torque exerted due to the shockwave hitting each face // model the effect of the shockwave as if the shockwave were a plane of projectiles, // all moving in the direction direction_vec. then find the torque as the cross prod // of the force (pressure * area * normal * sin * scale * mass) // normal takes account the fraction of the surface exposed to the shockwave // the sin term is not technically needed but "feels" better // scale factors out the increase in area with larger objects // more massive objects get less rotation // find torque due to forces on the right/left face if ( normal.xyz.x < 0.0f ) // normal < 0, hits the right face vm_vec_copy_scale( &impact_vec, &orient->vec.rvec, max->xyz.x * pressure * area.xyz.x * normal.xyz.x * sin.xyz.x / pi->mass ); else // normal > 0, hits the left face vm_vec_copy_scale( &impact_vec, &orient->vec.rvec, min->xyz.x * pressure * area.xyz.x * -normal.xyz.x * sin.xyz.x / pi->mass ); vm_vec_crossprod( &temp_torque, &impact_vec, direction_vec ); vm_vec_add2( &torque, &temp_torque ); // find torque due to forces on the up/down face if ( normal.xyz.y < 0.0f ) vm_vec_copy_scale( &impact_vec, &orient->vec.uvec, max->xyz.y * pressure * area.xyz.y * normal.xyz.y * sin.xyz.y / pi->mass ); else vm_vec_copy_scale( &impact_vec, &orient->vec.uvec, min->xyz.y * pressure * area.xyz.y * -normal.xyz.y * sin.xyz.y / pi->mass ); vm_vec_crossprod( &temp_torque, &impact_vec, direction_vec ); vm_vec_add2( &torque, &temp_torque ); // find torque due to forces on the forward/backward face if ( normal.xyz.z < 0.0f ) vm_vec_copy_scale( &impact_vec, &orient->vec.fvec, max->xyz.z * pressure * area.xyz.z * normal.xyz.z * sin.xyz.z / pi->mass ); else vm_vec_copy_scale( &impact_vec, &orient->vec.fvec, min->xyz.z * pressure * area.xyz.z * -normal.xyz.z * sin.xyz.z / pi->mass ); vm_vec_crossprod( &temp_torque, &impact_vec, direction_vec ); vm_vec_add2( &torque, &temp_torque ); // compute delta rotvel, scale according to blast and radius float scale; if (radius < MIN_RADIUS) { scale = 1.0f; } else { scale = (MAX_RADIUS - radius)/(MAX_RADIUS-MIN_RADIUS); } // set shockwave shake amplitude, duration, flag pi->shockwave_shake_amp = (float)(MAX_SHAKE*(pressure/STD_PRESSURE)*scale); pi->shockwave_decay = timestamp( SW_BLAST_DURATION ); pi->flags |= PF_IN_SHOCKWAVE; // safety dance if (!(IS_VEC_NULL_SQ_SAFE(&torque))) { vec3d delta_rotvel; vm_vec_rotate( &local_torque, &torque, orient ); vm_vec_copy_normalize(&delta_rotvel, &local_torque); vm_vec_scale(&delta_rotvel, (float)(MAX_ROTVEL*(pressure/STD_PRESSURE)*scale)); // nprintf(("Physics", "rotvel scale %f/n", (MAX_ROTVEL*(pressure/STD_PRESSURE)*scale))); vm_vec_add2(&pi->rotvel, &delta_rotvel); } // set reduced translational damping, set flags float velocity_scale = (float)MAX_VEL*scale; pi->flags |= PF_REDUCED_DAMP; update_reduced_damp_timestamp( pi, velocity_scale*pi->mass ); vm_vec_scale_add2( &pi->vel, direction_vec, velocity_scale ); vm_vec_rotate(&pi->prev_ramp_vel, &pi->vel, orient); // set so velocity will ramp starting from current speed // check that kick from shockwave is not too large if (!(pi->flags & PF_USE_VEL) && (vm_vec_mag_squared(&pi->vel) > MAX_SHIP_SPEED*MAX_SHIP_SPEED)) { // Get DaveA nprintf(("Physics", "speed reset in physics_apply_shock [speed: %f]/n", vm_vec_mag(&pi->vel)));//.........这里部分代码省略.........
开发者ID:DahBlount,项目名称:Freespace-Open-Swifty,代码行数:101,
示例21: physics_read_flying_controls//.........这里部分代码省略......... ramp_time_const = pi->afterburner_reverse_accel; else ramp_time_const = pi->forward_decel_time_const; } else { ramp_time_const = pi->forward_decel_time_const; } // If reduced damp in effect, then adjust ramp_velocity and desired_velocity can not change as fast if ( pi->flags & PF_REDUCED_DAMP ) { ramp_time_const *= reduced_damp_ramp_time_expansion; } pi->prev_ramp_vel.xyz.z = velocity_ramp(pi->prev_ramp_vel.xyz.z, goal_vel.xyz.z, ramp_time_const, sim_time); //Deternine the current dynamic glide cap, and ramp to it //This is outside the normal "glide" block since we want the cap to adjust whether or not the ship is in glide mode float dynamic_glide_cap_goal = 0.0; if (pi->flags & PF_AFTERBURNER_ON) { dynamic_glide_cap_goal = ( goal_vel.xyz.z >= 0.0f ) ? pi->afterburner_max_vel.xyz.z : pi->afterburner_max_reverse_vel; } else { //Use the maximum value in X, Y, and Z (including overclocking) dynamic_glide_cap_goal = MAX(MAX(pi->max_vel.xyz.x,pi->max_vel.xyz.y), pi->max_vel.xyz.z); } pi->cur_glide_cap = velocity_ramp(pi->cur_glide_cap, dynamic_glide_cap_goal, ramp_time_const, sim_time); if ( (pi->flags & PF_GLIDING) || (pi->flags & PF_FORCE_GLIDE ) ) { pi->desired_vel = pi->vel; //SUSHI: A (hopefully better) approach to dealing with accelerations in glide mode //Get *actual* current velocities along each axis and use those instead of ramped velocities vec3d local_vel; vm_vec_rotate(&local_vel, &pi->vel, orient); //Having pi->glide_cap == 0 means we're using a dynamic glide cap float curGlideCap = 0.0f; if (pi->glide_cap == 0.0f) curGlideCap = pi->cur_glide_cap; else curGlideCap = pi->glide_cap; //If we're near the (positive) glide cap, decay velocity where we aren't thrusting //This is a hack, but makes the flight feel a lot smoother //Don't do this if we aren't applying any thrust, we have no glide cap, or the accel multiplier is 0 (no thrust while gliding) float cap_decay_threshold = 0.95f; float cap_decay_amount = 0.2f; if (curGlideCap >= 0.0f && vm_vec_mag(&pi->desired_vel) >= cap_decay_threshold * curGlideCap && vm_vec_mag(&goal_vel) > 0.0f && pi->glide_accel_mult != 0.0f) { if (goal_vel.xyz.x == 0.0f) vm_vec_scale_add2(&pi->desired_vel, &orient->vec.rvec, -cap_decay_amount * local_vel.xyz.x); if (goal_vel.xyz.y == 0.0f) vm_vec_scale_add2(&pi->desired_vel, &orient->vec.uvec, -cap_decay_amount * local_vel.xyz.y); if (goal_vel.xyz.z == 0.0f) vm_vec_scale_add2(&pi->desired_vel, &orient->vec.fvec, -cap_decay_amount * local_vel.xyz.z); } //The glide_ramp function uses (basically) the same math as the velocity ramp so that thruster power is consistent //Only ramp if the glide cap is positive float xVal = glide_ramp(local_vel.xyz.x, goal_vel.xyz.x, pi->slide_accel_time_const, pi->glide_accel_mult, sim_time); float yVal = glide_ramp(local_vel.xyz.y, goal_vel.xyz.y, pi->slide_accel_time_const, pi->glide_accel_mult, sim_time); float zVal = 0.0; if (pi->flags & PF_AFTERBURNER_ON) zVal = glide_ramp(local_vel.xyz.z, goal_vel.xyz.z, pi->afterburner_forward_accel_time_const, pi->glide_accel_mult, sim_time); else { if (goal_vel.xyz.z >= 0.0f) zVal = glide_ramp(local_vel.xyz.z, goal_vel.xyz.z, pi->forward_accel_time_const, pi->glide_accel_mult, sim_time); else zVal = glide_ramp(local_vel.xyz.z, goal_vel.xyz.z, pi->forward_decel_time_const, pi->glide_accel_mult, sim_time); } //Compensate for effect of dampening: normal flight cheats here, so /we make up for it this way so glide acts the same way xVal *= pi->side_slip_time_const / sim_time; yVal *= pi->side_slip_time_const / sim_time; if (pi->use_newtonian_damp) zVal *= pi->side_slip_time_const / sim_time; vm_vec_scale_add2(&pi->desired_vel, &orient->vec.fvec, zVal); vm_vec_scale_add2(&pi->desired_vel, &orient->vec.rvec, xVal); vm_vec_scale_add2(&pi->desired_vel, &orient->vec.uvec, yVal); // Only do the glide cap if we have one and are actively thrusting in some direction. if ( curGlideCap >= 0.0f && (ci->forward != 0.0f || ci->sideways != 0.0f || ci->vertical != 0.0f) ) { float currentmag = vm_vec_mag(&pi->desired_vel); if ( currentmag > curGlideCap ) { vm_vec_scale( &pi->desired_vel, curGlideCap / currentmag ); } } } else { // this translates local desired velocities to world velocities vm_vec_zero(&pi->desired_vel); vm_vec_scale_add2( &pi->desired_vel, &orient->vec.rvec, pi->prev_ramp_vel.xyz.x ); vm_vec_scale_add2( &pi->desired_vel, &orient->vec.uvec, pi->prev_ramp_vel.xyz.y ); vm_vec_scale_add2( &pi->desired_vel, &orient->vec.fvec, pi->prev_ramp_vel.xyz.z ); } } else // object does not accelerate (PF_ACCELERATES not set) pi->desired_vel = pi->vel;}
开发者ID:DahBlount,项目名称:Freespace-Open-Swifty,代码行数:101,
示例22: UpdateDatavoid asteroid_editor::update_init(){ int num_asteroids, idx, cur_choice; UpdateData(TRUE); if (last_field >= 0) { // store into temp asteroid field num_asteroids = a_field[last_field].num_initial_asteroids; a_field[last_field].num_initial_asteroids = m_enable_asteroids ? m_density : 0; if (a_field[last_field].num_initial_asteroids < 0) a_field[last_field].num_initial_asteroids = 0; if (a_field[last_field].num_initial_asteroids > MAX_ASTEROIDS) a_field[last_field].num_initial_asteroids = MAX_ASTEROIDS; if (num_asteroids != a_field[last_field].num_initial_asteroids) set_modified(); vector vel_vec = {1.0f, 0.0f, 0.0f}; vm_vec_scale(&vel_vec, (float) m_avg_speed); MODIFY(a_field[last_field].vel.x, vel_vec.x); MODIFY(a_field[last_field].vel.y, vel_vec.y); MODIFY(a_field[last_field].vel.z, vel_vec.z); MODIFY(a_field[last_field].min_bound.x, (float) atof(m_min_x)); MODIFY(a_field[last_field].min_bound.y, (float) atof(m_min_y)); MODIFY(a_field[last_field].min_bound.z, (float) atof(m_min_z)); MODIFY(a_field[last_field].max_bound.x, (float) atof(m_max_x)); MODIFY(a_field[last_field].max_bound.y, (float) atof(m_max_y)); MODIFY(a_field[last_field].max_bound.z, (float) atof(m_max_z)); // type of field MODIFY(a_field[last_field].field_type, m_field_type); MODIFY(a_field[last_field].debris_genre, m_debris_genre); if ( (m_field_type == FT_PASSIVE) && (m_debris_genre == DG_SHIP) ) { // we should have ship debris for (idx=0; idx<3; idx++) { // loop over combo boxes, store the item data of the cur selection, -1 in no cur selection int cur_sel = ((CComboBox*)GetDlgItem(Dlg_id[idx]))->GetCurSel(); if (cur_sel != CB_ERR) { cur_choice = ((CComboBox*)GetDlgItem(Dlg_id[idx]))->GetItemData(cur_sel); } else { cur_choice = -1; } MODIFY(a_field[cur_field].field_debris_type[idx], cur_choice); } } if ( m_debris_genre == DG_ASTEROID ) { if ( ((CButton *)GetDlgItem(IDC_SUBTYPE1))->GetCheck() == 1) { cur_choice = 1; } else { cur_choice = -1; } MODIFY(a_field[cur_field].field_debris_type[0], cur_choice); if ( ((CButton *)GetDlgItem(IDC_SUBTYPE2))->GetCheck() == 1) { cur_choice = 1; } else { cur_choice = -1; } MODIFY(a_field[cur_field].field_debris_type[1], cur_choice); if ( ((CButton *)GetDlgItem(IDC_SUBTYPE3))->GetCheck() == 1) { cur_choice = 1; } else { cur_choice = -1; } MODIFY(a_field[cur_field].field_debris_type[2], cur_choice); } MODIFY(a_field[last_field].has_inner_bound, m_enable_inner_bounds); MODIFY(a_field[last_field].inner_min_bound.x, (float) atof(m_box_min_x)); MODIFY(a_field[last_field].inner_min_bound.y, (float) atof(m_box_min_y)); MODIFY(a_field[last_field].inner_min_bound.z, (float) atof(m_box_min_z)); MODIFY(a_field[last_field].inner_max_bound.x, (float) atof(m_box_max_x)); MODIFY(a_field[last_field].inner_max_bound.y, (float) atof(m_box_max_y)); MODIFY(a_field[last_field].inner_max_bound.z, (float) atof(m_box_max_z)); } Assert(cur_field >= 0); // get from temp asteroid field into class m_enable_asteroids = a_field[cur_field].num_initial_asteroids ? TRUE : FALSE; m_enable_inner_bounds = a_field[cur_field].has_inner_bound ? TRUE : FALSE; m_density = a_field[cur_field].num_initial_asteroids; if (!m_enable_asteroids) m_density = 10; // set field type m_field_type = a_field[cur_field].field_type; m_debris_genre = a_field[cur_field].debris_genre;// m_debris_species = a_field[cur_field].debris_species; m_avg_speed = (int) vm_vec_mag(&a_field[cur_field].vel); m_min_x.Format("%.1f", a_field[cur_field].min_bound.x); m_min_y.Format("%.1f", a_field[cur_field].min_bound.y);//.........这里部分代码省略.........
开发者ID:lubomyr,项目名称:freespace2,代码行数:101,
注:本文中的vm_vec_scale函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ vm_vec_scale_add函数代码示例 C++ vm_vec_rotate函数代码示例 |