Add vm_vec_copy_scale that returns result

This commit is contained in:
Kp 2014-11-02 03:43:47 +00:00
parent 6746879427
commit b32f5e5df3
9 changed files with 25 additions and 31 deletions

View file

@ -28,7 +28,7 @@ struct rod_4point
//compute the corners of a rod. fills in vertbuf.
static int calc_rod_corners(rod_4point &rod_point_group, g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width)
{
vms_vector top,tempv,rod_norm;
vms_vector top,rod_norm;
//compute vector from one point to other, do cross product with vector
//from eye to get perpendiclar
@ -61,7 +61,7 @@ static int calc_rod_corners(rod_4point &rod_point_group, g3s_point *bot_point,fi
//top points
vm_vec_copy_scale(tempv,rod_norm,top_width);
auto tempv = vm_vec_copy_scale(rod_norm,top_width);
tempv.z = 0;
rod_point_group.point_list[0] = &rod_point_group.points[0];

View file

@ -157,7 +157,11 @@ void vm_vec_divide(vms_vector &dest, const vms_vector &src, fix d);
//scales and copies a vector. returns ptr to dest
vms_vector &vm_vec_copy_scale (vms_vector &dest, const vms_vector &src, fix s);
static inline vms_vector vm_vec_copy_scale(vms_vector src, fix s) __attribute_warn_unused_result;
static inline vms_vector vm_vec_copy_scale(vms_vector src, fix s)
{
return vm_vec_scale(src, s), src;
}
//scales a vector, adds it to another, and stores in a 3rd vector
//dest = src1 + k * src2

View file

@ -535,7 +535,6 @@ int SetPlayerFromCursegAndRotate()
//far enough away to see all of curside
int SetPlayerFromCursegMinusOne()
{
vms_vector view_vec2;
vms_vector corner_v[4];
g3s_point corner_p[4];
int i;
@ -544,7 +543,7 @@ int SetPlayerFromCursegMinusOne()
const auto view_vec = vm_vec_negated(Cursegp->sides[Curside].normals[0]);
const auto side_center = compute_center_point_on_side(Cursegp,Curside);
vm_vec_copy_scale(view_vec2,view_vec,view_dist);
const auto view_vec2 = vm_vec_copy_scale(view_vec,view_dist);
vm_vec_sub(ConsoleObject->pos,side_center,view_vec2);
const auto upvec = vm_vec_sub(Vertices[Cursegp->verts[Side_to_verts[Curside][edgenum%4]]], Vertices[Cursegp->verts[Side_to_verts[Curside][(edgenum+3)%4]]]);
@ -564,8 +563,8 @@ int SetPlayerFromCursegMinusOne()
}
view_dist = fixmul(view_dist,fixdiv(fixdiv(max,SIDE_VIEW_FRAC),corner_p[0].p3_z));
vm_vec_copy_scale(view_vec2,view_vec,view_dist);
vm_vec_sub(ConsoleObject->pos,side_center,view_vec2);
const auto view_vec3 = vm_vec_copy_scale(view_vec,view_dist);
vm_vec_sub(ConsoleObject->pos,side_center,view_vec3);
//obj_relink(ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
//update_object_seg(ConsoleObject); //might have backed right out of curseg

View file

@ -293,8 +293,7 @@ static void bump_two_objects(const vobjptridx_t obj0,const vobjptridx_t obj1,int
{
const vobjptridx_t &t = *pt;
Assert(t->movement_type == MT_PHYSICS);
vms_vector force;
vm_vec_copy_scale(force,t->mtype.phys_info.velocity,-t->mtype.phys_info.mass);
const auto force = vm_vec_copy_scale(t->mtype.phys_info.velocity,-t->mtype.phys_info.mass);
phys_apply_force(t,force);
return;
}
@ -308,8 +307,7 @@ static void bump_two_objects(const vobjptridx_t obj0,const vobjptridx_t obj1,int
void bump_one_object(const vobjptr_t obj0, const vms_vector &hit_dir, fix damage)
{
auto hit_vec = hit_dir;
vm_vec_scale(hit_vec, damage);
const auto hit_vec = vm_vec_copy_scale(hit_dir, damage);
phys_apply_force(obj0,hit_vec);
}

View file

@ -622,13 +622,12 @@ void do_endlevel_frame()
//do little explosions on walls
if (Endlevel_sequence >= EL_FLYTHROUGH && Endlevel_sequence < EL_OUTSIDE)
if ((explosion_wait2-=FrameTime) < 0) {
vms_vector tpnt;
fvi_query fq;
fvi_info hit_data;
//create little explosion on wall
vm_vec_copy_scale(tpnt,ConsoleObject->orient.rvec,(d_rand()-D_RAND_MAX/2)*100);
auto tpnt = vm_vec_copy_scale(ConsoleObject->orient.rvec,(d_rand()-D_RAND_MAX/2)*100);
vm_vec_scale_add2(tpnt,ConsoleObject->orient.uvec,(d_rand()-D_RAND_MAX/2)*100);
vm_vec_add2(tpnt,ConsoleObject->pos);

View file

@ -282,10 +282,9 @@ static g3s_lrgb compute_light_emission(int objnum)
else
#endif
{
vms_vector sthrust = obj->mtype.phys_info.thrust;
fix k = fixmuldiv(obj->mtype.phys_info.mass,obj->mtype.phys_info.drag,(f1_0-obj->mtype.phys_info.drag));
// smooth thrust value like set_thrust_from_velocity()
vm_vec_copy_scale(sthrust,obj->mtype.phys_info.velocity,k);
auto sthrust = vm_vec_copy_scale(obj->mtype.phys_info.velocity,k);
light_intensity = max(vm_vec_mag_quick(sthrust)/4, F1_0*2) + F1_0/2;
}
break;

View file

@ -216,7 +216,6 @@ void draw_object_tmap_rod(const vobjptridx_t obj,bitmap_index bitmapi,int lighte
grs_bitmap * bitmap = &GameBitmaps[bitmapi.index];
g3s_lrgb light;
vms_vector delta;
g3s_point top_p,bot_p;
PIGGY_PAGE_IN(bitmapi);
@ -225,7 +224,7 @@ void draw_object_tmap_rod(const vobjptridx_t obj,bitmap_index bitmapi,int lighte
bitmap->bm_handle = bitmapi.index;
#endif
vm_vec_copy_scale(delta,obj->orient.uvec,obj->size);
const auto delta = vm_vec_copy_scale(obj->orient.uvec,obj->size);
const auto top_v = vm_vec_add(obj->pos,delta);
const auto bot_v = vm_vec_sub(obj->pos,delta);

View file

@ -201,7 +201,6 @@ static void do_physics_sim_rot(const vobjptr_t obj)
if (obj->mtype.phys_info.drag) {
int count;
vms_vector accel;
fix drag,r,k;
count = FrameTime / FT;
@ -212,7 +211,7 @@ static void do_physics_sim_rot(const vobjptr_t obj)
if (obj->mtype.phys_info.flags & PF_USES_THRUST) {
vm_vec_copy_scale(accel,obj->mtype.phys_info.rotthrust,fixdiv(f1_0,obj->mtype.phys_info.mass));
const auto accel = vm_vec_copy_scale(obj->mtype.phys_info.rotthrust,fixdiv(f1_0,obj->mtype.phys_info.mass));
while (count--) {
@ -300,7 +299,6 @@ void do_physics_sim(const vobjptridx_t obj)
int n_ignore_objs;
int try_again;
int fate=0;
vms_vector frame_vec; //movement in this frame
vms_vector ipos; //position after this frame
int count=0;
segnum_t WallHitSeg;
@ -362,7 +360,6 @@ void do_physics_sim(const vobjptridx_t obj)
if ((drag = obj->mtype.phys_info.drag) != 0) {
int count;
vms_vector accel;
fix r,k,have_accel;
count = FrameTime / FT;
@ -371,7 +368,7 @@ void do_physics_sim(const vobjptridx_t obj)
if (obj->mtype.phys_info.flags & PF_USES_THRUST) {
vm_vec_copy_scale(accel,obj->mtype.phys_info.thrust,fixdiv(f1_0,obj->mtype.phys_info.mass));
const auto accel = vm_vec_copy_scale(obj->mtype.phys_info.thrust,fixdiv(f1_0,obj->mtype.phys_info.mass));
have_accel = (accel.x || accel.y || accel.z);
while (count--) {
@ -406,7 +403,7 @@ void do_physics_sim(const vobjptridx_t obj)
try_again = 0;
//Move the object
vm_vec_copy_scale(frame_vec, obj->mtype.phys_info.velocity, sim_time);
const auto frame_vec = vm_vec_copy_scale(obj->mtype.phys_info.velocity, sim_time);
if ( (frame_vec.x==0) && (frame_vec.y==0) && (frame_vec.z==0) )
break;

View file

@ -150,11 +150,7 @@ vms_vector &terrain_y_cache::operator()(uint_fast32_t h)
{
auto &dyp = y_cache[h];
if (!yc_flags[h]) {
vms_vector tv;
//@@g3_rotate_delta_y(dyp,h*HEIGHT_SCALE);
vm_vec_copy_scale(tv,surface_orient.uvec,h*HEIGHT_SCALE);
const auto tv = vm_vec_copy_scale(surface_orient.uvec,h*HEIGHT_SCALE);
g3_rotate_delta_vec(dyp,tv);
yc_flags[h] = 1;
@ -172,7 +168,6 @@ void render_terrain(const vms_vector &org_point,int org_2dx,int org_2dy)
int i,j;
int low_i,high_i,low_j,high_j;
int viewer_i,viewer_j;
vms_vector tv;
org_i = org_2dy;
org_j = org_2dx;
@ -189,10 +184,14 @@ void render_terrain(const vms_vector &org_point,int org_2dx,int org_2dy)
//Lighting_on = 0;
Interpolation_method = im;
vm_vec_copy_scale(tv,surface_orient.rvec,GRID_SCALE);
{
const auto tv = vm_vec_copy_scale(surface_orient.rvec,GRID_SCALE);
g3_rotate_delta_vec(delta_i,tv);
vm_vec_copy_scale(tv,surface_orient.fvec,GRID_SCALE);
}
{
const auto tv = vm_vec_copy_scale(surface_orient.fvec,GRID_SCALE);
g3_rotate_delta_vec(delta_j,tv);
}
vm_vec_scale_add(start_point,org_point,surface_orient.rvec,-(org_i - low_i)*GRID_SCALE);
vm_vec_scale_add2(start_point,surface_orient.fvec,-(org_j - low_j)*GRID_SCALE);