Advertisement

How do i find out the width of my model?

Started by February 17, 2005 01:38 PM
11 comments, last by BangorRipper 20 years ago
I am making a shooting game and i need to do some collision detection, i know the x,y,z of my bullet and also the x,y,z of my enemy but how do i find out the width of the enemy, i have played about with the numbers and have something that is close but what about something accurate? i cant say the width of the enemy, only the xyz that i plot the model at any ideas? i have rhino if that is able to tell me thanks
close is good, cheat when you can, and when you can't, do it anyway.
Did you know that the hitbox for all players in quake was just a hardcoded box roughly shaped like the character model.

If you really want to find the width of the enemy then just take all vertics and find the two vertics that are the furthest apart from each other in one axis.

But taking an aproximate value is good enough.
Advertisement
ok, so i just need to check the values in my raw file, thanks :)
Quote:
Original post by BangorRipper
ok, so i just need to check the values in my raw file, thanks :)


You don't want to hard code the values by looking at the raw values though. What if you decide to add more objects and you end up with hundreds of objects? Would you want those all hard coded? What if you change the model around, do you want to modify the hard coded values for every update? (I assume you were going to hard code them, if you were not then my apology)

Just make a function that can find the min and max of the vector components for you after you read in the raw values. To compute a bounding box is not too difficult.

Here's what I use to compute a bounding box:
//--You will only need the BoxMin and BoxMax, the other members//--were for debugging.void EPSBOUNDINGBOX::Compute(EPSVECTOR3 *Vertices, long NumVertices){    EPSVECTOR3 Min = EPSVECTOR3(0.0f);    EPSVECTOR3 Max = EPSVECTOR3(0.0f);    if(NumVertices == 0)    {        return;    }    for(long ID = 0; ID < NumVertices; ID++)    {        if(Vertices[ID].X < Min.X){Min.X = Vertices[ID].X;}        if(Vertices[ID].X > Max.X){Max.X = Vertices[ID].X;}        if(Vertices[ID].Y < Min.Y){Min.Y = Vertices[ID].Y;}        if(Vertices[ID].Y > Max.Y){Max.Y = Vertices[ID].Y;}        if(Vertices[ID].Z < Min.Z){Min.Z = Vertices[ID].Z;}		        if(Vertices[ID].Z > Max.Z){Max.Z = Vertices[ID].Z;}    }    this->BoxMin = EPSVECTOR3(Min.X, Min.Y, Min.Z);    this->BoxMax = EPSVECTOR3(Max.X, Max.Y, Max.Z);    this->Center.Average(&this->BoxMin, &this->BoxMax);    this->Radius = (this->BoxMax - this->BoxMin).Magnitude() / 2.0f;    this->BoundingVertices[0] = EPSVECTOR3(Min.X, Min.Y, Min.Z);    this->BoundingVertices[1] = EPSVECTOR3(Min.X, Max.Y, Min.Z);    this->BoundingVertices[2] = EPSVECTOR3(Max.X, Min.Y, Min.Z);    this->BoundingVertices[3] = EPSVECTOR3(Max.X, Max.Y, Min.Z);    this->BoundingVertices[4] = EPSVECTOR3(Max.X, Max.Y, Max.Z);    this->BoundingVertices[5] = EPSVECTOR3(Max.X, Min.Y, Max.Z);    this->BoundingVertices[6] = EPSVECTOR3(Min.X, Max.Y, Max.Z);    this->BoundingVertices[7] = EPSVECTOR3(Min.X, Min.Y, Max.Z);}
is that c code? i only understand java sorry.
if it is java then i have just seen my ass though :)
i have looked through the raw file and have found the min and max for x, just need to get the min and max z now, dont need the y becuase the bullet and enemies odnt move on the y in my game
No it's C++ and I have never used Java before.

Here's some Java resources for bounding boxes:
http://www.morrowland.com/apron/article/gl/boundingbox/index.php
http://www.brackeen.com/javagamebook/
Advertisement
UltimaX: In your code you initially set min and max to 0.
If the model was not centered around 0.0,0.0,0.0 your method could incorrectly report 0,0,0 being as the minimum or maximum.
I think min and max should be initially set to the first vertice value.

Quote:
Original post by stevenmarky
UltimaX: In your code you initially set min and max to 0.
If the model was not centered around 0.0,0.0,0.0 your method could incorrectly report 0,0,0 being as the minimum or maximum.
I think min and max should be initially set to the first vertice value.


Hmmm thanks for pointing that out. I originally had them set like the following (Looked at my bounding sphere class, it uses this also):

//--You will only need the BoxMin and BoxMax, the other members//--were for debugging.void EPSBOUNDINGBOX::Compute(EPSVECTOR3 *Vertices, long NumVertices){    //--    //--In the math base class    //--const float EPSMATH::BGFLT = 10e-5f;    //--(Could have just use 9999999 or some other crazy number :))    //--    EPSVECTOR3 Min = EPSVECTOR3( EPSMATH::BGFLT);    EPSVECTOR3 Max = EPSVECTOR3(-EPSMATH::BGFLT);    if(NumVertices == 0)    {        return;    }    for(long ID = 0; ID < NumVertices; ID++)    {        if(Vertices[ID].X < Min.X){Min.X = Vertices[ID].X;}        if(Vertices[ID].X > Max.X){Max.X = Vertices[ID].X;}        if(Vertices[ID].Y < Min.Y){Min.Y = Vertices[ID].Y;}        if(Vertices[ID].Y > Max.Y){Max.Y = Vertices[ID].Y;}        if(Vertices[ID].Z < Min.Z){Min.Z = Vertices[ID].Z;}		        if(Vertices[ID].Z > Max.Z){Max.Z = Vertices[ID].Z;}    }    this->BoxMin = EPSVECTOR3(Min.X, Min.Y, Min.Z);    this->BoxMax = EPSVECTOR3(Max.X, Max.Y, Max.Z);    this->Center.Average(&this->BoxMin, &this->BoxMax);    this->Radius = (this->BoxMax - this->BoxMin).Magnitude() / 2.0f;    this->BoundingVertices[0] = EPSVECTOR3(Min.X, Min.Y, Min.Z);    this->BoundingVertices[1] = EPSVECTOR3(Min.X, Max.Y, Min.Z);    this->BoundingVertices[2] = EPSVECTOR3(Max.X, Min.Y, Min.Z);    this->BoundingVertices[3] = EPSVECTOR3(Max.X, Max.Y, Min.Z);    this->BoundingVertices[4] = EPSVECTOR3(Max.X, Max.Y, Max.Z);    this->BoundingVertices[5] = EPSVECTOR3(Max.X, Min.Y, Max.Z);    this->BoundingVertices[6] = EPSVECTOR3(Min.X, Max.Y, Max.Z);    this->BoundingVertices[7] = EPSVECTOR3(Min.X, Min.Y, Max.Z);}
I had originally:

if(bullet[0].xBullet > aliens[x].xAlien - 2.0f && bullet[0].xBullet < aliens[x].xAlien+2.0f && bullet[0].zBullet > aliens[x].zAlien - 2.0f && bullet[0].zBullet < aliens[x].zAlien+2.0f)

System.out.println("hit alien no. " + x);

but now that I have discovered that:

bullet:
min x = -0.2
max x = 0.2
maz z = 0.5
min z = -0.5

alien:
min x = -2.222750
max x = 1.367632
max z = 1.116205
min z = -0.931442

what should my formula now be? and is this a good way of doing it?
thanks
can anyone plz tell me if this is fine or is there a better way that you would use?
thanks

This topic is closed to new replies.

Advertisement