January 22, 2013, 8:35pm
Sorry for the rambling title.
Is it possible to take the collision point on a Geometry that uses a Terrain.j3md MatDef and have it tell me what the RGB value of the Alph Texture is for that point? Right now my command line Ogre mesh/scene -> .j3o compiler can attach objects to the surface of a Geometry, but if the Geometry uses a Terrain MatDef I’d like to be able to llimit attaching objects to area’s defined by the Aplh Texture.
Example: If the terrain blends from grass to dirt and my compiler is attaching bushes/shrubs to the terrain’s geometry I would like to limit it to only place it on the areas that are atleast 50% grass.
January 22, 2013, 8:50pm
I suggests you sample the Alpha Texture directly in you program code. Then it is just an matter of transforming your Vector3f position to a texture coordinate, shouldn’t be that hard I think.
Look at the ImageRaster class, it can be used to read values from textures on the CPU =)
January 22, 2013, 10:02pm
So thinking outloud:
I know the Geometry is an OgreMesh and the CollisionResult will let me know which triangle on the Geometry it collided with.
I could then get the vertices of the triangle and calculate the distance between my collision point and those verticies.
I can then take the TextCoords for those verticies and find my X, Y point for the ImageRaster based off of the distance I calculated between the collision point and each vertex.
Then I just create an ImageRaster using the Alpha Texture and get my RGB value.
Having it be slow is fine since this is being done when I create my .j3o, not at run time.
January 24, 2013, 10:05pm
Just incase someone else comes across this and wonders if it worked, I was able to get it working.
While I’m sure there is a much better way to find the point in the Image that is at the collision point this is what I ended up doing:
I took the geometry face’s triangle and the point where the collision took place, so I have points A, B, C, P
I create a line going from A through P and through the line between B and C
I take the length of the line from B to the new line I created and get it’s % length compared to the line from B to C
Repeat 2 & 3 but with corner B
Take the TexCoords’s UV map and create vector going from B to C and shorten it by the amount from step 3
Repeat 5 but for the line going from C to A
Take the ends of the new vectors to create a new triangle where the intersection inside is the contact point in the UV Map
Convert the point from 7 into X,Y pixel coordinates by scaling it to the Image’s Width and Height and use ImageRaster to get the color like kwando mentioned