Jump to content

  • Log In with Google      Sign In   
  • Create Account

Raycasting incredibly slowing down rendering?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Medo3337   Members   -  Reputation: 680

Like
0Likes
Like

Posted 29 November 2012 - 12:16 PM

I'm using Bullet world Raytest to detect vision on enemies, I have a tank and this tank is supposed to see other enemies, so here is what I do:

1. I create a large invisible sphere around the tank.
2. Once any collision is detected with the sphere, I use Raytest to check if the tank can see the model that's colliding with the large sphere.
3. If the Raytest has hit and the hit is on one of the enemies, then the tank can see that enemy.

Basically, the tank will cast rays on any mesh colliding with the large sphere to see if this mesh is an enemy and to make sure that there is actually vision on it.

I can notice that the rendering is very slow even I'm only dealing with one tank, when I don't use Raytest it's rendering normally.

Sponsor:

#2 Medo3337   Members   -  Reputation: 680

Like
0Likes
Like

Posted 01 December 2012 - 06:24 AM

I'm trying to use raycasting to for a tank vision, so I have a very large sphere, this sphere will cover the tank and the vision area, so when any enemy collide with the sphere, I know that the enemy is around, so I use raycasting to check if the tank can actually have direct eye sight on the enemy, if raycasting hit the enemy, the tank can see the enemy otherwise the enemy is around the tank but the tank can't see the enemy yet.

I experience noticeable slow rendering when I use the following code:

// ########### NOTE: This code is executed in rendering, so this code will be executed every frame ###########
if (...) // If the enemy is colliding with the large sphere
{
btVector3 btRayFrom(tankPos.x, tankPos.y, tankPos.z);
btVector3 btRayFrom(enemyPos.x, enemyPos.y, enemyPos.z);
btCollisionWorld::ClosestRayResultCallback rayCallback(btRayFrom, btRayTo);
m_DynamicsWorld->rayTest(btRayFrom, btRayTo, rayCallback);
if (rayCallback.hasHit())
    {
	    const btRigidBody *body = btRigidBody::upcast(rayCallback.m_collisionObject);
	    if (body && body->hasContactResponse())
        {
            rayHitMesh = (long)body->getUserPointer();
            if (rayHitMesh == 3) // The number '3' is the ID of the enemy model
           {
                 // The tank can see the enemy
            } else {
                // The tank can't see the enemy
           }
       }
}
}

I'm using Bullet Physics Raytest, C++, DirectX 9.

Any idea on why the rendering is slow when I use the above code and how to fix it?

Edited by Medo3337, 01 December 2012 - 06:34 AM.


#3 Zaoshi Kaba   Crossbones+   -  Reputation: 4571

Like
0Likes
Like

Posted 01 December 2012 - 07:51 AM

What kind of shape is enemy model? If it's triangle mesh then yes, it will be extremely slow. You should use primitives like boxes, spheres, etc.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS