• 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
Volgogradetzzz

Box2DLite porting. Questions.

11 posts in this topic

Hello. I'm trying to port famous Box2DLite to AS3.0 (yeah, I know that AS3 version of Box2D exists, but I need to port it myself to pump my physics skill) and there're some question. First of all - I don't know C++ (but can read it a little) and thats main reason that my ported version works incorrectly. If you don't mind, I'll post my questions here and I hope you'll help a little ).
#1. There're strange construction in Arbiter constructor:
[code]Arbiter::Arbiter(Body* b1, Body* b2)
{
if (b1 < b2)
{
body1 = b1;
body2 = b2;
}
else
{
body1 = b2;
body2 = b1;
}
...
}[/code]
And there;re no overloading '<' operator in Body class. So what does it mean and why are we need such check?
0

Share this post


Link to post
Share on other sites
In this case, operator<() simply sorts based on pointer values. Without looking at the source code I can't tell you exactly what the context is, but one reason you might do this would be to facilitate easy comparison of Arbiter objects (assuming that b1, b2 and b2, b1 should be considered to be the same pair).

Whatever the reason for the sorting is, you should be able to determine it by looking at the code for the Arbiter class in its entirety. (Most likely there's an operator or other function somewhere in the class that relies on the two bodies being in a pre-determined order.)
0

Share this post


Link to post
Share on other sites
Thanks, jyk. I think I understand now. There is map<ArbiterKey, Arbiter> and later there is search in this map by ArbiterKey. So I think that's the reason.
0

Share this post


Link to post
Share on other sites
As far as I remember Box2D the sorting there is only to add some consistency such that the same pair of bodies is always processed in the "same order". This could be done by assigning id to the bodies and sorting by that or just sort by the pointers since they are unique too... Basically, he just wants and arbitrary order so he might as well use the pointers.
0

Share this post


Link to post
Share on other sites
If you do the port for learning purposes I strongly encourage you do this. On the other site Erin mentioned yesterday that some people took Adobe Alchemy to port Box2D to flash and it gave very good performance. So if you want to use Box2D just in Flash this might be a much easier route to go.

[url="http://labs.adobe.com/technologies/alchemy/"]http://labs.adobe.co...logies/alchemy/[/url]
0

Share this post


Link to post
Share on other sites
japro, thanks. Dirk, yeah, it's purely for learning - I want to understand every line of code.
Next question:
#2. There's Collide class and there's collide() method that contains:
[code]var RotA:Matrix22 = new Matrix22(bodyA.rotation);//creates current rotation matrices
var RotB:Matrix22 = new Matrix22(bodyB.rotation);

var RotAT:Matrix22 = RotA.transpose();//inverse of rotation matrices
var RotBT:Matrix22 = RotB.transpose();

var dp:Vector2 = posB.subtract(posA);//dist between bodies

var dA:Vector2 = RotAT.multiplyByVector(dp);//converts dist between bodies to local frame of each body
var dB:Vector2 = RotBT.multiplyByVector(dp);

//this I can't understand - what is C and what is absolute and why we need it??? (In code abs - converts all entries of vector/matrix to positive values)
var C:Matrix22 = RotAT.multiplyByMatrix(RotB);
var absC:Matrix22 = C.absolute();
var absCT:Matrix22 = absC.transpose();

// Box A faces
var faceA:Vector2 = dA.absolute().subtract(hA).subtract(absC.multiplyByVector(hB));
if (faceA.x > 0 || faceA.y > 0) return 0;

// Box B faces
var faceB:Vector2 = dB.absolute().subtract(absCT.multiplyByVector(hA)).subtract(hB);
if (faceB.x > 0 || faceB.y > 0) return 0;[/code]
There's comment about absolute matrix - what is this and why?
0

Share this post


Link to post
Share on other sites
C represents the coordinate frame of one of the boxes expressed with respect to the coordinate frame of the other. absolute() probably returns the matrix with all elements set to their absolute values.

The code in question implements the separating axis test (SAT) for two boxes. The SAT for boxes typically involves computing the absolute values of the dot products of pairs of box axes (one from the first box and one from the second), and it looks like that's what absC represents here.
0

Share this post


Link to post
Share on other sites
Thanks jyk, but I know SAT a little and this code definitely not SAT - there's no axes at all - there's some sort of projections. But how are they work - for example this line:
[code]absC.multiplyByVector(hB)//here hB - is a distance from bodys center to vertex.[/code]
What does it do? It's not rotation - but what is it?
0

Share this post


Link to post
Share on other sites
[quote name='Volgogradetzzz' timestamp='1303466359' post='4801553']
this code definitely not SAT[/quote]
Are you sure? :)

Have you considered the possibility that it is the SAT, but expressed in a form you're not accustomed to?

(Disclaimer: I'm fairly certain it is in fact the SAT, but to be completely certain I'd need to see the function in its entirety, and would probably need to work through it to make sure it's doing what I think it's doing.)
0

Share this post


Link to post
Share on other sites
Ok, jyk. I'll agree that maybe it's sat - but not in usual form that I see before. And post #6 is entire function, i.e. it's enougth to check penetration.
0

Share this post


Link to post
Share on other sites
Hello again!
At last i'm getting close to soul of Box2D - famous Sequential Impulses. I've read Catto's presentations, investigate code, but anyway it's hard to understand the purpose of such technique. Using this sequential impulses he reduces final impulse applied to body. But why? isn't it cheaper to manually decrease it than recalculate it in loop. Also there no bounce at all - i.e. collisions fully inelastic. I added some restitution and immidiatelly get jittering. So what the profit of sequential impulses???
0

Share this post


Link to post
Share on other sites
Seqential Impulses are verz easy to implement and give very good results. There are some tricks like slobs and warmstarting. You can look into the ODE and check their iterative Projected Gauss-Seidel and even the direkt Dantzig solver. Let me know what you find easier to implement :)

You have to be careful with restitution. If the relative velocity falls below some threshold ( roughly 1-2 m/s ) you use the usual bias. Otherwise you get jitter. So this is a problem of your implementation and not sequential impulses :)
1

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