Angles: entities "up" normal depending on its roll

Post your scripting questions / solutions here

Moderator: Moderators

Elgan
Lieutenant General
Posts: 890
Joined: Tue Apr 13, 2004 10:43 pm
Location: uk
Contact:

Angles: entities "up" normal depending on its roll

Post by Elgan »

Code: Select all

________________

Key
----

( X Y Z )   = Stuff

   ^          = Arrows

---|---       = Aeroplane

________________
ok. SO if my plane has a roll of 0,nothing. flat:

Code: Select all

---|---
So i would want the angle perpendicular to the wings, i think. Im going to call this angle "U" for up.

Code: Select all

              ^
so u = ---|---
Thats easy enough its local.plane.angles[0] or pitch.


maybe i sud call it pitch? anyway

WHat if the plane has a roll , maybe 90 deg left/ i cant draw anything else.

Code: Select all

       |
u  < |
       |
i thought maybe trying the cross product but i get weird results, maybe i crossing the wrong things? left/fwd?

upvector seems wrong. tried some other things but they move the roll also. not really sure what to do.

Any sugestions?

WOuld scripting movement using origin++ and changling angles be laggy:S? i think i cud script angles and leave origin to physics_on however the drop would be all wrong.
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Honestly I haven't got the slightest clue what you're trying to do or what the problem is :? (apart from angles being mathematically inconvenient).
WOuld scripting movement using origin++ and changling angles be laggy:S?
Not more than any other way of movement.
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

xyz

Post by tltrude »

Well, I can't really tell what you are trying to do, but here is a lesson in flight angles.

Normally XYZ is a 3D point in space, but in this case it is pitch, yaw, and roll. Pitch is the nose moving up and down. Yaw is the nose moving left and right. Roll is spinning the wings around the nose to tail axis.

When you use "angle" only one number is needed because it sets only the yaw. But, when you use "angles" you need 3 numbers to set the pitch yaw and roll.

local.plane.angles = ( 0 0 90 )

The three angles can be read with [0], [1], and [2].

Hope that helps!
Tom Trude,

Image
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

I think it's quite clear Elgan is perfectly aware of all this stuff, Tom.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

:roll:

At least now we can be sure :) . Besides it can be very useful info for some innocent passer-by :wink:
Last edited by jv_map on Wed Sep 21, 2005 4:20 pm, edited 1 time in total.
Image
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post by lizardkid »

Flamer One to the rescue...

i think Elg wants to make the plane do a barrel roll, and also to ask if changing origin manually is buggier than a command, after some re-reads.

if so:

Code: Select all

roller:

self.angles = ( self.angles + (0 1 0))

wait .01
end
tweak for full rolls.
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
Elgan
Lieutenant General
Posts: 890
Joined: Tue Apr 13, 2004 10:43 pm
Location: uk
Contact:

Post by Elgan »

lizardkid wrote:Flamer One to the rescue...

i think Elg wants to make the plane do a barrel roll, and also to ask if changing origin manually is buggier than a command, after some re-reads.

if so:

Code: Select all

roller:

self.angles = ( self.angles + (0 1 0))

wait .01
end
tweak for full rolls.
hehe. ok

well the barrel roll i can get, but pitch [0]. WIll be pitch up and down unless the plane is banked, then pitch is not straight up but at the angle of the roll.

and by saying that i think i have worked it out. I will try it tomorrow. i didnt do anything else since, i been working on something else and something else, i get distracted. Expecialy when stuck.

My other project im stuck on too now:\..hehe any1 know why i get read memory errors with my custom mohaa dll?

Maybe ill have some success with the planes .
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post by lizardkid »

Elg! i slap you! speak english! :P

are you wanting to know what will happen with a pitch of 0? pitch 0 is probably straight up.

regardless of the other vectors, pitch will move the nose of the plane, unless it returns a buggy number (like, -42572811789892135622773837) it should always control the nose as expected.
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
Elgan
Lieutenant General
Posts: 890
Joined: Tue Apr 13, 2004 10:43 pm
Location: uk
Contact:

Post by Elgan »

lizardkid wrote:Elg! i slap you! speak english! :P

are you wanting to know what will happen with a pitch of 0? pitch 0 is probably straight up.

regardless of the other vectors, pitch will move the nose of the plane, unless it returns a buggy number (like, -42572811789892135622773837) it should always control the nose as expected.
if u can imagine pitch as up and down thats good. That is pitch. But if your looking up and u lean sideways, Your not looking straight up anymore are you. So up would by the angle your leaning.

So to work it out, i just have to get the deg of the roll and aplly it to the errm "up".

I mean like a plane doe not fly without loosing altitude, when it turns depending on how it is being turned by the pilot and the forces turning it. it will loose altitute unless the pilot compensates by slightly picthing up, rolled sideways this will keep normal height because they are not going diretly up. it is angled, the plane then turns. If u dont add pitch u will do a barrel roll and most likely loose a little height.

however i probably wont worry about the forces and drag etc thta will cause height loss. I just want the angles to be correct at least. hehe then maybe later i can add some gravity if people on the server can grasp the controls.

even with the better then before controls with planes that turn 90 deg, ppl ask how to fly :\
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post by lizardkid »

ahh, i get it now.
So to work it out, i just have to get the deg of the roll and aplly it to the errm "up".
i get it, i understand what you're doing, you got it, me noob :lol:
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

