I am trying to create a server for one game. This is a non-profit project. This project is a hobby for me. At the moment I am trying to add physics to the game. And at the moment I have some difficulties.
A few words about the game. This is a game about heavy vehicles (or armored tank, I'm not sure how it is correct in english). The feature of the game is that all calculations take place on the server.
I am using newton-3.14. I was able to add a physical object. But I need a calculation from the shots. So I decided to split the physical model. One simplified model will be used for physics. Another model is the hitbox. To calculate the shot, I need some data, such as the thickness of the armor, the location of the internal modules and the crew members. Because this physics model is not moving, I decided to use functions to work with static collision (as i remember in static collision i can assign material or index for each individual polygon). I'm not sure what I'm doing right, that's why I'm writing here.
I am creating a collision with the NewtonCreateSceneCollision function. Then NewtonSceneCollisionBeginAddRemove. And in the loop, I add a collision using the NewtonCreateTreeCollisionFromMesh function. Each collision created with the NewtonCreateTreeCollisionFromMesh function has its own material that will be used for the RayCast.
- Code: Select all
NewtonCollision *compound = NewtonCreateSceneCollision(newton, 0);
NewtonSceneCollisionBeginAddRemove(compound);
for (size_t i = 0, count = collision_vector.size(); i < count; i++)
{
NewtonMesh *mesh = collision_vector[i];
NewtonCollision *collision = NewtonCreateTreeCollisionFromMesh(newton, mesh, 0);
NewtonMeshDestroy(mesh);
NewtonCollisionMaterial material;
...
NewtonCollisionSetMaterial(collision, &material);
NewtonTreeCollisionSetUserRayCastCallback(collision, Cb_TreeRayCast);
NewtonSceneCollisionAddSubCollision(compound, collision);
NewtonDestroyCollision(collision);
}
NewtonSceneCollisionEndAddRemove(compound);
I need to somehow list all the surfaces that the raycast crosses. I found the NewtonTreeCollisionSetUserRayCastCallback function. But when I try to raycast (NewtonCollisionRayCast), I get an assert.
newton-3.14\sdk\dgphysics\dgcollisionbvh.cpp
- Code: Select all
dgFloat32 dgCollisionBVH::RayHitUser (void* const context, const dgFloat32* const polygon, dgInt32 strideInBytes, const dgInt32* const indexArray, dgInt32 indexCount)
{
dgAssert (0);
Is this function just for debugging? Or can I use it?
I have commented out the asserts. But when I try to raycast, the callback is called only once (it doesn't matter what I return 1.0 or the intersection parameter). And after that I get an assertion in the function.
newton-3.14\sdk\dgphysics\dgcollisionbvh.cpp
- Code: Select all
dgFloat32 dgCollisionBVH::RayCast (const dgVector& localP0, const dgVector& localP1, dgFloat32 maxT, dgContactPoint& contactOut, const dgBody* const body, void* const userData, OnRayPrecastAction preFilter) const
...
dgAssert(ray.m_normal.m_w == dgFloat32(0.0f));
The value of the vector is as if it had not been initialized.
Did I choose the correct collision type?
How can I get all the polygons that the raycast has crossed?