Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 23 Oct 2000
Offline Last Active Apr 20 2013 04:24 AM

Posts I've Made

In Topic: bounding box collision detection not working right....

20 April 2013 - 04:27 AM

Oh and to use:


Vector playerPosition = new Vector();
			playerPosition.x = Math.abs(v.x);  // get player X,Y,Z
			playerPosition.y = Math.abs(v.y);
			playerPosition.z = Math.abs(v.z);
			playerSphere.update(playerPosition, 1.0f);

			AABB voxel = new AABB(1f, 1f, 1f); // width, height, depth
			Vector voxelPosition = new Vector();
			voxelPosition.x = Math.abs(bx);  // get object X,Y,Z
			voxelPosition.y = Math.abs(by);
			voxelPosition.z = Math.abs(bz);

			if (CollisionLibrary.testCircleAABB(playerSphere, voxel)) {
// do whatever 

In Topic: bounding box collision detection not working right....

20 April 2013 - 04:26 AM



Don't know if this will help, this is java AABB I use, should be simple to port to C++.


package com.voxby.game;

public class CollisionLibrary {
	public static boolean testAABBAABB(final AABB box1, final AABB box2) {
		   if (Math.abs(box1.center.x - box2.center.x) > (box1.r[0] + box2.r[0])) return false;
		   if (Math.abs(box1.center.y - box2.center.y) > (box1.r[1] + box2.r[1])) return false;
		   if (Math.abs(box1.center.z - box2.center.z) > (box1.r[2] + box2.r[2])) return false;
		   return true;
	public static float sqDistPointAABB(final Vector p, final AABB aabb) {
		   float sqDist = 0.0f;
		   float v;
		   float minX, minY, minZ, maxX, maxY, maxZ;
		   // get the minX, maxX, minY, maxY and minZ, maxZ points of the AABB
		   minX = aabb.center.x - aabb.r[0];
		   maxX = aabb.center.x + aabb.r[0];
		   minY = aabb.center.y - aabb.r[1];
		   maxY = aabb.center.y + aabb.r[1];
		   minZ = aabb.center.z - aabb.r[2];
		   maxZ = aabb.center.z + aabb.r[2];
		   // test the bounds against the points X axis
		   v = p.x;
		   if (v < minX) sqDist += (minX - v) * (minX - v);
		   if (v > maxX) sqDist += (v - maxX) * (v - maxX);
		   // test the bounds against the points Y axis
		   v = p.y;
		   if (v < minY) sqDist += (minY - v) * (minY - v);
		   if (v > maxY) sqDist += (v - maxY) * (v - maxY);
		   // test the bounds against the points Z axis
		   v = p.z;
		   if (v < minZ) sqDist += (minZ - v) * (minZ - v);
		   if (v > maxZ) sqDist += (v - maxZ) * (v - maxZ);
		   return sqDist;
		public static boolean testCircleAABB(final Circle circle, final AABB box) {
		   // get the squared distance between circle center and the AABB
		   float sqDist = sqDistPointAABB(circle.center, box);
		   float r = circle.radius;
		   return sqDist <= r * r;

package com.voxby.game;

public class AABB {
	public Vector center;
	public float r[];

	public AABB(final float width, final float height, final float depth) {
		center = new Vector();
		r = new float[3];
		r[0] = width * 0.5f;
		r[1] = height * 0.5f;
		r[2] = depth * 0.5f;

	public void update(final Vector position) {
		center.x = position.x;
		center.y = position.y;
		center.z = position.z;

package com.voxby.game;

public class Vector {
	public float x;
	public float y;
	public float z;

	public Vector() {
		x = 0.0f;
		y = 0.0f;
		z = 0.0f;

	// returns the (squared) distance between this Vector and another
	public float distSQ(final Vector vec) {
		float distX = x - vec.x;
		float distY = y - vec.y;
		float distZ = z - vec.z;
		return distX * distX + distY * distY + distZ * distZ;

In Topic: Fastest data structure

19 April 2013 - 05:50 AM

Thanks @Sandman, some good insight there, appreciate your comments.


As I have many, many chunks, I think I need to look at loading and unloading these into the hash map.  At the moment, they 

are ALL placed into it even if you cannot see them on screen - so quite a big memory footprint and impossible to make 

the world seem infinite.


1. If chunk has gone out of view, unload from hash map

2. If a chunk has come into view, load to hash map


Should only have say max of 16 chunks loaded at a time.


It is the chunks in the hash map that get rendered.  



In Topic: Fastest data structure

19 April 2013 - 12:53 AM

Hey many thanks guys,


No, the project is running ok - frustum culling will be implemented today on chunks, but this can be expensive if no form of

spatial partioning been done - we don't want to loop through 100000 objects for instance... 


Using an array of object id's and use this id as the index (kinda like a bucket sort) - I guess this will be a dynamic array?


There still needs to be something in place to determine what is visible and not, for voxel type world it looks like an Octree is

a good solution to speed this process up.


@Norman - my draw routine is basically like that, but that is flawed as you would be checking every object in that loop, it needs splitting / partioning up first.


My voxels do have a boolean to see if active or not.  


Reason wanting to know if something had been drawn as at some point it will need unloading from memory - so I guess I should have said, has been loaded and still in view, if not in view but has been loaded, release from memory.


I implemented face culling yesterday, basically don't draw faces that have neighbouring ones, this is all done before being sent to the GPU, so gave some very good optimization.  Of course, you could take this further and merge triangles - but and don't shout ;-), but I'm using quads at the moment.


Have any of you guys got some good advice on what to do when a collision with one of the blocks occurs?


Again, thanks for your appreciated advice :-)


In Topic: Fastest data structure

18 April 2013 - 10:52 AM

PS - here is a clip of what I am doing: