axes of coordinates R.U.B.E to box2d sdl2

General discussion about the R.U.B.E editor
Post Reply
FLYNSXCOOL
Posts: 25
Joined: Tue Sep 19, 2017 4:30 pm

axes of coordinates R.U.B.E to box2d sdl2

Post by FLYNSXCOOL » Thu Oct 05, 2017 5:38 pm

Безымянный.png
Безымянный.png (13.5 KiB) Viewed 18247 times
Screenshot_1.png
Screenshot_1.png (88.45 KiB) Viewed 18251 times
Screenshot_2.png
Screenshot_2.png (17.03 KiB) Viewed 18251 times

How to adjust the program to the correct axes ??? I Have to do the FLIP for proper display and placement of the object in the game

iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Re: axes of coordinates R.U.B.E to box2d sdl2

Post by iforce2d » Fri Oct 06, 2017 9:12 am

Have you looked at the example SDL2 loader? Maybe it will help:
https://www.iforce2d.net/rube/?panel=loaders

These threads may also be relevant:
viewtopic.php?f=6&t=542
viewtopic.php?f=6&t=291
viewtopic.php?f=6&t=49

FLYNSXCOOL
Posts: 25
Joined: Tue Sep 19, 2017 4:30 pm

Re: axes of coordinates R.U.B.E to box2d sdl2

Post by FLYNSXCOOL » Fri Oct 06, 2017 4:32 pm

1) will I need to make the likeness as in the example?
2) did the example contains ready b2dJson ??
3) I took here https://github.com/iforce2d/b2dJson for C++, maybe I need to change some file and not try to move from rube-C++-sample-SDL2 in my project. What do you think about this?

iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Re: axes of coordinates R.U.B.E to box2d sdl2

Post by iforce2d » Sat Oct 07, 2017 5:43 pm

1. No.
2. Yes of course, that is the whole point of having an example.
3. I would start with the example and work from there. Or at least, take a look at how the example does things and maybe you can modify your existing code a little.

FLYNSXCOOL
Posts: 25
Joined: Tue Sep 19, 2017 4:30 pm

Re: axes of coordinates R.U.B.E to box2d sdl2

Post by FLYNSXCOOL » Sun Oct 08, 2017 6:58 am

In an example rube-C++-sample-SDL2:

Code: Select all

b2World* World;
World= car.readFromFile("car.json", errorMsg);
if i try to creat another object:

Code: Select all

b2Body		        *body;
b2BodyDef		bdefw;
b2FixtureDef	        fdef;
b2PolygonShape	rectb;

          bdefw.angle = (float) (angl*M_PI/180);
          bdefw.position.Set((float32) x/SCALE, (float32) y/SCALE);
          rectb.SetAsBox((float32) w * 0.5 / SCALE, (float32) (h * 0.5 / SCALE));
          body = World->CreateBody(&bdefw);
          fdef.shape = &rectb;
	  fdef.friction = 0.0f;
          body->CreateFixture(&fdef);
          body = World->CreateBody(&bdefw);

It is to make ERROR in b2BlockAllocator.cpp:

line 112

Code: Select all

if (m_freeLists[index])
	{
		b2Block* block = m_freeLists[index];
		m_freeLists[index] = block->next;
		return block;
	}

I think that i must do all objects in one *.json file like LEVEL... but it isn't good idea.

FLYNSXCOOL
Posts: 25
Joined: Tue Sep 19, 2017 4:30 pm

Re: axes of coordinates R.U.B.E to box2d sdl2

Post by FLYNSXCOOL » Sun Oct 08, 2017 11:58 am

I try loader from rube-C++-sample-SDL2

and got:
Screenshot_1.png
Screenshot_1.png (81.01 KiB) Viewed 18229 times

I dont use b2dJsonImage_SDL2 ( SDL_Rect texr; texr.w = (int)(w * aspectScale * s * (flip?-1.0f:1.0f));), I have made exactly the same (use setScale(-1, -1);) for image

But I have not found in rube-C++-sample-SDL2 how to deploy all of the body


summing up..
1) loader from rube-C++-sample-SDL2 - i must do all objects in one *.json file like LEVEL.. and i cant throw new object to world.

rube-C++-sample-SDL2 code have flip for image and i can rotate body to 180 for normal position.

2) https://github.com/iforce2d/b2dJson for C++ - i can load level and i can load to level new objects but this code havent flip for image and i must similarly rotate body to 180 for normal position.
............................................

I understand how to deploy an one object (one сentral body) but do not understand how to deploy the entire level, relative to the centre (0,0) of the axes.

FLYNSXCOOL
Posts: 25
Joined: Tue Sep 19, 2017 4:30 pm

Re: axes of coordinates R.U.B.E to box2d sdl2

Post by FLYNSXCOOL » Mon Oct 09, 2017 3:12 am

No rotate... Need flip body, how it do

iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Re: axes of coordinates R.U.B.E to box2d sdl2

Post by iforce2d » Tue Oct 10, 2017 11:28 am

What line of that code causes the b2BlockAllocator crash? Is it the World->CreateBody line? Is the World variable valid?

The recommended method for merging multiple RUBE scenes into one world at runtime is shown on the main b2dJson page: http://www.iforce2d.net/b2djson/#merging

I don't understand what you mean in your point number 2. Are you saying that the SDL2 example is displaying things flipped the wrong way for you?

I would recommend that your level is created relative to 0,0 so that it does not need to be moved. Load the level first. Then when you load each object into the world, move the objects as necessary. To move them, all bodies in the incoming object must be moved. Eg. https://www.iforce2d.net/forums/viewtopic.php?f=6&t=379

FLYNSXCOOL
Posts: 25
Joined: Tue Sep 19, 2017 4:30 pm

Re: axes of coordinates R.U.B.E to box2d sdl2

Post by FLYNSXCOOL » Thu Oct 12, 2017 3:57 pm

I came out of the situation by making two versions of the body. One body, one facing left, another body is facing right, then turn them 180 ° and use loader json for C++, not SDL

and 2 question - answer - viewtopic.php?f=6&t=176

FLYNSXCOOL
Posts: 25
Joined: Tue Sep 19, 2017 4:30 pm

Re: axes of coordinates R.U.B.E to box2d sdl2

Post by FLYNSXCOOL » Thu Oct 12, 2017 5:12 pm

BUT that would load the level will have to rotate them upside-down in the program R. U. B. E and turn on the X-axis

Post Reply