Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Simplest Way to align a 3d object on a surface with normals

Author
Message
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 1st Apr 2013 16:36 Edited at: 1st Apr 2013 16:37
I would like to orientate a 3d object along a 3d surface (with the normals known by "floor collision" : GetObjectRayCastNormalX,GetObjectRayCastNormalY,GetObjectRayCastNormalZ)

Like this :



Any idea with actual AppGameKit commands ? i know that is possible only with normals but can't achieve to get it working lol
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Apr 2013 18:45
Those are the right commands to use. How are you trying to do it? I would use raycasting personally.


this.mess = abs(sin(times#))
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 1st Apr 2013 18:56
Raycasting to get the normals... yes.

But can't achieve to transform normals to angles to set object rotation ...

Actually i'm using two raycasting tests on two different floor points along Z axis (movelocal) and i'm using the "SetObjectLookAt" command to the target point and i can get the correct angles.

But it's certainly possible with the surface X,Y,Z normals only (with Quaternions maybe ? "SetObjectRotationQuat").
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Apr 2013 19:07
I would just use setObjectLookAt as you suggested. I wouldn't personally fancy converting the normals into angles if I didn't have to.


this.mess = abs(sin(times#))
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 1st Apr 2013 19:36
yes but raycasting is consuming a lot ... :/
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Apr 2013 23:42
i would try to rotate with Quaternions the object to the surface normal (your local up vector) too.
(the surface normal is only a direction with length=1.)
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 2nd Apr 2013 01:07
that is exactly what i've tried ... but without success
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Apr 2013 09:35
ok, i will play with quaternions in agk.
for my helicopter game in blitz max i use this to align.
my own simple solution.
(.Turn use Axis Rotate)
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 3rd Apr 2013 11:13
already tried that too and not very relevant in my case ... i have to compute the object rotation (and its facing direction vector) with the terrain normals/angles
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Apr 2013 13:53
Is this for the 3D racer? If so I don't think the vehicles should rotate to suit the terrain, I think they should rotate and turn based on how they are driven. I'm not sure how you plan to let this affect your vehicles but it might not appear very realistic.


this.mess = abs(sin(times#))
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 3rd Apr 2013 22:31 Edited at: 3rd Apr 2013 22:42
my example use a object up vector and the world up vector.
how you can get the up vector in agk from a object?
or the down vector from bottom face.

with only the ground angle i have no relation between gound and object.

edit:i attach a pic

Attachments

Login to view attachments
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 3rd Apr 2013 22:49 Edited at: 3rd Apr 2013 22:49
but with the angle i can set the rotation at once with SetObjectRotation
look pic

a smooth align is better...

Attachments

Login to view attachments
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 3rd Apr 2013 23:15 Edited at: 3rd Apr 2013 23:17
my result
a align cube sliding on ground
the sliding was a side effect LOL

useing the 4 cursor keys
i rotate the ground plane for simulation a other normal vector.

MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 3rd Apr 2013 23:44 Edited at: 3rd Apr 2013 23:44
Thanks for the code snippet, i have the same result (IT IS the problem) but try this to undestand my problem :

Simply add (my object is turning around his local Y axis):




before or after your (in the main loop) :



and look at the problem i encounter when you move with arrow keys...
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 4th Apr 2013 00:07
Quote: "Is this for the 3D racer? If so I don't think the vehicles should rotate to suit the terrain, I think they should rotate and turn based on how they are driven. I'm not sure how you plan to let this affect your vehicles but it might not appear very realistic.
"


it's for my 3D racer yes. i only want to pitch the vehicle. Yaw and roll totally relies on the player commands



i already doing it with lookat commands and it's ok (but use a lot of time) i will post a video
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 4th Apr 2013 00:43 Edited at: 4th Apr 2013 00:48
ahh,
you need a line pick in front(nose) and back(tail) from your plane.
then you have 2 heights (Y front AND Y back at ground level) and a angle for pitch,true?
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 4th Apr 2013 01:04 Edited at: 4th Apr 2013 01:22
no.

I just want my ship to be parallel to the ground (ie perpendicular to the ground's normals ) according to the ship direction (Y axis rotation)

edit : but not fully parrallel ... i want to stabilize the roll (according to the player direction)
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 4th Apr 2013 02:20
Here is the result i want (and the result i have but i want it with formulas (and not by using movelocalZ , collision and lookat commands for a second point ... due to heavy cpu consumption)

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 4th Apr 2013 11:15 Edited at: 4th Apr 2013 11:32
true,
i atach a pic.
you wrote you only want pitch the object, from inside cockpit
this is up down.
for roll this is the same but you need two line picks left and right from wing.
for stabilize you turn only a part each frame
you want 45 degree in 1 second = 45° /60 fps
roll=roll+ (45° /60 fps)

Attachments

Login to view attachments
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 4th Apr 2013 13:45 Edited at: 4th Apr 2013 13:47
i want the correct global object rotation according to the actual yaw angle (must be computed). The roll angle according to the left/right input is not a problem.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Apr 2013 14:01
You can use the suggestion by Markus to get an accurate pitch for your ship using only 2 raycasts and by adjusting your ship by rotating in X by the angle returned. It will not get much simpler than that.

Assume the distance from the front to the back of your ship is X#, the difference in length of the two raycasts from these points is Y# and you have a cheap calculation:
ANGLE# = atan(X#/Y#)
RotateObjectLocalX( objID, -ANGLE# )

That's only two lines of code!


this.mess = abs(sin(times#))
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 4th Apr 2013 20:39 Edited at: 4th Apr 2013 20:41
the beginning rays are something like this
x=shipx+cos(yaw)*shiplenght/2
z=shipy+sin(yaw)*shiplenght/2
y=shipy

x=shipx+cos(yaw+180)*shiplenght/2
z=shipz+sin(yaw+180)*shiplenght/2
y=shipy
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 5th Apr 2013 00:46 Edited at: 5th Apr 2013 00:50
Ok thanks ! An example should be into the Code snippets section !

Finally i managed to regroup my needs without using maths and save framerate :

- MultipleRaycasts function for vertical test (ship height, CheckPoint crossing, Bonus crossing etc etc) (yes it's doing multiple raycast tests but no other choice to get all the collisions points through multiple objects). Here is the code if it can help someone (Waiting for Paul to work on a "pass through multiple objects" raycast function in one pass):



(Strangely it seems i can't use the simple "ObjectRayCast" command (doesn't work on a loaded object maybe ?) and i don't undestand why i need to use each time the Sphere raycast version (with a very small radius). If someone can help me to understand ... I know that it works with predefined AppGameKit object (sphere,cubes etc ..) but not with my OBJ terrain ...)



- and another vertical raycast (few units to local Z+) to retrieve another point to look at (and so getting the good pitch for my ship) which retrieves also a possible jump even on edges rounded mountains. It's possible to simply check the heights with the first vertical raycast but with an high framerate, the raycasting test is taking every floor points which doesn't allow to check an height diff correctly.... and i don't always have a "clean and radical" springboard on my terrain


Anyway, thanks Markus and Baxslash for your help i'm sure i will have to use your code snippets for other things

Login to post a reply

Server time is: 2024-11-24 11:54:43
Your offset time is: 2024-11-24 11:54:43