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 / How Do You Tilt An Object On A Matrix?

Author
Message
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 7th Aug 2009 17:30
This must be one of the few remaining DBC questions which appears to remain unanswered.

I've seen many examples, but none work 100% correctly - especially when using the Move Object command (rather than Position Object ObjNum,X,Y,Z). Those that are nearly there suffer from the same problem that my own attempts do (see beow).

I have to confess at the start that I was never any good with trig at school so my maths is being stretched to the limits as it is...

I'd like to suggest that we all chip in a bit of knowledge and communally see if we can crack this problem once and for all.

Object Of The Excercise:

To make the function in the code snippet below work. You should be able to use the cursor keys to move the box on the matrix. As it moves onto a slope, the box should tilt to reflect the angle of the matrix - regardless of the direction you move.

Empty Code Snippet To Start Us Off:



Note: I've added [N]orth, [S]outh, [E]ast and [W]est keys to quickly point the box to the main 0, 180, 90 and 270 degree headings while testing.


My Attempt So Far:

ATanFull(X,Y) will return the angle between two points so my reasoning was that I should define two points - one at the front of the box and one at the back.

If I got the height of the matrix at the front point and the height of the matrix at the back point, subtracting one from the other would give me 'Y' in the above formula.

In the same way, getting the X positions of the front and back points and subtracting one from the other will give me the 'X'.

This works and ATanFull returns the slope angle on the matrix.

But, the box needs to be tilted on two axis, so we also need two points on the left and right of the box. Two ATanFull's then give us the XRotate and ZRotate angles to rotate the box.

The first problem is that as the box turns, the four points do not. After a bit of head scratching and a lot of trial and error, I've fixed that problem. So, as the box rotates, the four test points now keep track with it.

In the snippet below, I've created four tiny cubes and positioned them at the four points - purely as a visual aid. In the final version, these cubes will not be required.

Now for the problem I simply can't get my head around:

If the box is pointing North or South, then all is well. But, when the box is pointing East, rotating the box with either XRotate or ZRotate turns the box in exactly the same way.

This is totally baffling me and I guess is down to the strange properties of Euler rotation - something else I don't fully understand.

Anyway, I added another object (a cone) and tried to use it to apply rotations to - and then apply them to the box. But that idea failed abysmally - for the same reason! When the box is at 90 degrees (pointing East), even though I can calculate the angle of the slope, I cannot apply it to the box.

My Very Rough Code Snippet So Far:



Note: This snippet is my rough workings and is a bit of a shambles. It has lots of remmed out sections - left in to give you an idea of what I was trying to do.

The section I can't figure out is highlighted 'FAULTY HEADING EAST SECTION' and is only called when the Y angle of the box is set to 90. You can quickly set it to 90 by pressing the E key.

As you can see when you run it, the Z slope angle is calculated (ZATF), but when applied to the box, it rotates on the world X axis whether you use XRotate or ZRotate.

I was using floats for XATF and ZATF, but rounding errors caused problems so I switched to floats. The rotation angles don't actually need float precision and it's smooth enough with integers.

