Game Development Community

Selecting PhysX objects

by Rex Hiebert · in Torque 3D Professional · 11/09/2009 (12:17 pm) · 4 replies

I have a game that is played in an RTS mode. The user must select objects and move them. I started with StaticShape objects and the user selected them much like in the World Editor. This is done by calling castRayRendered. But this does not seem to be able to see the PhysX object. If you place PhysX objects in the world editor you will notice that you don't get the mouseover highlight (white box corners) unless you are over the object icon. Other objects trigger the highlight when you mouse over the geometry. Now, you can get this effect if you are in bounding box mode but my app needs to trigger based on the object and not the bounding box.

I haven't delved into the workings of the PhysX objects to see why they are invisible to ray collisions. Has anyone run into this before? Is there a way to work around it?

Thanks!

#1
11/13/2009 (11:31 am)
Still no replies? Is anyone using PhysX beyond stacking a few crates and then shooting at them?

I started looking at how the worldeditor was doing its selection of normal objects. It calls Container::castRayBase which is in sceneObject.cpp. And that's where I get lost. There's not a lot of documentation in this function. In this function there are is a lot of work dealing with bins. What are these and how are objects assigned to bins? It looks like a lot of the ray cast collision code is handled here in the sceneObject which the PhysX object (pxSingleActor in my case) has subclassed. It would seem that the functionality would be there. What am I missing?
#2
02/21/2010 (8:06 am)
I have the same problem; I'm trying find physX objects scriptside with a raycast. But the raycast doesn't collide with physX objects, while they do have the correct typeMasks.

Did you find a solution Rex?
#3
02/22/2010 (1:44 pm)
PhysX objects are not seen by the normal raycast function but have their own function for this. I'm not sure how my solution would impact speed if it was used every frame since my app only needed this when clicking on an object. Here's what I did:
- get the normal hit object
- see if we are using physx
- get physx hit object
- see which it object was closer and use that one

bool hit;
SceneObject *controlObj = getControlObject();
if ( controlObj )
    controlObj->disableCollision();

Point3F startPnt = event.pos;
Point3F endPnt = event.pos + event.vec * mProjectDistance;

U32 mask = StaticShapeObjectType | StaticTSObjectType;

RayInfo riP;
bool hitP;

// get the normal torque hit object 
hit = gServerContainer.castRayRendered(startPnt, endPnt, mask, rInfo);
if ( gPhysicsPlugin )
{
	// TODO: hacked for single player... fix me!
	PhysicsWorld *world = gPhysicsPlugin->getWorld( "Client"/*isServerObject() ? "Server" : "Client"*/ );
        // see if we are in a physics world
	if ( world )
	{
                // get the physx hit obj
		hitP = world->castRay( startPnt, endPnt, &riP, Point3F(0,0,0) );
		// check for which object is closer
		if ( hitP && (riP.distance < (startPnt - rInfo->point).len()) )
		{
			// Torque object is closer than PhysX. Use it instead
			rInfo->distance = riP.distance;
			rInfo->face = riP.face;
			rInfo->faceDot = riP.faceDot;
			rInfo->normal = riP.normal;
			rInfo->object = riP.object;
			rInfo->point = riP.point;
			rInfo->t = riP.t;
			rInfo->texCoord = riP.texCoord;
			rInfo->userData = riP.userData;
			hit = hitP;
		}
	}
}
#4
02/27/2010 (2:53 am)
I only need the avatar to be able to use an interact function on physics objects, so for me there is no need to cast rays every frame.
Thanks for sharing your solution (and for even sharing your code).
Will have to see how I can implemend this in the best way.

Thanks again