I don't get it the upvector is always at 90 angle to the plane regardless of pitch or roll . Do you mean up as in straight up from the ground ? To do what I think you are doing would take a bit of effort , I guess you are setting a height based on angles and veleocity ?
Image
Elgan
Lieutenant General
Posts: 890
Joined: Tue Apr 13, 2004 10:43 pm
Location: uk
Contact:

Post by Elgan »

bdbodger wrote:I don't get it the upvector is always at 90 angle to the plane regardless of pitch or roll . Do you mean up as in straight up from the ground ? To do what I think you are doing would take a bit of effort , I guess you are setting a height based on angles and veleocity ?

Then i need to apply the up to the pitch without effecting roll. hmm, actualy.

i have a couple of ideas on how. I will let you know the results:)
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

In case all above fails and FYI in general, it's probably good to know how exactly angles are defined in mohaa.

Say you have some set of angles A = (p y r); with p, y, r pitch, yaw and roll angles.

Also define I to be the set of unrotated coordinate vectors "fwd", "lf" and "up". Because I is unrotated these are aligned to the world axes x,y,z.

I = {fwd,lf,up} = { (1 0 0) , (0 1 0) , (0 0 1) }

Now what mohaa does with the value of angles you give it, is rotate the model's coordinate system. As a result, the vertex locations move as well (relative to the world's coordinate system) and the object looks rotated.

The way this rotation is accomplished is somewhat arbitrary and hence inconvenient, but here is how it is done anyway.

(note: all subsequent rotations are right-handed, which means that for instance in a 2D coordinate system, the x-axis would rotate towards the positive y-axis, and the y-axis towards the negative x-axis. For a left-handed rotation this is the other way around.)

First, the coordinate system I is rotated around the world z axes by the amount y (the yaw). This results in a new sytem, say C, with the up vector still aligned with the world z-axis but with new forward and left vectors.

Next, the pitch rotation is applied by rotating the new coordinate system C around its left vector by p (the pitch). Again we get a new coordinate system, D, which has the same left vector as C but new forward and up vectors.

We've almost established the final coordinate system now, we only have to add the roll next. This is done by rotating the entire system D around its forward vector by r (the roll), leading to system E with the same forwardvector as D but new left and up vectors.

E is the final rotated coordinate system, which depends only on the values given for p, y and r.

Now I am aware this 'explanation' may produce more clouds than it dissolves, and I would be quite amazed if you'd understand it all at once. However I'm hoping that at least some of it makes sense, and after some trial and error more will... maybe eventually you'll get it all and notice it doesn't in any way help you solve your problem. But hey by then you've learned a lot anyway :wink:

Assuming that you have learned a lot and not wanting to take all fun / challenge away, I'll present you with a simple method to transform any set of 2 vectors (forward and left, up is defined as fwd x lf) into angles that can be used to rotate your plane entity. Finding out what should be the new forward / left vectors depending on the player's input and plane roll angle I'll leave up to you for now, but you know where to go if you need help in the future ;)

Code: Select all

level.PI = 3.1415926

// transforms vectors to angles (pitch,yaw,roll)
// unlike vector_toangles this also includes roll
vectors_toangles local.vec_fwd local.vec_lf:
	local.base_angles = vector_toangles local.vec_fwd
	
	local.base_fwd = local.vec_fwd
	local.base_lf = -1.0 * (angles_toleft local.base_angles)
	local.base_up = vector_cross local.base_fwd local.base_lf
	
	local.cos = local.vec_lf * local.base_lf
	
	if(abs local.cos < 0.8)
	{
		local.roll_angle = waitthread arccos local.cos
		
		if(local.vec_lf * local.base_up < 0.0)
		{
			local.roll_angle = -local.roll_angle
		}
	}
	else
	{
		// arccos inaccurate here
		// so just use arcsin instead
		// (far more sensitive in this region)
		local.sin = local.vec_lf * local.base_up
		
		local.roll_angle = waitthread arcsin local.sin
		
		if(local.cos < 0.0)
		{
			local.roll_angle = level.PI - local.roll_angle
		}
	}
	
	// convert to degrees
	local.roll_angle = local.roll_angle / level.PI * 180.0
	
	local.angles = local.base_angles
	local.angles[2] = local.roll_angle
end local.angles

// inverse sin
// somewhat inaccurate near +-0.5PI
arcsin local.x:
	if(local.x < -0.857 || local.x > 0.857)
	{
		// some 9th order approximation
		local.x3 = local.x * local.x * local.x
		local.x9 = local.x3 * local.x3 * local.x3
		
		local.out = local.x + (0.5 * level.PI - 1.0) * local.x9
	}
	else
	{
		local.x2 = local.x * local.x
		local.x3 = local.x2 * local.x
		local.x5 = local.x3 * local.x2
	
		// Taylor series expansion
		local.out = local.x + 0.1667 * local.x3 + 0.075 * local.x5
	}
end local.out

// inverse cos
arccos local.rad:
	local.result = 0.5 * level.PI - (waitthread arcsin local.rad)
end local.result
Image
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post by lizardkid »

you lost me after
In case all above fails and FYI in general, it's probably good to know how exactly angles are defined in mohaa.
:lol:

actually, that's a really good explanation of it, it's never really occured to me it does the angles in any order, or how the rotation works.

Definitely helpful info ;)
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Why, yes, that's a very nice explanation. :)

There's also one in the Spearhead SDK (docs/Coordinate_system_documentation.html).
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Post Reply