# Aligning a Plane to the Terrain

## Aligning a Plane to the Terrain##

So. I am a jMonkeyEngine newbie and I have a decent program built up over the last week, and I just added ray casting. Upon contact with an object, it places a Sphere. I want it to place a textured quad onto whatever it hits and make the quad align with the face of the object it hit, like so:

I basically need a function to get the angle of the face of the object the ray hits, and rotate the plane to that angle.

- WickedJet

Angles are almost always the wrong approach for stuff like this.

What would you recommend I do this with then?
I’m using this to create a bullet hole texture on an object that i shoot, so there is probably a better way of doing this…

Well, I mean angles are usually wrong because inevitably you turn that angle back into something else. The angle was almost never necessary in the first place as it’s generally possible to go from what you have to what you want.

In this case of the originally stated (non) solution, you’d use a Quaternion to rotate the quad so you need to know what quaternion. lookAt() is a good start for that.

But what it sounds like you really want is projective texturing and that’s a whole other subject. I know some users posted some implementation a long time ago but I don’t remember who are anything like that.

The quad approach will have problems because it’s flat and your sphere is round.

Sorry if I wasn’t clear in the OP. I mean to say that i want to replace the Sphere with an image of a bullet hole, and the only method of doing that my dumb mind could come up with is creating a plane. But this projective texture mapping thing seems promising, so it’s time to do some research! Thanks for your help!

Could you do something like this?

``````Geometry bulletTexture;
CollisionResults cr = getCollision(rootNode);
Vector3f normal = cr.getClosestCollision().getContactNormal();
bulletTexture.setLocalTranslation(cr.getClosestCollision().getContactPoint());