Advertisement Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

topic here

Sign in to follow this  


Yeah, the blocks really were that easy. Not a real hit in the frame rate either. I thought that the sphere testing might be costly, but it makes its first test on distance, so its pretty much unchanged as far as speed is related. The only thing thats really been taking up my time in my code, is trying to get the sphere-AABB responce to be 'good'. What I want is, normal reflection when it hits the AABB on a face. When it collides with an edge, it should react correctly. I know thats not very decriptave, but I just sat here for two mins trying to think about how to explain it. And I couldnt, its late. But I will show you what I have in place right now, because I love to share.

A little explination, this is a function of the sphere, to react to the AABB. The AABB is passed as 's' for the first param, and 2nd is for time, and its not being used yet, I'll get it in when its reacting the I want. The commented out stuff is working for when it hits the plane with only 1 axis in c (which is a vector from the closest point on the box to the sphere internal), if the closest point on the box is a corner, it would cause it to simply reverse direction. Not what I want. But anyways, the stuff that is being used, is in need of some work, but lets just say that its hard to predict where the ball is going to be reflected, inless you (are a user and) have read the code.

void CColSphere::CollideAABB(const CColAABB s, float tcount)
Vector3 b = s.ClosestToPoint(Internal - s.Internal); // vector offset from s.internal to closest point on/in box local coords
Vector3 c = ( b + s.Internal ) - Internal;

c = Normalize3(c);
Direction.x = -Direction.x;
Direction.z = -Direction.z;


if( s.Contains( Internal - s.Internal ) )
Direction = Internal - s.Internal;
Direction = Direction + c + b;
Direction = Normalize3(-Direction);

oh yeah, I also added a neat little funct to make the array of blocks, and its working well, so I thought I'd share this too. my fav part of it is that the distance in between rows are spaced to match with the columns. yay!

void ObjectManager::AddBlocks(int cols, int rows)
Vector3 dest;
float w = BOARD_WIDTH;
float h = BOARD_HEIGHT;
float b = w / 2;
float y = h / 2;
Vector3 S = Vector3(-b,0.0f,y);
for(int i = 1; i <= cols; ++i)
float x = S.x + (( w / ( cols + 1 ) ) * i );
for(int j = 1; j <= rows; ++j)
float y = S.z - (( w / ( cols + 1 ) ) * j );
BlockList.AddLast(new CObjectBlock(x, y));

Sign in to follow this  


Recommended Comments

There are no comments to display.

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

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!