Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


Finalspace

Member Since 29 Mar 2012
Offline Last Active Aug 28 2015 07:28 AM

Posts I've Made

In Topic: Collision Detection techniques.

28 August 2015 - 07:32 AM

There is a much simpler solution for that - in case you have hard edges:

 

You just trace all the contours in your level sprite, build up the edges and the create chained line segments out of it.

Also you can create polygons out of that edges, but you must convert non-convex polygons to convex polygons!

The theory behind is really simple, but implementation is not that easy - just google for contour tracing.


In Topic: How to revert the scale of a matrix?

18 August 2015 - 06:53 AM

It depends. In general you cannot reconstruct the history how the one available matrix was generated from the matrix alone. You can just decompose the matrix into an equivalent translational and scaling transform (letting rotation aside as mentioned in the OP), replacing the transform of interest with its desired substitute, and re-compose, so that the translational part is not effected. But if the composition was done so that the position was effected by a scaling (as e.g. in S1 * T * S2), then you cannot eliminate scaling totally (AFAIK).

 

So in your case decomposition is relatively easy, because in a homogeneous 3x3 matrix without rotation there is an embedded 2x2 matrix that is effected by scaling only but not by translation. You get this sub-matrix if you strip the row and the column where in the 3x3 matrix the homogenous "1" is located. The resulting sub-matrix must be a diagonal matrix, e.g. only the values at [0][0] and [1][1] differ from zero. Those both values are in fact the scaling factors along x and y axis directions, resp. Hence setting both these values to 1 will do the trick.

 

 

I already decompose the matrix like this:

sx = transform.m[0 * 3 + 0];
sy = transform.m[1 * 3 + 1];
tx = transform.m[0 * 3 + 2];
ty = transform.m[1 * 3 + 2];

And use this to transform my position/vertices manually:

posX = pos.x * sx + tx;
posY = pos.y * sy + ty;

The inverse matrix wont help me at all, isnt it?


In Topic: Velocity and deltatime confusion

13 August 2015 - 04:00 AM

Its easier to think in a way how integration works.

 

We use the acceleration - which is defined in m/s² to integrate into velocity.

We use velocity - which is defined as m/s to integrate into position.

Position is just a distance (m) from the origin.

 

Therefore if we look at one frame in our game (typical 1/60 of a second) then we need to integrate our "delta-time" which is normally 1.0 / 60.0 into all the integration equations - otherwise your acceleration, velocity and position is getting 60 times faster than it should be.

 

When you do collision detection, the velocity is already integrated so that it contains only the acceleration for one frame - so you dont have to put the delta time again.

 

- Integrate with delta time

 

vel += acc * dt;

pos += vel * dt;

 

- Solve collisions without delta time:

 

vel += -(1.0 + restitution) * relative velocity along normal * normal

 

The only way you need delta time again is when you want to use the distance in velocity - then you need to divide it by the delta time - to convert it into m/s.


In Topic: I already have a game, but I want to make a new engine from scratch for it. T...

17 May 2015 - 01:26 AM

TheBennyBox is a great source for engine development - but only for the 3D Stuff:

https://www.youtube.com/user/thebennybox

 

Also there is a book called "Game Engine Archtecture" from one of the uncharted developers which is really good. But i give you fairly good warning: This book is high-level and is not suitable for beginners!

http://www.amazon.com/Engine-Architecture-Second-Jason-Gregory/dp/1466560010/ref=sr_1_1?ie=UTF8&qid=1431847590&sr=8-1&keywords=game+engine+architecture


In Topic: Impulse based physics issues with mass

16 May 2015 - 04:01 AM

Oh boy, after looking into the jitter physics source, i somehow know how this works and what i need to todo:

 

- First off, you need to cache contacts - so you can have access to previous contacts (I know this concept, but have never implemented it yet).

- You calculate a bias for restitution including penetration correction - like box2d lite ish...

- When contacts are speculative (no penetration) you store this bias in the contact for the next frame (lost speculative bounce).

- Then before calculating the bias for restitutuion at the start of the frame, you read it directly from the last contact (lost speculative bounce).

- You use a sequential impulse method, but also adding the speculative velocity (penetration / dt) in the impulse term

 

Looks like its a mix of sequential impulse and speculative contacts...

 

The only thing which bugs me is that penetration is reversed, so positive penetration are "penetration" and negative penetration is separation.

 

Here are the relevant source parts from the jitter contact class:

restitutionBias = lostSpeculativeBounce;

speculativeVelocity = 0.0f;

float relNormalVel = normal.X * dvx + normal.Y * dvy + normal.Z * dvz; //JVector.Dot(ref normal, ref dv);

if (Penetration > settings.allowedPenetration)
{
	restitutionBias = settings.bias * (1.0f / timestep) * JMath.Max(0.0f, Penetration - settings.allowedPenetration);
	restitutionBias = JMath.Clamp(restitutionBias, 0.0f, settings.maximumBias);
}

// Simultaneos solving and restitution is simply not possible
// so fake it a bit by just applying restitution impulse when there
// is a new contact.
if (relNormalVel < -1.0f && newContact)
{
	restitutionBias = Math.Max(-restitution * relNormalVel, restitutionBias);
}

// Speculative Contacts!
// if the penetration is negative (which means the bodies are not already in contact, but they will
// be in the future) we store the current bounce bias in the variable 'lostSpeculativeBounce'
// and apply it the next frame, when the speculative contact was already solved.
if (penetration < -settings.allowedPenetration)
{
	speculativeVelocity = penetration / timestep;

	lostSpeculativeBounce = restitutionBias;
	restitutionBias = 0.0f;
}
else
{
	lostSpeculativeBounce = 0.0f;
}


PARTNERS