• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Collins1987

Rotation of a Bounding Box around a point that is not the objects centre

11 posts in this topic

hey,

 

Ive been trying to work out how to rotate a bounding box about a position that is not the objects centre and perform collisions based on SAT Collision Dectection. I have the collisions working but i cannot figure out how to rotate the bounding box into the right location as all I seem to be able to manage is to rotate the bounding box around the objects centre position.

 

This is what i have so far:

 

        float Rot = Entity.getRotation();
	D3DXVECTOR2 pos = D3DXVECTOR2(Entity.getPosition().x,Entity.getPosition().y);
	Centre = Entity.getCentre() + pos;	

	D3DXVECTOR2 X(cosf(Rot), sinf(Rot));
	D3DXVECTOR2 Y(-sinf(Rot), cosf(Rot));

	X *= Entity.getWidth()/2;
	Y *= Entity.getHeight()/2;

	Corner[0] = (Centre - X) - Y;
	Corner[1] = (Centre + X) - Y;
	Corner[2] = (Centre + X) + Y;
	Corner[3] = (Centre - X) + Y;

This code rotates about the objects centre position but i cant mange to rotate about a position say 15 pixels in the positive X direction from its own centre.

 

Any Ideas on how I would accomplish this?

0

Share this post


Link to post
Share on other sites

Thanks for that but this is just rotating the box then moving it back to the old position.

 

I am trying to rotate the bounding box so that its is rotated around a point on a fixed circular distance away from the origin and cannot figure out how to rotate the bounding box to the same position around the circle as the object instead of just rotating around the point where the object was before it was rotated around the fixed point. if that makes any sense?

0

Share this post


Link to post
Share on other sites

If you want to do that then what you can is after you rotate the camera around the point you want to rotate then you need move the camera back based on the camera inverse look at direction in local space multiply by the distance factor you want. Hope that helps. Let me give you an example, let's say the camera look at direction is 0,0,1 and you position in on the point and rotate it by let's say 90 degrees clockwise around the Y axis (0,1,0) then your new look at direction for the camera in local space would be now (1,0,0) taking the inverse of that gives you (-1,0,0). Now you can take that inverse and multiply by the distance factor your want, let say it is 5. So we can (-1,0,0)*5 and we now get (-5,0,0). Take the value and add it to the camera position. As you notice i am using an camera as an example, but the same thing applies to your objects, the camera is no different then any of your objects.

Edited by BornToCode
0

Share this post


Link to post
Share on other sites

You where on the right track, its like this:

 

        D3DXVECTOR2 X(Entity.getPosition().x//The point to rotate around//+((Raduis//distance from point//)*(sinf((Rot//In radians//));
        D3DXVECTOR2 Y(Entity.getPosition().Y//The point to rotate around//+((Raduis//distance from point//)*(cosf((Rot//In radians//));
 
it's Trigonometry.
Edited by Scouting Ninja
0

Share this post


Link to post
Share on other sites

have tried using this formula there is two things wrong with it, first you cant set a 2D vector with just one value and second it creates a bounding box that is massive compared to the actual entity. Also when drawing these bounding boxes to check to see if it has worked the size of them changes dependent on the rotation of the parent object? Any ideas how to solve this or what I have done wrong?

D3DXVECTOR3 orientation = Entity.getOrientation();
	float Rot = Entity.getRotation();
	D3DXVECTOR2 pos = D3DXVECTOR2(Entity.getPosition().x,Entity.getPosition().y);
	Centre = Entity.getCentre() + pos;
	

	D3DXVECTOR2 X(Entity.getPosition().x + (168 * (sinf(Rot))), 0);
	D3DXVECTOR2 Y(0, Entity.getPosition().y + (168 * (cosf(Rot))));

	X.x -= Entity.getWidth()/2;
	Y.y -= Entity.getHeight()/2;

	Corner[0] = (Centre - X) - Y;
	Corner[1] = (Centre + X) - Y;
	Corner[2] = (Centre + X) + Y;
	Corner[3] = (Centre - X) + Y;

Where entity Position = 496, 200.

entity centre = 512, 216

rotation point is = 512, 368

0

Share this post


Link to post
Share on other sites

Oh!

Sorry my mistake, my C is a bit rusty.(Using python now)

 

you would use these values in only one vector: D3DXVECTOR2 MID(Entity.getPosition().x + (168 * (sinf(Rot))) ,Entity.getPosition().y + (168 * (cosf(Rot))));

This will be the mid point so then you define the bounding box by adding or subtracting from the mid point:

D3DXVECTOR2 X( D3DXVECTOR2 MID.x + HalfSiseOfBox,D3DXVECTOR2 MID.x - HalfSiseOfBox)

D3DXVECTOR2 Y( D3DXVECTOR2 MID.y + HalfSiseOfBox,D3DXVECTOR2 MID.y - HalfSiseOfBox)

 

See normally if your bounding box's middle is 0 the first X vector would be say +2 and second -2 and the same for Y

+2_______-2 

   |               |

   |      0       |

   |               | 

-2_______+2 Is this correct or are you using a deferent bounding box ?

Sorry I mean this  

__+2__

|     |     |

-2  0   +2

|     |     |

|__-2__|

Edited by Scouting Ninja
0

Share this post


Link to post
Share on other sites

Yes that is the type of bounding box I am using just trying to get it placed in the right location for the collision detection to work. I will give it a try and see what happens

Thanks

0

Share this post


Link to post
Share on other sites

Have tried implementing it this way and its not working still just rotating the bounding boxes into some weird places, would using a matrix transform during drawing of the sprite effect this as directx draws the sprite in the right location but the world only knows the positions without the transform matrix applied to it?

 

should state that im working with Orientated Bounding Boxes opposed to Axis Aligned Bounding Boxes

Edited by Collins1987
0

Share this post


Link to post
Share on other sites

Personally I cant see why it isn't working, the equation is meant to rotate around a point, then it would only mean reassemble the bounding box at that point.

Make sure that your using radians and not degrees for rotation,degrees causes 90 degree jumps.(could be the weird jumping you see)

You could do it for each point of the bounding box, but that could get complicated.

You could always test it first by attempting to rotate a sprite around a point.

You could always search: trig rotating around point.

 

These are the last ideas I can think of with out you sending me the file so I can look at it, if you do get it right please drop a comment here showing how you did it,I am curios now.

1

Share this post


Link to post
Share on other sites

Ive figured it out really was quite simple to be honest.

 

involved adding the radius of the circle to be rotated around to the objects position, then when the object had been rotated working out the objects current orientation

and multiplying that by the radius offset and taking it from the position before adding it the rotated corners.

 

Here's the code that is being used:

D3DXVECTOR2 X(cosf(Rot), sinf(Rot));
	D3DXVECTOR2 Y(-sinf(Rot), cosf(Rot));

	X *= halfWidth/2;
	Y *= halfHeight/2;

	Corner[0] = Centre - X - Y;
	Corner[1] = Centre + X - Y;
	Corner[2] = Centre + X + Y;
	Corner[3] = Centre - X + Y;

	float offsetX = orientation.x * Offset;
	float offsetY = orientation.y * Offset;

	D3DXVECTOR2 offset(offsetX, offsetY);

	pos -= offset;

	Corner[0] += pos;
	Corner[1] += pos;
	Corner[2] += pos;
	Corner[3] += pos;

	Centre += pos;

Thanks for all the help! Wouldn't have made it without the pointers in the write direction!

1

Share this post


Link to post
Share on other sites

Good work!

 

I see,you multiply the offset after calculating the rotation point and then subtract it from the position.

This will definitely be a useful piece of code thanks!

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0