Rotate Quad on Box/Mesh

Hey,



I’m currently trying to implement Bullet-Holes into my Game.



My first thought was to create a Quad with the Texture of the Bullethole and just put it where it hit the Wall.

My Problem is now, how to rotate the Quad, so it fits on the Wall and doesn’t look weird.





I’m not quite sure how to explain this, so here are two Screenshots:

How it’s supposed to be:





And how it’s not supposed to be:







Currently I’m loading my Map from an XML-File and all the Walls are just Boxes, but i want to change this and load a Model instead.

For the beginning it would be enough to put the quad on the Box, but since i want to change this and load a Model instead it would be nice to know how to put the Quad on a Mesh.



So this is the method i’m currently using to make the Quad fit on the Box:

   private void faceBox(Quad bulletHole, Box b, Vector3f start, Vector3f end) {
      
      if(b.getXExtent() > b.getZExtent() && b.getYExtent() > b.getZExtent()) {
//         System.out.println("z small");
         bulletHole.lookAt(bulletHole.getLocalTranslation().add(new Vector3f(0,0,5)), Vector3f.UNIT_Y);
      }else if(b.getYExtent() > b.getXExtent() && b.getZExtent() > b.getXExtent()) {
//         System.out.println("x small");
         bulletHole.lookAt(bulletHole.getLocalTranslation().add(new Vector3f(5,0,0)), Vector3f.UNIT_Y);
         
      }else if(b.getXExtent() > b.getYExtent() && b.getZExtent() > b.getYExtent()) {
//         System.out.println("y small");
         bulletHole.lookAt(bulletHole.getLocalTranslation().add(new Vector3f(0,5,0)), Vector3f.UNIT_Y);
         
      }else if(b.getXExtent() == b.getYExtent() && b.getYExtent() == b.getZExtent()) {
         // All sides are the same
         bulletHole.lookAt(start, Vector3f.UNIT_Y);
      }
   }


start is the Location, from where the player shoot and end is the location, where the bullet hit the box.
But as you can see, this method isn't really good and it won't work on any other Meshes.

So is there a better way to do this? (which hopefully also works on any other mesh?)

Dennis

Well, you are probably making your bullets with the ray class?

Well then you can get the normal from them, a vector poinzing directly away (90 degree) from the face that got hit(think of it as a plane).Then you could generate the rotation from this info, I suspect there are some helper methods in the quarternion, aka from Vector / axis or so.

My Problem is how to get this Vector.

How do i get the normal of the plane that got hit?



As you already assumed, I'm using a Ray to check for the Collision and so i can get from the Results the Geometry that got hit, but how do i calculate the normal from this?

And do i need to use TrianglePickResults or can i also use BoundingPickResults to do this?

The well not sure either you an calcualte the normal over a plane

(A triangle exists in a 2d plane, generate the plane out of the Vectors, and calculate the normals out of this, you should be able to find the caclulations with google)



If you use Bounding pick, then you get the collision with the bounding, so assume a star witha  box as bounding, then your decal will be on the box!