Sign in to follow this  
Medo Mex

Raycasting incredibly slowing down rendering?

Recommended Posts

Medo Mex    891
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.

Share this post


Link to post
Share on other sites
Medo Mex    891
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:
[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
}
}
}
}
[/CODE]

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

Share this post


Link to post
Share on other sites

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

Sign in to follow this