Heres what i have a 2D rect that defines movable area, and set of 2D rects that define obstacles Now i would like to find a safe passage from point A to B.

I can't pit that into 2D grid, its a math problem i either use points or planes to define obstacles.

Any references or ideas?

]]>

AABB.cpp

int AABB::supportFaceCount() { // there are only three directions for every face of an AABB box. return 3; } XMVECTOR AABB::supportFaceDirection(int i) { // the three axes of an AABB box. along the x, y and z axis. static const XMVECTOR s_aabbAxes[] = { XMVectorSet(1, 0, 0, 0), XMVectorSet(0, 1, 0, 0), XMVectorSet(0, 0, 1, 0) }; return s_aabbAxes[i]; } int AABB::supportEdgeCount() { // there are only three directions for every edges of an AABB box. return 3; } XMVECTOR AABB::supportEdgeDirection(int i) { // every edge go along the x y, or z axis. static const XMVECTOR s_aabbEdges[] = { XMVectorSet(1, 0, 0, 0), XMVectorSet(0, 1, 0, 0), XMVectorSet(0, 0, 1, 0) }; return s_aabbEdges[i]; } void AABB::supportInterval(XMVECTOR direction, float& min, float& max) { XMVECTOR centre = XMVectorSet(Center[0], Center[1], Center[2], 1); // projection of the box centre float p = XMVector3Dot(centre, direction).m128_f32[0]; // projection of the box extents float rx = fabs(direction.m128_f32[0]) * Radius[0]; float ry = fabs(direction.m128_f32[1]) * Radius[1]; float rz = fabs(direction.m128_f32[2]) * Radius[2]; // the projection interval along the direction. float rb = rx + ry + rz; min = p - rb; max = p + rb; }

bool ObjectsSeparatedAlongDirection(XMVECTOR& direction, AABB* a, AABB* b) { float mina, maxa; float minb, maxb; a->supportInterval(direction, mina, maxa); b->supportInterval(direction, minb, maxb); return (mina > maxb || minb > maxa); } bool ObjectsIntersected(AABB* a, AABB* b) { // test faces of A for(int i = 0; i < a->supportFaceCount(); i++) { XMVECTOR direction = a->supportFaceDirection(i); if(ObjectsSeparatedAlongDirection(direction, a, b)) return false; } // test faces of B for(int i = 0; i < b->supportFaceCount(); i++) { XMVECTOR direction = b->supportFaceDirection(i); if(ObjectsSeparatedAlongDirection(direction, a, b)) return false; } // test cross product of edges of A against edges of B. for(int i = 0; i < a->supportEdgeCount(); i++) { XMVECTOR edge_a = a->supportEdgeDirection(i); for(int j = 0; j < b->supportEdgeCount(); j++) { XMVECTOR edge_b = b->supportEdgeDirection(j); XMVECTOR direction = XMVector3Cross(edge_a, edge_b); if(ObjectsSeparatedAlongDirection(direction, a, b)) return false; } } return true; }

]]>

I'm in process of implementing the SAT for OBB-OBB test and the detection part is working fine and all that i'm missing is collision normal. Tried few options but it never works perfectly (comparing it with Unity's).

I'd appreciate any kind of input on that matter. Thanks

]]>Some additional info, I am making the game in javascript (web browser) and dont plan on using any physics related engines or libraries. Also my first interests (as a starting point) for development lie in managing water vs oxygen vs immobile material in terms of gravity, weight, flow and pressure, both individually and against each other. The game will naturally use a basic 2D block/grid system similar to what you would see in a game like oxygen not included.

If a voice chat not going to be so practical, then here are some of my starting questions:

Water has weight and is therefore pulled down by gravity, I know this. I have also heard that water does not compress well, so I probably don't have to worry about deeper water having a higher density due to large amounts of water weight above it. So assuming some constant or formula for gravity and water weight, if you have one tile filled with water, and nothing underneath it, it all falls straight down (not caring much about atmospheric interference). But if you have solid mass underneath, then the water should probably fill tiles to the sides instead. Im guessing a good way of doing this will be to multiply your chosen flow rate by the difference between the fuller tile and the more empty tile or something like that in order to calculate change over time?

There should probably also be something else at play here, as the liquid tile falling straight down would be very fast surely vs the 'flowing' into a neighboring tile or am I wrong?

Another consideration is how do you handle the concept whereby I believe the water would flow downwards (gravity) first before attempting to flow to neighboring tiles (or am I just being naive here)?

Also does gas or high pressure gas have any noticeable effect on any of the 'flow rates'?

]]>

I have begun using quaternions in my game code, as my game logic occurs in 3D space. My rendering, however, is done with sprites. So I use swing-twist decomposition to get the component of the quaternion in the Z-Axis, and the sprite rotates appropriately. So far, so good.

However, when I have a parented transform, it appears the quaternions act a bit strangely. I was under the impression that I could, from the accumulated world rotation, perform the swing-twist decomposition as normal, and apply the relative rotation to set my world rotation to this value for rendering. This did not work as planned. So I investigated, and found something that seems to be rather distressing.

As a test, I set my child quaternion to the conjugate of the parent (all quaternions are unit length). You would expect that this would result in no rotation at all. It does not. In fact, as far as I could tell, there seemed to be little change at all. I checked the quaternion multiplication; I get the identity quaternion, so that checks out. It appears that when I apply it to the world transformation calculation something is lost, but I don't know what. The calculation of the matrix is as follows (using the conjugate as the child rotation):

glm::mat4 childTransform = glm::translate(parentPosition) * glm::mat4_cast(parentRotation) * glm::scale(parentScale) * glm::translate(childPosition) * glm::mat4_cast(glm::conjugate(parentPosition)) * glm::scale(childScale) * glm::translate(glm::vec3(-.5f, -.5f, 0));

Nothing seems wrong here in terms of matrix multiplication order. The position and scale are correct, but its not cancelling out the rotation as planned.

So I guess the questions are as follows:

- Why does inverting the parent quaternion in the child not cancel out the rotation?
- Is this actually the best means of accomplishing my goal of extracting the rotation on the Z-axis? Perhaps I am missing a more obvious solution to this issue.

Thank you very much for your help.

]]>I've been absolutely fascinated by Noita trailers, and gameplay videos.

Their pitch is that every single pixel is simulated. How does it work exactly?

I'm trying to take another game as example, let's say Oxygen Not Included, tiles have properties such as material, temperature, quality of air, pressure, etc...

It's actually very easy to understand how to model these kind of data. It can just be a massive grid, each element of that grid is a tile, tiles are regrouped by chunks. A chunk getting a change would be set to dirty, then get reupdated, etc... Of course it's not easy to make, but it's easy to understand,

Now what about Noita? Could it be the same way to model the environment, but at the level of a pixel instead of a tile? Would that not be way too costly?

Just trying to wrap my head around the concept...

]]>

I have rough dimensions of a cube. I have XYZ coordinates for the cube (I don't know where in the cube these coordinates originate--I just need a ballpark answer). I am drawing objects around the cube. Of course I have coordinates for each object being drawn. How can I tell if an object would be placed within the cube?

I've been looking at (i.e. Googling) math to determine if a point intersects a line, but that's way too specific. I need to know if a point (XYZ coordinate) will be placed within the dimensions of a cube.

I hope I'm being clear. Let me know what other info you need if you think it can be done.

Thanks

]]>AABB::AABB(XMFLOAT3 c, XMFLOAT3 r) { Center[0] = c.x; Center[1] = c.y; Center[2] = c.z; Radius[0] = r.x; Radius[1] = r.y; Radius[2] = r.z; } void AABB::UpdateAABB(float orientation[3][3], float translation[3]) { float C[3], R[3]; for (int i=0; i<3; i++) { C[i] = translation[i]; R[i] = 0.0f; for (int j=0; j<3; j++) { C[i] += orientation[i][j] * Center[j]; R[i] += abs(orientation[i][j]) * Radius[j]; } } Center[0] = C[0]; Center[1] = C[1]; Center[2] = C[2]; Radius[0] = R[0]; Radius[1] = R[1]; Radius[2] = R[2]; } XMFLOAT3 AABB::GetCenter() { return XMFLOAT3(Center[0], Center[1],Center[2]); } XMFLOAT3 AABB::GetRadius() { return XMFLOAT3(Radius[0], Radius[1],Radius[2]); }

]]>

