ProjectedTextureUtil to project "spell ring" on terrain

I know that ProjectedTextureUtil is the way to go for this (I have only 3 textures to project, so it's no problem) and I really don't want to use the simple "ring made of lines" strategy because the artist for my game made a beautiful spell selection picture for me.



So I was wondering if anybody has done the code where they could project the texture on land via the mouse? The test is a little confusing so it will take me a lot of time to understand what I need to do. I'm just hoping somebody else who has done it (since I'm sure SOMEBODY has) could send me some snippets to work with. Thanks a ton :slight_smile:

I figured it out and programmed an example for you all.

I tried out your example, and hit a problem with it.

When I first ran it, I got the terrain, but everything was yellow with no projection or anything. Curiosity got the better of me, so after some digging I found the cause. It seems that this is a problem that occurs when the pos and aim passed into updateProjectedTexture have the same values for the X and Z coordinates.

I got this working by adding a small amount to the x coord of the newLoc in the simple update method -


                    Vector3f newLoc = loc.clone();
                    newLoc.y += 30f;
                    newLoc.x += 0.000001f;



I'm not a maths person, so have no idea why its going wrong (the matrix generated looks awfully empty, but I don't know if it should be) or if this is an issue that needs further looking at, or even if it only happens on my machine - Im just posting my findings here as an FYI to anyone else who had the same problem or loves maths :D