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

topic here

Sign in to follow this  
mozie

280 views

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);
/*
if(c.x)
{
Direction.x = -Direction.x;
}
if(c.y)
{
}
if(c.z)
{
Direction.z = -Direction.z;
}

*/

if( s.Contains( Internal - s.Internal ) )
{
Direction = Internal - s.Internal;
}
else
{
Direction = Direction + c + b;
Direction = Normalize3(-Direction);
}
return;
}





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  


0 Comments


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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!