Rigidbody.cpp XMVECTOR RigidBody::GetVelocityAtPoint(XMVECTOR p) { return (v + XMVector3Cross(Omega, (p - x))); } XMMATRIX RigidBody::GetIInverse() { return IInverse; } ...... CollisionResponse.cpp enum CollidingType { None = -1, MoveAway = 0, Resting = 1, Collide = 2 }; struct Contact { RigidBody *a, *b; XMVECTOR p, n; }; CollidingType VerifyTypeOfColliding(Contact *c) { XMVECTOR padot = c->a->GetVelocityAtPoint(c->p); XMVECTOR pbdot = c->b->GetVelocityAtPoint(c->p); XMVECTOR vrel = XMVector3Dot(c->n, (padot - pbdot)); if (vrel.m128_f32[0] > 0) return MoveAway; else if (vrel.m128_f32[0] == 0) return Resting; else if (vrel.m128_f32[0] < 0) return Collide; return None; } void CollisionResponse(Contact *c, float epsilon) { XMVECTOR padot = c->a->GetVelocityAtPoint(c->p); XMVECTOR pbdot = c->b->GetVelocityAtPoint(c->p); XMVECTOR n = c->n; XMVECTOR ra = (c->p - c->a->GetPosition()); XMVECTOR rb = (c->p - c->b->GetPosition()); XMVECTOR vrel = XMVector3Dot(c->n, (padot - pbdot)); float numerator = (-(1 + epsilon)*vrel.m128_f32[0]); float term1 = (1 / c->a->GetMass()); float term2 = (1 / c->b->GetMass()); XMVECTOR term3 = XMVector3Dot(c->n, XMVector3Cross(XMVector4Transform(XMVector3Cross(ra, n), c->a->GetIInverse()), ra)); XMVECTOR term4 = XMVector3Dot(c->n, XMVector3Cross(XMVector4Transform(XMVector3Cross(rb, n), c->b->GetIInverse()), rb)); float j = (numerator / (term1 + term2 + term3.m128_f32[0] + term4.m128_f32[0])); XMVECTOR f = (j*n); c->a->AddForce(f); c->b->AddForce(-f); c->a->AddTorque(XMVector3Cross(ra, f)); c->b->AddTorque(-XMVector3Cross(rb, f)); } ..... Collision Detection // BS - BoundingSphere class & Plane- Normal Plane class bool SpherePlaneIntersection(BS *CricketBall, Plane *CricketGround, Contact *c) { float dist = XMVector3Dot(XMLoadFloat3(&CricketBall->GetCenter()), XMLoadFloat3(&CricketGround->GetNormal())).m128_f32[0] - CricketGround->GetOffset(); c->a = rbBall; c->b = rbGround; if ((dist) <= CricketBall->GetRadius()) { c->n = XMLoadFloat3(&CricketGround->GetNormal()); c->p = XMLoadFloat3(&CricketBall->GetCenter()) - dist * XMLoadFloat3(&CricketGround->GetNormal()); return true; } else return false; return false; } ..... In the Rendering loop code Contact CBwithCG; if (SpherePlaneIntersection(cdBall, cdGround, &CBwithCG)) { if (VerifyTypeOfColliding(&CBwithCG) == Resting) { rbBall->AddForce(XMVectorSet(0, CB_Mass*g, 0, 0)); } else if (VerifyTypeOfColliding(&CBwithCG) == Collide) { CollisionResponse(&CBwithCG, .5f); } } else rbBall->AddForce(XMVectorSet(0, -CB_Mass*g, 0, 0));

]]>

Hello all,

I am trying to workout how a pallet jack (esentially a tricycle) would travel. I'm looking at top-down 2D here.

My current setup is that I have a handle fixed to a point on the jack body, with an angle independent of the jacks body. The jack body then has an angle, and as the jack moves forward (as in you pull the jack along), it's angle would converge by some constant on the handle angle. When pushing the pallet jack it would instead diverge by some constant until the handle hits some maximum angle and then the jack would spin on the spot.

This works OK, but it there are some mistakes. When the handle is 90 degrees from the jack body, it should spin with the center of rotation being exactly between the two fork wheels. Using this method I couldn't figure out how to rotate about the correct spot. I thought about just having edge cases be handled different, but I was hoping someone knew of a better all encompassing solution. Either using friction/drag and other physics concepts, or just using geometry.

I tried using geometry and trigonometry to calculate some circle that the jack should be travelling along but I haven't had any luck.

Am I over complicating this? I'm not search how to search for "physics of pulling an object behind you with drag", so I haven't been able to find any resources.

EDIT: Finally found something on google (now realizing that the same problem applies to 4 wheeled vehicles), I reached this same sort of solution, but I am stuck on how the jack moves along the circle:

Thanks for reading.

]]>Here is a demo video from YouTube.

Does anyone know the techniques behind this snow physics?

