Vector headaches

Posted By: Anonymous

Vector headaches - 06/01/01 14:30

First off, can someone explain & give a short example of what vec_normalize does. I can't get my head around it?

Another vector question? I have a wheel.
I roll it along the ground by changing its TILT value.
I steer it by changing its PAN angle. BUT!,when I change its ROLL angle (it's going across a hill) things go wobbly!!

Do I have to re-calc the entire
PAN/TILT/ROLL angles using trigonometry if I want to do this?? (YUCK!)

3rd Question:
(Still with the wheels) If I want to trace under a wheel but my car is going up a hill,
is there any command that will calc a vector under the wheel (NOT wheel.z-amount) but actully looking in the direction 90 degrees downwards from the cars TILT & ROLL or do I have to use trigonometry again.

It looks to me that only the Ent_Move & Move functions move relative the the objects Euler angles, all the vector stuff seems to be base on world co-ords & as such down is -Z?

As you probably have guessed, trigonometry isn't my strong point & I'm worried about slowdowns from using it to excess.

(I will get there, no matter how long it takes!!!)


Posted By: WildCat

Re: Vector headaches - 06/01/01 23:32

Shovel,
When I first started with WDL I had tremendous difficulty wrapping my head around all this vector stuff. I believe I can help you understand some of these problems. I've encountered some of them in my own work. If it's any consolation, It does get easier as you do it more...

VEC_NORMALIZE "Chops the vector to the length given in the second variable while keeping it's direction".

I can't define it any better than that quote from the manual, but I can give an example that may be helpful...

In the SpaceFlight workshop, I have a variable for a spaceship called "MAX_SHIP_SPEED". The idea is that your ship can't go any faster than this speed. Once I apply all the accelerations and things to the direction that the ship is going, sometimes the ship is going faster than my speed limit, so I "Chop" the size of my speed vector down to the size it is supposed to be by using Vec_normalize, and it still retains the direction that it initially had. I use it as a speed govener.


Your next issue, with wobbly wheels might be if you are adjusting the pan, roll and tilt of the wheels directly...

The tilt value of an entity can never be greater than 90 or less than -90. If you give an entity a tilt value of 100 for example, the engine will account for that by flipping the PAN angles 180 degrees and then adjusting the tilt to (180-tilt).

I know that sounds crazy, but it's true. From the TILT point of view, everyhting is ok, from the PAN point of view everything gets messed up when you have a tilt larger than 90.

If you need to make those kinds of changes, you should use the ROTATE command instead. (NOT the VEC_ROTATE command, that does different stuff!) ROTATE somehow knows how to fix the problem using a different kind of math called "Quaternions".

Can't really help you with your third question, but I help this other stuff gets you going in the right direction. Good luck!

-WildCat

[This message has been edited by WildCat (edited 01 June 2001).]

Posted By: Anonymous

Re: Vector headaches - 06/02/01 01:35

Shovel,

Regarding your 3rd question:
Are you trying to anticipate the tire's collision with the ground/terrain ahead.
Tire bouncing effect (up/down ?).

-Neut.

Posted By: Anonymous

Re: Vector headaches - 06/03/01 12:37

Thanks WildCat, and I sort of guessed that I'd need to use "rotate" but is seems to give the same problem.

// ---- Here's some pseudo code ----
//
//WheelRF is the right front wheel synonym.
//Wheel_Roll_Angle = angle the wheel rolls to travel the correct distance.
//Steering_Angle is what it says.

WheelRF.Skill11 = Car.PAN-Steering_Angle;
WheelRF.Skill12 -= Wheel_Roll_Angle;
WheelRF.Skill13 = Car.Roll;

// reset the wheel back to normal
WheelRF.Pan = 0;
WheelRF.Tilt= 0;
WheelRF.Roll= 0;

// setup the temp rotation vector
temp.pan = WheelRF.Skill11;
temp.tilt = WheelRF.Skill12;
temp.roll = WheelRF.Skill13;

// rotate to desired pan/tilt/roll
rotate(WheelRF,temp,nullvector);

//--- end of code ---
Same as before, if you try to change the roll angle the wheel goes wobbly.

Neutron Blue: Yes, I am trying to do collision & doing the tyre suspension stuff.
I've got it working at present but the wheels
collision is caclulated straight down:

Pseudo Code:
//------------------------------
// (WR = wheel radius)
vec_set(temp1,which_wheel.x)
vec_set(temp2,which_wheel.x)
temp2.z -= 100; // scan 100 under current wheel
New_Wheel_Height = trace(temp1,temp2) - WR ;
which_wheel.z = which_wheel.z - New_Wheel_Height;
//------------------------------
As you can see it doesn't take into account if the car is tilited or rolled, also I wish to allow the car to completely roll over.

Man this vector stuff is fun but I haven't done anything like this since school over 20 years ago.....

Posted By: Anonymous

Re: Vector headaches - 06/06/01 07:14

I've basically given up trying to get the wheel to roll, I couldn't get past the flipping problem. All else works ok & I think I'll actually animate the wheel models through 360 degree animation then update the wheel anim frames instead of rotating the wheel, it won't look as good but it will also help by leaving the wheel axies alligned with the car & help with the suspension code.
Does anyone know if you can use say 30 frames animation to rotate a wheel (12 degrees per frame) then let the engine interpolate intermediate steps of say 1-2 degrees???. The problem will only be visible when the car is going very slow...

Posted By: Anonymous

Re: Vector headaches - 06/08/01 07:10

If anyone is interested, I've got it all working using the animation method.
I'm impressed with the interpolation:
I've generated a rotation animation of the wheel moved every 15 degrees. I then feed it values between %0-%100 in very fine amounts and its looks every bit as good as actually rotating the wheel model but without all the pan/tilt/roll hassles.

Posted By: James Snydstrup

Re: Vector headaches - 06/08/01 12:37

shovel:

Here is some code I dug up out of one of my WDL scripts...

code:

SONAR MY, 4000;
walk_speed.Z = -.5 * RESULT;

floor_normal.X = NORMAL.X;
floor_normal.Y = NORMAL.Y;
floor_normal.Z = NORMAL.Z;

///adjust for sloped surfaces
MY_ANGLE.TILT = 0;
MY_ANGLE.ROLL = 0;

MY_ANGLE.PAN = -MY.PAN;
VECROTATE floor_normal,MY_ANGLE;

MY_ANGLE.TILT = -ASIN(floor_normal.X);
MY_ANGLE.ROLL = -ASIN(floor_normal.Y);

MY.TILT += 0.2 * ANG(MY_ANGLE.TILT-MY.TILT);
MY.ROLL += 0.2 * ANG(MY_ANGLE.ROLL-MY.ROLL);


It will adjust the model's tilt and roll so that it matches the surface it is on...does this help at all?

Posted By: Anonymous

Re: Vector headaches - 06/09/01 09:03

Thanks James, but I individually adjust each wheels height, suspension travel limits & such, then calc the cars roll/tilt from this.
I don't actually use the surfaces normal for the car but I will be checking for the surfaces texture which I'll use to determine wheel grip values.
It's taking a long time but I knew it wouldn't be easy...
© 2023 lite-C Forums