Please feel free to use anything I have done (if it's of any use) and tweak it to make a working function in the communal snippet at the top.

Or, if your expertise is more in maths than programming, you can attempt to explain where I am going wrong.

Hopefully we can get a working function we can all find a use for - especially fr future DBC challenges - which what got me started on this in the first place...

TDK

TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 7th Aug 2009 17:44 Edited at: 7th Aug 2009 17:45
Did you get my e-mail, TDK? If not, I'll post the code here:



TheComet


Make the path of your enemies easier with Waypoint Pro!
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 7th Aug 2009 18:08
Sorry - I've not set up my new mailboxes yet, so I don't have a working email at the moment.

As a program on it's own, yes, it works perfectly. I actually have that snippet already.

However, it isn't what this thread is about. Maybe I waffled too much in the OP and people are missing the important points in all the text. So, for clarification, here they are.

The object is for all of us to contribute to create a general purpose Matrix/object tilt function which:

1. Rotates any object based on it's current X/Y/Z location on a matrix.

2. Will work if you use 'Move Object' to control your object as well as 'Position Object'.

It's the conversion to making it Move Object compatible which is causing the problem.

The way my DBC Programming Challenge entry works, it's impossible to use the method used in the snowboarding example without re-writing the whole lot.

What's needed is a generic function we can drop into our programs and simply call with the object number and it rotates the object to match the matrix at it's current X/Y/Z location.

Thanks for trying though. Run the first snippet above and then try copying code from your snippet into it to get it to work and you'll see exactly what I mean!

TDK

TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 7th Aug 2009 19:40 Edited at: 7th Aug 2009 19:41
So what you want to do is have a function that can rotate an object without any help objects or dummy objects according to the angle of the matrix? Brick Break asked a question not too long ago about that. And as Latch said in that thread, this will come down to matrix rotation math. But now I remember that that isn't such a bad idea after all. I used matrix rotation math for my spiral generator, so why not use it here? Here are the formulas:




ax, ay, az are the angles, XYZ the current positions of the object, and X'Y'Z' the destination positions. If you combine this with your code I posted above, you will be able to write such a function. I wish you luck!

TheComet


Make the path of your enemies easier with Waypoint Pro!
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 7th Aug 2009 20:03
Quote: "So what you want to do is have a function that can rotate an object without any help objects or dummy objects"


No, I'm not saying that. If you need dummy objects then it's fine to use them - as many as you want. It's not important what method is actually used as long as the object is rotated to match the matrix.

Ideally we just want to be able to say to a function: here's the object number and matrix number - go and rotate the object to match the matrix slope at it's current position. It sounds ever so simple when you say it like that...

Lots of people have answered this question with "all you need to do is X, Y and Z" but to the best of my knowledge no-one has actually come up with a code sippet which actually does it - hence this thread.

Maybe it can't actually be done - I don't know.

Maybe someone with a better understanding of maths than me can point us in the right direction if they look at my second code snippet.

I've already figured out the X and Z angles I need to rotate the object - I'm just struggling to apply those angles to the object.

TDK

Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 7th Aug 2009 20:21 Edited at: 7th Aug 2009 20:28
What do you mean by, "not working 100%",Tdk? erm...........I remember one that used "Feelers" to achive this, i'll have to dig it out.

Darn you, you got me so interested now that i've been looking for it.............

I'll have fun playin wit this

edit
Quote: "The object is for all of us to contribute to create a general purpose Matrix/object tilt function which:
"


Kinda like the idea, in fact we should do a lot more functions once this one's done.......


Quote: "someone with a better understanding of maths than me can point us in the right direction "


Idk, its a battle between you,obese and Latch. You three are the best ive seen here when it comes to all that Math stuff.

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Aug 2009 00:52
I have been on this for over 2 hours now, and I can't seem to figure out this part in my function:



You can imagine the X and Z angles as two rods. One laid down facing away from you, and the other rotated 90 on top of it facing left and right of you. These are the X and Z axises. The problem is that they never rotate with the object's Y angle. The rods will always face the direction they originally were, not affected by the Y axis.

This part



Will blend the two angles returned into each other, so when the car is yrotated 90°, the X axis of the car is actually rotated by the value of the Z axis and the Z axis of the car is actually rotated by the value of the X axis. But it doesn't seem to work! Am I thinking way too far or not enough?

TheComet


Make the path of your enemies easier with Waypoint Pro!
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Aug 2009 03:01 Edited at: 8th Aug 2009 03:05
I know I've said it over and over like a broken record, but a pivot object makes things easier. It's not the only solution, but it takes some of the headaches out of the problems with eulers.

The pivot object is an object that gets moved around by whatever controls. The pivot object is positioned to the correct heights and rotated on it's y axis. The vehicle that tilts, is glued to the pivot object. The vehicle's y local orientation(rotation) never changes, but it's world y changes with the rotation of the pivot object because it is glued to it.

So, for those objects that we want to tilt, create a pivot object as well.

Steps:
1. Create main object
2. Create pivot object
3. glue main to pivot (or setup as a limb - ignore this for now)
4. position pivot object, and yrotate pivot as necessary
5. call tilt function to tilt main object




Enjoy your day.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 8th Aug 2009 19:16
Quote: "From TheComet: The problem is that they never rotate with the object's Y angle. The rods will always face the direction they originally were, not affected by the Y axis."


Exactly!

Quote: "From Me: The first problem is that as the box turns, the four points do not. After a bit of head scratching and a lot of trial and error, I've fixed that problem. So, as the box rotates, the four test points now keep track with it."


From what I know now (thanks to Latch) this is where the 'pivot' object comes in. I was thinking of a pivot in the sense of an X or Z axis 'see-saw' and not as something vertical to mirror the Y axis. That's where I've been going wrong...

Quote: "From TheComet: Am I thinking way too far or not enough?"


I think it's down to the strange properties of Euler rotations and is why I never managed t crack the problem myself. Latch's solution below seems the best method and I'm goinfg to use his example to try and create what I need.

Quote: "From Latch: I know I've said it over and over like a broken record, but a pivot object makes things easier."


Lol - I don't mind at all - some things have to be said over and over again before they sink in - especially with old thickos like me!

The problem was that I didn't really have a grasp of exactly what you meant by a 'pivot'. Now I've enlarged the plain big enough to see it I can see what is going on. Many thanks for that!

Going to drop it into my challenge entry and see what happens - altering it accordingly.

As I said in the OP, my aim is to ultimately have a function that can be dropped into any DB program and be used by a single function call.

Looks at first glance that your snippet should need little or no modification to do just that!

TDK

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Aug 2009 20:32
Quote: "The problem was that I didn't really have a grasp of exactly what you meant by a 'pivot'. Now I've enlarged the plain big enough to see it I can see what is going on. Many thanks for that!"

I was probably just explaining it poorly without demonstrating the example. I'm glad it makes sense now.

Enjoy your day.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Aug 2009 20:34
@TDK

I thought you know about the glued object trick. Because you were the first one that showed me how to tilt an object on a matrix. This is very confusing.

TheComet


Make the path of your enemies easier with Waypoint Pro!
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 8th Aug 2009 21:10
Quote: "Because you were the first one that showed me how to tilt an object on a matrix"


I probably just gave you a code snippet which did what you wanted to do at the time.

Obviously I already had a snippet which would tilt an object on a matrix but it couldn't be just dropped into any DB program.

The method I am using at the moment for an 'all-purpose' function was not working because of my limited knowledge of Euler rotation.

TDK

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Aug 2009 00:51
Uh oh. Hold the phone. There is a problem with glue object. Any objects out of camera view that are glued to an object, do not update their positions. So if you bring them back into view, if the object that they were glued to moves, they will no longer match the position of that object. They will sit whereever they went out of camera view.

So, as long as the glued obejct stays in viewm it's ok.

An alternative to the glued object is using limbs in the same way. Limb 0, the pivot, if you will, will have limb 1 which is the tiltable vehicle. Create a mesh out of the vehicle and add it as limb 1. Apply y rotations to the main object just like the pivot object, and apply the tilt rotations to the limb.

For complex objects with rotating tires and such, use multiple limbs and linkthem to limb 1 accordingly.

Enjoy your day.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 9th Aug 2009 01:23
I've actually got my own method working using your advice with the pivot object - before it only worked going North and South. Now, even going East and West, the box tilts correctly.

As I'm doing things a little differently in my function, the problem you describe may not affect me... fingers crossed!

I'm now working on the angles between N, S, E and W...

TDK

Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 12th Aug 2009 09:24 Edited at: 12th Aug 2009 09:26
Quote: "Idk, its a battle between you,obese and Latch. You three are the best ive seen here when it comes to all that Math stuff."

haha I think you mean BN2 and Latch
I pretend to do maths

Although I did realise
Quote: "If I got the height of the matrix at the front point and the height of the matrix at the back point, subtracting one from the other would give me 'Y' in the above formula."

No it wouldn't it would give you the difference, you want the average (ay+by)/2
[edit]Hmm now I am wondering if that isn't right in the first place.
Maybe I should actually read this function first![/edit]
And don't we need four points if were going to be able to yrotate this cube?

I remember the Tank demo had a tilting function, what was the problem with that one?

TGC Forum - converting error messages into sarcasm since 2002.
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 12th Aug 2009 23:33
Quote: "haha I think you mean BN2 and Latch
I pretend to do maths "

Then you are one star actor!

u seemed to do good, but now i guess i can magically change you back to the status of N00B.

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Bluestar4
18
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 14th Aug 2009 08:45

tkd your the best I was going to implement this in HB, but it didn't look right to have the characters slanting with the slopes.
I usually keep backups of the code at every minor versions so I'll look in my source and see if I cant find it. This might take a day as the source was quite large, but I remember that its there somewhere.

bluestar4~
---Missle Might - Hero Battles - Zillipede --- which do you like the best ?
Monk
15
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 14th Aug 2009 13:12 Edited at: 14th Aug 2009 13:19
Can you use limbs in DBC?

If so, dont rotate the object, just rotate the limb 0.

That might work.

Edit:
Do the up,down, and left parts of your snippet work TDK?
If so, this may or may not work as the right bit...




Monk

I like work. It fascinates me. I sit and look at it for hours.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 14th Aug 2009 14:49
I'm just curious. Did anyone try the code I posted above? It completely works with tilt in all directions. Though there's a general glitch in DBC with glued objects moving out of camera view not being glued anymore. So a limb would be the better solution. Here's that variation:



Enjoy your day.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 14th Aug 2009 15:21 Edited at: 14th Aug 2009 15:22
Quote: "Can you use limbs in DBC?

If so, dont rotate the object, just rotate the limb 0. "


Our feet, and hips tilt to the landscape, that would look better than straight feet, and hips. Then we bend out knees.. it gets a bit complicated.

Bluestar4
18
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 15th Aug 2009 09:14 Edited at: 15th Aug 2009 16:35
This was my solution. Simular to latches, except in place of using limbs, sorry I posted the wrong code. Here is one that works perfectly for getting the pitch , no dependencies on your math skills,limbs,commands that glitch or slow math commands :


oh and btw tdk, those wonderful atans dont always return an accurate angle. I experianced this as well when programming the AI for hb so had to program in a fix so that characters wouldn't just walk off the map. anyway, if you can get the angle of the east/west all you would have to do is add a roll object right/left command in the function I have provided. Hope this helps.

bluestar4~
---Missle Might - Hero Battles - Zillipede --- which do you like the best ?
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 17th Aug 2009 00:14 Edited at: 17th Aug 2009 00:21
Quote: "Our feet, and hips tilt to the landscape, that would look better than straight feet, and hips. Then we bend out knees.. it gets a bit complicated."


oooooh, thats the problem Ok now every thing makes scince! heheh.......

Quote: "but it didn't look right to have the characters slanting with the slopes.
"


This might sound dumb but try only rotating parts that will actually be effected by the matrix in real life; Like the feet for example - when you rotate the characters feet to the matrix as they are walking, you get a nice,clean effect, i think

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Bluestar4
18
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 18th Aug 2009 16:32
yes , thats an excellent Idea, next time I do something like that I'll have to try that out.

bluestar4~
---Missle Might - Hero Battles - Zillipede --- which do you like the best ?
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 18th Aug 2009 20:15
Will You try it "Hb"?
I think it would be a great improvement to that game.....

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Bluestar4
18
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 18th Aug 2009 21:17
yes it is possible to do so with HB. I see no harm in attempting it. I probably need to optimize the code a little anyway. Here is what I will do, I will make one version where the characters just slant , and will attempt to make a working version where just their feet slant and you can test them all and tell me whitch one you like the best DD.

bluestar4~
---Missle Might - Hero Battles - Zillipede --- which do you like the best ?
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 18th Aug 2009 23:36
kk, cant wait, cuz i just love Hero battles - its like a way better version of my first cheezy little game....

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Bluestar4
18
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 19th Aug 2009 06:54
ok, now here is a screenshot of what I was meaning DD. It doesn't look good. The life bar is vertical , and the dragon isn't.

bluestar4~
---Missle Might - Hero Battles - Zillipede --- which do you like the best ?

Attachments

Login to view attachments
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 19th Aug 2009 23:25
Hmmmm....try attaching the life bar to the dragon with
, and see if that helps......

How goes it with the "Feet"? lol.

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Bluestar4
18
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 20th Aug 2009 00:09 Edited at: 21st Aug 2009 07:03
actually it turned out pretty neat with earthquakes on. new version for you DD complete with new sound track as well.

@tdk, here is an alternate version of the function above that I used in the game. Not 100% accurate but it does produce some interesting effects.



Latch also made a thread so might as well include it for this thread
http://forum.thegamecreators.com/?m=forum_view&t=136645&b=10

bluestar4~
---Missle Might - Hero Battles - Zillipede --- which do you like the best ?

Login to post a reply

Server time is: 2024-03-29 11:55:58
Your offset time is: 2024-03-29 11:55:58