Public Group

Raycasting incredibly slowing down rendering?

This topic is 2179 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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 on other sites
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 &amp;&amp; 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

Share on other sites
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.

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• Forum Statistics

• Total Topics
633388
• Total Posts
3011614
• Who's Online (See full list)

There are no registered users currently online

×