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.

Dark GDK / Modifying an object's world matrix and manual rendering

Author
Message
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 20th Feb 2012 00:32
Hello everyone,

I'm wanting to use DarkGDK but in a slightly different way. I like to keep my scenes organised into a hierarchy, and to do this I want all objects to be placed relative to each other. This is tricky using the standard dbPosition/Rotate/ScaleObject commands, but pretty easy using matrices. I know it's possible to modify an object's world matrix through the sObject struct, but it doesn't render from all camera angles and/or positions. Is there any way to change it and keep GDK happy?

Also, I would like to be able to render an object when I tell it to, and do away with dbSync. The reason for this is that I want to traverse the hierarchy and only draw an object when it's been reached. This means that if I miss out a node because it's too far away or not in view, I don't draw it, and neither do I draw any of the child objects. To achieve this would require me to call dbShow/HideObject on every object in the scene graph, which kinda ruins the point of the optimisation.


TL;DR, I want to change an object's world matrix without it screwing up, and I want to be able to draw objects when needed.

Anyone got any hints for this?

"everyone forgets a semi-colon sometimes." - Phaelax
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 20th Feb 2012 13:52
There is really no way around it (that I can tell). You have to do each object seperately. You could place all the object in a hierarchy like a list of structs. Just check the list each time you get to another part of the hierachy and use dbExcludeObjectOn()/dbExcludeObjectOff() for each object in the hierachy.

I'm sure you were looking for something better, but that's all I have.

As far as the matrix part, I'm not even sure why you want to do it manually.....

The fastest code is the code never written.
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 20th Feb 2012 17:26
Create your own command for rendering dbpro objects, check dbpro source code to get an idea how to do it

For setting matrix manualy:
in sObject structure there's a parameter matrixOveride, set it to true and then set absolute world matrix of an object with your own matrix

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 20th Feb 2012 22:36 Edited at: 20th Feb 2012 22:37
Brendy boy, thanks, I think I'll be fine as long as I can manipulate the matrix. I'll try and see if I can figure out GDK's code for rendering.

Hawkblood,

I actually forgot about the exclude object commands, so that should be useful to me. As for making a list, it probably won't work how I want it to, as the whole point of the optimisation is to not even have to visit certain nodes, but if I figure out I'll post and let everyone know.

As for the matrix part, I perhaps didn't explain it clearly. The idea is basically the same as limbs on objects, except with any other kind of entity. If one object is attached to another (as a child object), and the parent moves or rotates, the child's relative position to the parent should stay the same. Not only that but it should rotate accordingly too. It's possible to position it using trig, but it's a lot of calculations and quite slow, and not exactly easy to figure out either. Rotation, in GDK, is terrible. I've never figured out how to solve this problem using GDK's rotation commands.

But by using a single 4x4 matrix, you can encode the object's position, scale and size. And to position/rotate/scale it relative to it's parent, you simply multiply it by it's parent's matrix. This is just an internal optimisation of course - my classes will give access to position, angle and scale vectors just like GDK does.


Anyway, thanks for the help!

"everyone forgets a semi-colon sometimes." - Phaelax
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 21st Feb 2012 01:09
Try
Quote: "void dbGlueObjectToLimb ( int iObject, int iSecondObject, int iLimb )"

That works well enough for me.....

The fastest code is the code never written.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 21st Feb 2012 01:39
Yeah that will work for just objects, but it's not a pretty solution and it doesn't work with everything.

The basic idea is that you have an abstract base class that will be the root of all 3d entities in a game (objects, lights, 3d sounds). There is also a virtual update method to be called for each of them. By manually making the scene graph like this, you can attach anything to anything else. A spaceship would have a few thrusters attached to it. Each thruster would then have a light attached to it, and maybe even a particle effect. When you move the ship, everything moves. When you update the ship, it then updates all child nodes, so you can have complex behaviour, easily.

Now that I know how to change the world matrix of an object, the rest should be pretty straightforward.

"everyone forgets a semi-colon sometimes." - Phaelax
WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Feb 2012 03:38
I'll be back to GDK sometime soon but I know what you're after. Full control. I'm faffing with raw openGL and glut at the moment so I've got full control over everything. granted I don't have the libs and stuff that does what GDK does but it's teaching me a lot about how things are processed on the GPU, 2D and 3D.

In openGL you can set the world matrix, whether it be projection, ortho, etc,(or even your camera matrix) and save your main matrix on the GPU stack each time you "draw" an object, pop the matrix and it will be transformed to the saved matrix when you pop the matrix from the stack. The GPU's stacks are only limited by your GPU basically which are quite a few and I'm on a crappy laptop with crappy graphics.

It's nice to know that at any point you can reset your projection matrix and anything "drawn" afterwards is set to that only.

Jumping from 3D to 2D and back again is as easy as saving the matrices and other settings on the GPU stack, setting the 2D stuff up, drawing it, popping everything off the GPU stack then carry on as if nothing happened...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 22nd Feb 2012 13:54
If you want full control, simply go to pure DirectX. It's a pain, but you get whatever you want in control.

The fastest code is the code never written.

Login to post a reply

Server time is: 2024-11-23 00:41:50
Your offset time is: 2024-11-23 00:41:50