For example,

- What is the shading model of the snow?
- How do they create snow deformation?

However, I do want to continue making games as a hobby. I want to be able to learn how to do fairly "fancy" things like create procedurally-generated worlds, and I want to have at least some ability to create AI for monsters and such.

My question is, knowing this, should I see if I can get a waiver for Calculus 1 and 2?

]]>This is about rendering a realistic perspective viewport. I know that matrices and trigonometry are used, from my days doing maths at school, but i’ve never seen the code for DirectX or OpenGL. I have some ideas about how software engineers might do it but I need more information.

First thing I should mention is this geometry, where a square bounds and circle, then a bigger circle bounds that square, and you keep repeating it as shown in the diagram below. If you draw diagonal lines, from the centre, to the corners of the geometry, it looks like you could walk through it, like a realistic corridor. I’m calling each square/circle pair a unit of depth (in to, out of) the scene. If you add a bigger square/circle to the outside, this pushes the far clipping plane further away from the virtual camera.

How is this idea useful for building a code based engine for allowing transformations (move, rotate, scale) to occur? I think if you consider the length from the origin, up to the point at which the next square intersects the circle, and store this value, to build a series, you could use the expression to apply transformations in an efficient way.

I have started working on a table that builds the expression from the bottom up, here is what I have so far.

n (units of depth out of the scene) |
y (square/circle intersection) |
√ (2*(circle minus square) |
expression for y |

6 |
22.14213562373095 |
9.65685424949238 |
4+√8+√32+(4+√32) |

5 |
12.48528137423857 |
5.65685424949238 |
4+√8+√32 |

4 |
6.82842712474619 |
2.82842712474619 |
4+√8 |

3 |
4 |
2 |
4 |

2 |
2 |
0.585786437626905 |
2 |

1 |
1.414213562373095 |
0.414213562373095 |
√2 |

I do it from the bottom up, because the geometry starts in the centre and works outwards. I start with a square who’s length from the origin to the edge is 1, and to calculate the length from the origin to the corner, from pythagorean trig, is √(2*(1^{2})), namely, (two times 1 squared, square rooted), or √2. Then, by subtracting 1 from root 2 (to give you the difference between the square/circle pair), and using the same function, to calculate the length from the corner, to the next corner (outwards), you can add this value onto the value from the previous iteration, to give a new value for the next term in the expression.

Building the expressions up in this way, and having an expression for y, should hopefully help us to figure out an expression for the entire series. I am thinking that this has already been done, by the guys at Microsoft and Silicon Graphics (DirectX, OpenGL), but I need more information because this seems like the most interesting part of computer graphics.

So I guess my question is, can you point me to further resources, or help me find more information about this technique. I was hoping there would be a wikipedia page showing how the technique works, it’s just that I don’t know what it’s called. It seems quadratic to me, but I would love to read about it, and see the code.

I tried to get in touch with Jim Van Verth too, but he hasn’t replied to me yet. Jim worked for Nvidia so he might know exactly how they do it.

Best regards.

—

Steven Wiseman

]]>The problem is that the algorithm only fits "aligned" knots, knots where the tangents have geometric continuity.

This has three input points, the blue curve was fit to them (it's from this demo by the way).

Is there an algorithm that can fit a piecewise cubic bezier curve that can have sharp ("cusp") type knots? On some cases (like those 3 input points) it would make the curve fit the polyline formed by the 3 points perfectly.

Something like this (a mockup):

I want the boat to be able to move pretty freely in terms of yaw, but when it gets bumped I need some kind of damping on the pitch and roll to get it back to a horizontal position. As far as I can see I can read the rotation of the boat (as a 3x3 matrix or quaternion) and I can read and write the angular velocity as an xyz vector (presumably the length denotes the magnitude and the vector direction the axis of rotation in some way).

So I have 2 questions really:

- How would be a good way of achieving this damping to pitch and roll
- To steer the boat (yaw), if I create an angular velocity of e.g. 0, 1, 0, can I just add this to the current angular velocity?

I'm not worried about it being correct in terms of water displacement / buoyancy, just something very cheap and approximate.

]]>Thanks!

]]>

