Best way to analyze collision polygon
by Justin Mosiman · in Torque Game Builder · 02/03/2009 (6:03 pm) · 1 replies
Hello,
I want to get information about the collision polygon surrounding a t2dSceneObject, and I've found that I can get the polygon using obj->getCollisionPoly(). This method returns a const char* of the different collision points, but I want to, for example, find the right-most collision point on the x-axis. I could use a string tokenizer to do this, but I'm not sure if that is the correct way of doing it. Is this the correct route, or should I be doing something entirely different?
I just came up with a possible solution, anybody see any shortcomings of this? This will find the maximum x.
Thanks,
Justin
I want to get information about the collision polygon surrounding a t2dSceneObject, and I've found that I can get the polygon using obj->getCollisionPoly(). This method returns a const char* of the different collision points, but I want to, for example, find the right-most collision point on the x-axis. I could use a string tokenizer to do this, but I'm not sure if that is the correct way of doing it. Is this the correct route, or should I be doing something entirely different?
I just came up with a possible solution, anybody see any shortcomings of this? This will find the maximum x.
F32 xPoint = F32_MIN;
const t2dVector* pCollisionPoly = obj->getParentPhysics().getCollisionPolyBasis();
for(int i = 0; i < obj->getCollisionPolyCount(); ++i){
F32 tempXPoint = obj->getWorldPoint(pCollisionPoly[i]).mX;
if(tempXPoint > xPoint)
xPoint = tempXPoint;
}obj is of type t2dSceneObject.Thanks,
Justin
Associate Melv May
This saves you calling the expensive "getWorldPoint()" call.
Your code would work but you would always get the "screen right", no the "object right" e.g. the "right" in screen-space not object-space. I presume that's what you want?
Hope this helps,
Melv.