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 Professional Discussion / Transformation matrix - maybe

Author
Message
Lord Einstein
20
Years of Service
User Offline
Joined: 22nd Oct 2005
Location: Well here, of course...
Posted: 20th Apr 2010 01:18
I want a plain object in 3D space rotated at random angles. When the player approaches it the whole scene reloads with the plain replaced with a 2D matrix and the player re-orientated and re-positioned so that they see no change except in an increase in detail of the plain object.

I think this would involve transformation matrix's but my knowledge of them is not very good and I don't know how to implement them in DBP.
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 20th Apr 2010 05:14
Hm? It sounds like you want LOD... Can you explain your problem in more detail, or give some pictures, or links to things you're trying to mimic?

Lord Einstein
20
Years of Service
User Offline
Joined: 22nd Oct 2005
Location: Well here, of course...
Posted: 20th Apr 2010 10:32
It could be used to create a bit of LOD but I don't know of any system which uses this method. But if they do it correctly you wouldn't know that they used it

Look at my expertly drawn diagram bellow:
[img][/img]

Basically the ship approaches the randomly rotated object which could be a piece of planet terrain, asteroid or space station. The scene then reloads with this object at the centre of the new scene and everything else positioned around it. With this I can have a player approach say a space station which is orbiting a planet, dock and then look out of the window and watching the planet and stars roll bellow them.
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 20th Apr 2010 11:17
Ah, I misunderstood. Hmm, I don't know if there is a way to apply your own world matrix to an object, but you could try offsetting each object so that its transformation center is at the center of the world, rotate it, and then offset its center back to its original position. I'm intrigued. I'll play around with this tomorrow, but for now I'm off to bed (it's 4:17am).

Lord Einstein
20
Years of Service
User Offline
Joined: 22nd Oct 2005
Location: Well here, of course...
Posted: 20th Apr 2010 15:30 Edited at: 20th Apr 2010 15:31
Hmm. I've tried something similar by trying to set the objects orientation to that of the plain and then rotating it in the opposite direction to the plains rotation and then offsetting it with the move object commands.

Here is my latest attempt. The solution should appear as if the plain just changes to a wire frame model when the space key is pressed. At the moment this is obviously not the case.

I have tried using free flight, eular and global rotations with the free EZ rotate plugin but I can't seem to get it working.

Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 21st Apr 2010 02:39
Well, the concept is simple enough. You need to get the world matrix of every object that will be repositioned and multiply each of them with the inverse world matrix of the object that defines the new center. Getting these matrices from object angles and positions is easy, but the hard part will be applying the new matrix you get for each object. I've seen some functions flying around that will extract Euler angles from a matrix, and for position, just grab the far right column. Implementing this whole thing in code's gonna be the real challenge.

Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 23rd Apr 2010 06:58 Edited at: 23rd Apr 2010 07:02
Success!

Play around with this:


If you press the spacebar, the entire scene will reorient around the player, who will be placed and oriented at the origin. Twas no easy task dealing with DBPro matrices. I hate them.

I hope this helps, and feel free to ask about anything. Now you can adapt this to do whatever object switching you had in mind.

Edit: You can see that the lighting on all of the objects is a little strange, but that's because the lights in the scene don't get reoriented with the objects. Make sure to do that.

Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 23rd Apr 2010 07:07
That's pretty swish. Well done.

Lord Einstein
20
Years of Service
User Offline
Joined: 22nd Oct 2005
Location: Well here, of course...
Posted: 23rd Apr 2010 14:33 Edited at: 23rd Apr 2010 14:35
Wow! Kira Vakaan that's amazing and will allow planets and everything else to be rendered pretty easily.
I hadn't done much experimenting since my first attempts but looking at that, it looks incredibly complicated and I haven't had any experience with matrices in Dark Basic. I've only done a little but in maths at school anyway.
Hopefully I can learn how to effectively use them from your demo and put the system to good use in my game. I'm going to have to make it reorientate the world around 1 particular object but it should be easy to change it from the player to any other object. Thanks.
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 23rd Apr 2010 19:17
You're plenty welcome
I'm glad that's more or less what you're looking for.

In the end, DBPro matrices behave exactly like matrices in the math world, but I just really dislike how one has to work with them in DBPro. I don't know about you, but I learned a bit about matrix algebra in high school, but they never taught me anything about matrix transformations with vectors or anything, so I had to learn that myself. If you have any questions about the math, please feel free to ask. I'd be more than happy to expedite the learning process for someone else.

Login to post a reply

Server time is: 2026-07-26 04:28:13
Your offset time is: 2026-07-26 04:28:13