private void SpawnProjectile(int _numberOfProjectiles) { float angleStep = 360f / _numberOfProjectiles; float angle = 0f; for (int i = 0; i <= _numberOfProjectiles - 1; i++) { // Direction calculations. float projectileDirXPosition = startPoint.x + Mathf.Cos((angle * Mathf.PI) / 180) * radius; float projectileDirYPosition = startPoint.y + Mathf.Sin((angle * Mathf.PI) / 180) * radius; // Create vectors. Vector2 projectileVector = new Vector2(projectileDirXPosition, projectileDirYPosition); Vector2 projectileMoveDirection = (projectileVector - startPoint).normalized * projectileSpeed; // Create game objects. GameObject tmpObj = Instantiate(ProjectilePrefab, startPoint, Quaternion.identity); tmpObj.GetComponent<Rigidbody2D>().velocity = new Vector2(projectileMoveDirection.x, projectileMoveDirection.y); // Destory the gameobject after 10 seconds. Destroy(tmpObj, 10F); angle += angleStep; } }

Here's the code i gotten from a github page, I have trouble understanding some things. Regarding the area where Mathf.Cos and Mathf.Sin are, how are they used in calculating the bullet trajectory, from school I know sin x and cos x, which is opposite over hypotenuse and adjacent over hypotenuse, so how are they used in this case to calculate bullet trajectory? Oh and one more, can they be used interchangeably, Cos and Sin in the code, after all since they are evenly distributed it does not matter whether the x position or y position gets the sin or cos value?

]]>

float fAccumulator = 0.0f; while(fAccumulator < fElapsedTime && mRigidBodyObjects.size() > 0) { F32 left_time = fElapsedTime - fAccumulator; for(unsigned int i = 0; i < mRigidBodyObjects.size(); ++i) { int j1 = -1; RigidBodyCollisionResult crFirstCollisionResult; crFirstCollisionResult.fCollisionTime = FLT_MAX; RigidBodyCollisionResult crCollisionResult; for(unsigned int j = 0; j < mStaticObjects.size(); ++j) { crCollisionResult = mRigidBodySolver.Collide(mRigidBodyObjects[i], mStaticObjects[j], left_time); if(crCollisionResult.enCollisionState == WILL_COLLIDE) { if(crCollisionResult.fCollisionTime <= crFirstCollisionResult.fCollisionTime) { crFirstCollisionResult = crCollisionResult; j1 = j; } } else if(crCollisionResult.enCollisionState == HAS_COLLISION || crCollisionResult.enCollisionState == RESTING_CONTACT) { crFirstCollisionResult = crCollisionResult; j1 = j; } } if(crCollisionResult.enCollisionState == WILL_COLLIDE || crCollisionResult.enCollisionState == NO_COLLISION) { mRigidBodyObjects[i]->ApplyGravity(); } if(j1 != -1) { if(crFirstCollisionResult.enCollisionState == WILL_COLLIDE && crFirstCollisionResult.fCollisionTime <= fElapsedTime) { mRigidBodyObjects[i]->Update(crFirstCollisionResult.fCollisionTime); mRigidBodySolver.HandleCollisionReponse(mRigidBodyObjects[i], mStaticObjects[j1], crFirstCollisionResult, crFirstCollisionResult.fCollisionTime); fAccumulator += crFirstCollisionResult.fCollisionTime; } else if(crFirstCollisionResult.enCollisionState == HAS_COLLISION || crFirstCollisionResult.enCollisionState == RESTING_CONTACT) { mRigidBodySolver.HandleCollisionReponse(mRigidBodyObjects[i], mStaticObjects[j1], crFirstCollisionResult, left_time); mRigidBodyObjects[i]->Update(left_time); fAccumulator += left_time; } else { mRigidBodySolver.HandleCollisionReponse(mRigidBodyObjects[i], mStaticObjects[j1], crFirstCollisionResult, left_time); mRigidBodyObjects[i]->Update(left_time); fAccumulator += left_time; } } else { mRigidBodyObjects[i]->Update(left_time); fAccumulator = fElapsedTime; } } }

]]>

What I need to figure out is which direction to turn, so the player has to move the least. What messes me up is the fact that degrees are 0-360. Anything that dosen't have to go past the 0/360 point works fine.

My variables are the current rotation, and the wanted rotation. Any ideas? Thanks

]]>I've seen this video mentioned in many places and it's indeed very interesting, so I went on and tried to implement it myself.

First, with the car suspensions. The guy doesn't mention the damper (a notion that I haven't quite grasped yet btw), he just talks about applying a force relative to the suspension compression. Is there any way it could work this way, or has he just forgot to mention it? By implementing it without damping my car will "wobble" when on the ground, but then I don't know what constants I should use for the spring.

Cheers

]]>