Drawing bodies and fixtures

General discussion about the R.U.B.E editor
rileyrg
Posts: 54
Joined: Sun Jul 19, 2015 11:42 am

Re: Drawing bodies and fixtures

Post by rileyrg »

I think I had better give up now as I'm clearly not explaining myself.

Yes, I do know how to display textures in libdx and I have my own animation class which uses a an atlas and corresponding packed texture.

The only thing I dont understand is how to get the position of a polygon fixture as shown as fixture2 which is offset from the body2 in the very first post. I'll re-read the thread but I think I keep asking the same thing so I'm guessing somewhere I have confused myself. I dont want , or rather think I need, to have to retrieve an "image" which I dont use in my in game rendering. That "image" is merely a placeholder in the rube editor.

btw, just got version 1 of b2djson loader working with libgdx :) If and when its fully working I'll post it on to you.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Drawing bodies and fixtures

Post by iforce2d »

The problem from my point of view is that the question you're asking doesn't seem to match the overall goal.

Yes, the image you place in RUBE would be a placeholder. That is where you will draw the frames of the animated texture right? Presumably the image you are placing there in RUBE is one frame of the animation?

Perhaps taking a step back for a bit, we could define the overall goal more clearly. This is what I'm understanding it to be, correct me where I've gone wrong:
1. We want to draw animation frames at the object position, which move along with the object
2. Animation frames are a rectangular texture which has a position and angle relative to the body
3. The position and angle of the texture relative to its body are defined by the placeholder image in RUBE
4. All frames of the animation will be the same size.

So when loading the scene, we need to look at the position and angle of the placeholder image relative to its body. To render the final result, we need to render whatever frame of the animation is current, at the placeholder position, and use the current body position and angle to transform it into the right place. Nothing in this process requires knowing anything at all about fixtures...

If you really do need to know where every vertex of a fixture is, as I said the best way would be to look at how libgdx is rendering the debug draw. But even if you did know the positions of all the vertices - I don't understand how you could use them to position a texture.
rileyrg
Posts: 54
Joined: Sun Jul 19, 2015 11:42 am

Re: Drawing bodies and fixtures

Post by rileyrg »

You appear to be saying I must use a placeholder image. I certainly dont want to know anything about vertices and thought I was clear on that in my previous reply. I had some idea that this would be a bad thing (using a placeholder image) because I need to query it each render loop. Or do I just calculate an offset when I create the body and its fixtures and then run with that relative to the body position and angle each render? I realise this is probably really frustrating for you but it's really quite confused me! The gdx render code doesnt treat the n sided polygon, or rather multiple n fixtures, as a single shape when debug rendering so doesnt explain where I should position my texture. So in pictures : when my "multiple fixtures that make up a logical rube fixture" are centered on the body they are attached to - easy. I draw my sprite at the body position.

Image

when the fixture is offset from the body is the Q : how at runtime do I calculate the equivalent position since all I have are n fixtures with no logical center. Are you saying I must use a placeholder image in the scene?

Image

Sorry if you're tearing your hair out! But hopefully this attempt clarifies the Q for the last time.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Drawing bodies and fixtures

Post by iforce2d »

Yes. Place an image in RUBE, as you showed in the screenshot in your first post (I have been assuming from the start that you were using that as a placeholder). That will let you set the size of it, make the physics shape to roughly match the picture, attach it to a body etc. After loading the scene in your game, the placeholder image itself can be ditched once you have read the position and angle from it. Then draw the frames of the animation at the placeholder location. The method for calculating the position to draw the image is done as I explained a few posts ago.

As for "querying" the placeholder image each render loop, I don't really know what you mean. When you load the scene, you will need to grab any information you want to use from the placeholder before destroying it, eg. which body it is attached to, the position and angle within that body, the size etc. but that is only done once.

No, you don't calculate an offset, you use the offset that is in the exported .json file output by RUBE. That's kinda the point of having a graphical tool to manipulate things visually.

