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.

DarkBASIC Discussion / matrix plane

Author
Message
Code eater
17
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 7th Sep 2008 17:21 Edited at: 8th Sep 2008 19:12
I have managed to write a piece of code to make a taxi rotate to the angle of the matrix below it just by finding the height underneith the right, left, front and back wheels.

I then wanted to use a plane instead of a matrix because it would be easier to make a world as a .x file than a matrix so i tried and using sparkys dll i managed to get it working except that it doesnt always tip correctly and sometimes goes up to 90 degrees off what it should be.

Ive attached a folder with both the one that works using a matrix and the one that doesnt work with a .x file. If any one can suggest why this may not be working please post.

all responses are appreciated...

codeeater

[edit]

I forgot to unrem the scale object 1000 and position object 1000 you may need to do this for it to work!

Attachments

Login to view attachments
Code eater
17
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 8th Sep 2008 19:13
Sorry forgot to attach models should be fine now
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Sep 2008 04:28
check out:

http://forum.thegamecreators.com/?m=forum_view&t=136645&b=10

And try using atanfull() instead of atan() . Atanfull will eliminate a possible division by zero error and it will return a fuller range of angles than atan()

Enjoy your day.
Code eater
17
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 12th Sep 2008 20:38
hi,,,

I tried atanfull() bt it doesnt seem to make a difference. does it for you?

I had a look at the tutorial but neither "dll_ground_height.dba" or "dll_ground_height_2.dba" work (I'm not wuite sure what they are alled as i am not on the pc witht hem saved on butt hats roughly their names)

In "dll_ground_height.dba" it cannot load the terrain as i didnot seem to download that file but i replaced it with another 3ds file and it worked fine assuming that the camera was not ment to tip.

In "dll_ground_height_2" it has trouble when i call the function "sparkys_tilt" or whatever it is called. When I can I will post the error it returns.


thank,,,

codeeater
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 12th Sep 2008 21:32
I looked through your code (you haven't included the matrix plane object in your download so I used my own) and the theory looks ok. With all of the variables and calculations and the general layout, it's a bit hard to follow in detail but the problem seems to be in the arctangent calculation for the tilts. Maybe try reversing the order of the subtractions (front-back vs back-front etc) and see if that makes a difference. That will change the direction of the angle. The other problem, unless you are accounting for it with math, is when you change the x or z rotation of an object, you can change the orientation of y or any other angle unitentionally. In the case of tilting an object to a terrain, it's usually helpful to use a pivot object that only changes it's y rotation and glue your main object on top of that that changes x and z orientation. That way, the pivot object move up and down according to the height of the terrain and turns left or right, and the main object glued to it tils on the x and z without affecting the height or direction.

Quote: "I had a look at the tutorial but neither "dll_ground_height.dba" or "dll_ground_height_2.dba" work "


What? Not the case at all here. What happens?

The get ground height example just shows how to get the ground height. The camera moves up and down according to the terrain. The vehicle tilt uses the ideas of how to get the ground height to calculate the slope of the terrain at the vehicles position and turn that into an x and z angle. I reworked your taxi tilt code a bit by adding my sparky's tilt function and it works fine with your code (I don't use the matrix height subroutine). Here's that version. Look through it and see if you can understand what I'm doing. The premise is the same as what you were trying to do:



Enjoy your day.
Code eater
17
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 13th Sep 2008 23:20 Edited at: 13th Sep 2008 23:24
@latch

Quote: "What? Not the case at all here. What happens?
"


Basicly for "dll_ground_height.dba" it doesnt have the terrain file but thats it and for "dll_ground_height_2.dba" it has trouble with the line:


and it says that "PARAMETER MISMATCH. EQUALS MUST ASSIGN A VALUE TO A VARIABLE"

Your code works brilliantly. But why do I need an object to pivot off?

but for now as I have it all working I can get on with developing my game!

thanks,,,

codeeater
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 14th Sep 2008 03:32
OOOPS! I forgot to include the terrain! Good catch, I'll update the download link.

Quote: "and it says that "PARAMETER MISMATCH. EQUALS MUST ASSIGN A VALUE TO A VARIABLE""

hmmmm... If it is complaining about the hc# assignment, It would seem that no value is being returned from the function. But when I look at the function, I see the center height being returned. I also don't get the error. Maybe it has to do with the terrain file not being included - which is now included.

Quote: "Your code works brilliantly. But why do I need an object to pivot off?"


Well, when you change the x y and z angles of an object, you can change it's orientation such that the behavior of rotation can be opposite of what you'd expect.

When you have a pivot object, the glued object's y angle never changes, so x and z always pivot relative to angle y=0.

For example, if you xrotate an object 30 degrees, then y rotate it 180 degrees, the actual x orientation relative to the direction the object is facing would be 330 degrees (at angle y=0 the object would be pointing down and at y=180 the object would be pointing up). However, DB would still be reporting the x angle as 30 degrees. If the object had been on a downward slope at y=0, then when it turns around to y=180, it would be on an upward slope so the tilt calculation would be in the opposite direction. The tilt calculation would calculate the angle at 330. If you were now to tilt the object 330 degrees it would point the object on the wrong tilt (down on an upward slope).



With math you can compensate, but using a pivot object is much easier.

Enjoy your day.

Login to post a reply

Server time is: 2025-06-07 06:52:14
Your offset time is: 2025-06-07 06:52:14