Gamestudio Links
Zorro Links
Newest Posts
What are you working on?
by NeoDumont
Today at 04:24
New Aum and few things
by George
Yesterday at 20:47
Transfer free license to different device?
by AndrewAMD
Yesterday at 20:14
read MT4 tradehistory html to create tradereport in Zorro
by GHMC
Yesterday at 13:45
Oanda - Darwinex data syncronisation
by MatPed
06/16/18 17:13
Genetic Algorithm
by AndrewAMD
06/16/18 06:09
Sponsorship
by Firoball
06/15/18 21:55
AUM Magazine
Latest Screens
Evonet Beta v1.0 : Online Project Development Template
Lake scene
Forgotten Tales - Demo version
RPG PARTY
Who's Online
5 registered (Superku, alibaba, AndrewAMD, 20BN, 1 invisible), 479 Guests and 3 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
Raisinbran, Grodt, drack, Paul_der_Zweite, madeinquant
17981 Registered Users
Topic Options
Rate This Topic
#467076 - 07/14/17 18:14 How to set tilt angle to the floor?
Ayumi Offline
User

Registered: 10/12/08
Posts: 634
Loc: 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


Edited by Ayumi (07/14/17 22:14)

Top
#467077 - 07/14/17 22:54 Re: How to set tilt angle to the floor? [Re: Ayumi]
Superku Online
Senior Expert

Registered: 09/13/03
Posts: 6707
Loc: 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

Superku The Game

Severely outdated footage: http://store.steampowered.com/app/407570

Top
#467098 - 07/15/17 11:32 Re: How to set tilt angle to the floor? [Re: Superku]
Ayumi Offline
User

Registered: 10/12/08
Posts: 634
Loc: Germany
Ty for information, seen to late my wrong angle.

Top
#467156 - 07/18/17 18:53 Re: How to set tilt angle to the floor? [Re: Ayumi]
jumpman Offline
Serious User

Registered: 04/17/02
Posts: 1170
Loc: ny
awesome explanation superku! I unknowingly did this once recently, and random crashes in an unrelated function occurred.
_________________________
A8 Pro 8.47

Top


Moderator:  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