You don't need any information whatsoever about fixtures to draw images. You can quite happily have a body with an image attached, that doesn't even have any fixtures at all. You could make a scene with 1000 images and zero fixtures and draw it just fine. The only reason I'm mentioning fixtures still is because you keep bringing it up :D
rileyrg
Posts: 54
Joined: Sun Jul 19, 2015 11:42 am

Re: Drawing bodies and fixtures

Post by rileyrg »

My bodies have multiple fixtures each of which need a separate in game sprite. So it seems at the end of the day we're just about there. Use an image placeholder . This I kind of grasped in my second reply

"Aha ! Wait. I think I have it. What you're saying is I *should* attach an image and position it over the fixture in order to then read that at load time and get the relative position to the body center. Even if I dont actually use the same image in game. And I need to do that because the "virtual" fixture we see in rube isn't there at rube loader time. I need to query the images and find it by name and then store its position to get the fixture position thats really modelled by more than one polygon shape in any complex fixture shape."

So thanks for bearing with me! It's all new to me ;)
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Drawing bodies and fixtures

Post by iforce2d »

What you're saying is I *should* attach an image and position it over the fixture in order to then read that at load time and get the relative position to the body center. Even if I dont actually use the same image in game.
Yes, that's exactly right.
And I need to do that because the "virtual" fixture we see in rube isn't there at rube loader time.
No, as we have already discussed, fixtures have absolutely nothing to do with it. The reason you need to get the image position relative to the body, is so you know where the image should be drawn in the scene.
I need to query the images and find it by name and then store its position...
Yes...
... to get the fixture position thats really modelled by more than one polygon shape in any complex fixture shape
... no :)
rileyrg
Posts: 54
Joined: Sun Jul 19, 2015 11:42 am

Re: Drawing bodies and fixtures

Post by rileyrg »

iforce2d wrote:
What you're saying is I *should* attach an image and position it over the fixture in order to then read that at load time and get the relative position to the body center. Even if I dont actually use the same image in game.
Yes, that's exactly right.
And I need to do that because the "virtual" fixture we see in rube isn't there at rube loader time.
No, as we have already discussed, fixtures have absolutely nothing to do with it. The reason you need to get the image position relative to the body, is so you know where the image should be drawn in the scene.
I need to query the images and find it by name and then store its position...
Yes...
... to get the fixture position thats really modelled by more than one polygon shape in any complex fixture shape
... no :)
Its down to language I think.. Having just read this reply I'm sure its a "yes" :) Thanks for your time and patience. Its probably down to my use of "virtual fixture" not being clear. I know what I mean and youve helped me a lot - bottom line : use images to get position even though I dont want them in my game engine.
rileyrg
Posts: 54
Joined: Sun Jul 19, 2015 11:42 am

Re: Drawing bodies and fixtures

Post by rileyrg »

iforce2d wrote:The problem from my point of view is that the question you're asking doesn't seem to match the overall goal.

Yes, the image you place in RUBE would be a placeholder. That is where you will draw the frames of the animated texture right? Presumably the image you are placing there in RUBE is one frame of the animation?

Perhaps taking a step back for a bit, we could define the overall goal more clearly. This is what I'm understanding it to be, correct me where I've gone wrong:
1. We want to draw animation frames at the object position, which move along with the object
2. Animation frames are a rectangular texture which has a position and angle relative to the body
3. The position and angle of the texture relative to its body are defined by the placeholder image in RUBE
4. All frames of the animation will be the same size.

So when loading the scene, we need to look at the position and angle of the placeholder image relative to its body. To render the final result, we need to render whatever frame of the animation is current, at the placeholder position, and use the current body position and angle to transform it into the right place. Nothing in this process requires knowing anything at all about fixtures...

If you really do need to know where every vertex of a fixture is, as I said the best way would be to look at how libgdx is rendering the debug draw. But even if you did know the positions of all the vertices - I don't understand how you could use them to position a texture.
For the latecomer, this is the best and most concise description that explains the issue and solution. Thanks to Chris for his patience. A wonderful editor.
Post Reply