Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 945 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How to set tilt angle to the floor? #467076
07/14/17 16:14
07/14/17 16:14
Joined: Oct 2008
Posts: 679
Germany
Ayumi Offline OP
User
Ayumi  Offline OP
User

Joined: Oct 2008
Posts: 679
Germany
Hey,

I have been trying for days to adjust an tilt angle of a model to an angle of the ground.

That code is working, but the tilt is wrong. Any ideas?

Code:
vec_to_angle(my.tilt, vector(hit.nx, hit.ny, hit.nz));




EDIT: Fixed with ang_for_axis

Last edited by Ayumi; 07/14/17 20:14.
Re: How to set tilt angle to the floor? [Re: Ayumi] #467077
07/14/17 20:54
07/14/17 20:54
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Your function argument "my.tilt" is not a vector. A(n acknex) vector consists of three consecutive var variables in the 1dimensional memory. When you write "my.tilt", the lite-C compiler sees that vec_to_angle required vector pointers, not a single var (which my.tilt normally is), so it adds the address operator for you automatically (pv = &(my.tilt) or &(my->tilt)).
The vec_to_angle function now calculates an orientation based on the direction vector/ its second argument and copies that into the vector pointer/ the first argument, meaning it overwrites three vars in a row: pv[0], pv[1], pv[2].
However, the address you wrote in the first argument was &(my.tilt), so my.tilt is overridden by pv[0], which normally is the pan value. Your desired tilt value is written into my.roll, and the bad part - should vec_to_angle change the roll value which I'm not sure/ I don't think it does, but other vec_... functions will - some random memory at address location pv[2] gets overriden.
This is really bad, and can and will lead to random behavior in your code/ game, random functions failing, game freezes/ crashes and so on. That's stuff that kills a project.

Always keep that in mind when functions require vectors/ vector pointers.
Either write
Code:
vec_to_angle(my.pan, hit.nx);


or
Code:
VECTOR temp; // or use an ANGLE, I always just use VECTORs
vec_to_angle(temp, hit.nx);
my.tilt = temp.y;


depending on what you want to achieve.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: How to set tilt angle to the floor? [Re: Superku] #467098
07/15/17 09:32
07/15/17 09:32
Joined: Oct 2008
Posts: 679
Germany
Ayumi Offline OP
User
Ayumi  Offline OP
User

Joined: Oct 2008
Posts: 679
Germany
Ty for information, seen to late my wrong angle.

Re: How to set tilt angle to the floor? [Re: Ayumi] #467156
07/18/17 16:53
07/18/17 16:53
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline
Serious User
jumpman  Offline
Serious User

Joined: Apr 2002
Posts: 1,246
ny
awesome explanation superku! I unknowingly did this once recently, and random crashes in an unrelated function occurred.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1