Hey folks.
Currently I'm sitting on a big problem.
Here is some code:
Some info:
type fix is int.
vms_vector is a packed struct that has
The problem here is:
rotvel_ptr->x,y
The values of them are correct and are in my case in ranges from -5000 to +5000.
The trouble begins when they get passed to the subfunction
"rotvel_ptr->x" is okay there but when "rotvel_ptr->y" is used WITHIN the subfunction (physics_set_rotvel_and_saturate) the value looks uninitated. I get very huge values (negative and positive).
For example if I print out "dest" while rotvel_ptr->y is used it gives insane values. rotvel_ptr->x however is okay. I could solve it by passing rotvel to an integer variable and use them to pass to physics_set_rotvel_and_saturate but my source is very big and I have similar problems on other places.
So my question is how to solve this in an easy way.
Hopefully I submitted enough information and someone can help me out.
I already tried -mstructure-size-boundary but it didn't help out.
Currently I'm sitting on a big problem.
Here is some code:
Code:
void physics_set_rotvel_and_saturate(fix *dest, fix delta)
{
if ((delta ^ *dest) < 0) {
if (abs(delta) < F1_0/8) {
// mprintf((0, "D"));
*dest = delta/4;
} else
// mprintf((0, "d"));
*dest = delta;
} else {
// mprintf((0, "!"));
*dest = delta;
}
}
void physics_turn_towards_vector(vms_vector *goal_vector, object *obj, fix rate)
{
vms_angvec dest_angles, cur_angles;
fix delta_p, delta_h;
vms_vector *rotvel_ptr = &obj->mtype.phys_info.rotvel;
// Make this object turn towards the goal_vector. Changes orientation, doesn't change direction of movement.
// If no one moves, will be facing goal_vector in 1 second.
// Detect null vector.
if ((goal_vector->x == 0) && (goal_vector->y == 0) && (goal_vector->z == 0))
return;
// Make morph objects turn more slowly.
if (obj->control_type == CT_MORPH)
rate *= 2;
vm_extract_angles_vector(&dest_angles, goal_vector);
vm_extract_angles_vector(&cur_angles, &obj->orient.fvec);
delta_p = (dest_angles.p - cur_angles.p);
delta_h = (dest_angles.h - cur_angles.h);
if (delta_p > F1_0/2) delta_p = dest_angles.p - cur_angles.p - F1_0;
if (delta_p < -F1_0/2) delta_p = dest_angles.p - cur_angles.p + F1_0;
if (delta_h > F1_0/2) delta_h = dest_angles.h - cur_angles.h - F1_0;
if (delta_h < -F1_0/2) delta_h = dest_angles.h - cur_angles.h + F1_0;
delta_p = fixdiv(delta_p, rate);
delta_h = fixdiv(delta_h, rate);
if (abs(delta_p) < F1_0/16) delta_p *= 4;
if (abs(delta_h) < F1_0/16) delta_h *= 4;
physics_set_rotvel_and_saturate(&rotvel_ptr->x, delta_p);
physics_set_rotvel_and_saturate(&rotvel_ptr->y, delta_h);
rotvel_ptr->z = 0;
}
Some info:
type fix is int.
vms_vector is a packed struct that has
Code:
int x,y,z;
The problem here is:
rotvel_ptr->x,y
The values of them are correct and are in my case in ranges from -5000 to +5000.
The trouble begins when they get passed to the subfunction
Code:
physics_set_rotvel_and_saturate
For example if I print out "dest" while rotvel_ptr->y is used it gives insane values. rotvel_ptr->x however is okay. I could solve it by passing rotvel to an integer variable and use them to pass to physics_set_rotvel_and_saturate but my source is very big and I have similar problems on other places.
So my question is how to solve this in an easy way.
Hopefully I submitted enough information and someone can help me out.
I already tried -mstructure-size-boundary but it didn't help out.