www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: cloak on January 31, 2013, 03:51:50 pm

Title: Help getting position on a texture
Post by: cloak on January 31, 2013, 03:51:50 pm
Hi,

I am still very new to JPCT-AE along with anything OGL.

I have a sphere, and I am translating the texture matrix around with touch events to make it appear as if it is moving. I am doing it this way so that I can maintain certain perspectives etc.

The problem I am having is the following. I am trying to get some sort of tapped position on my texture that I have wrapped around this sphere. I am using the following for calculating where I tapped:

Code: [Select]
final SimpleVector worldCoords = Interact2D.reproject2D3D(camera, frameBuffer, motionEventX, motionEventY);
worldCoords.matMul(camera.getBack().invert3x3());
worldCoords.add(camera.getPosition());
   
final SimpleVector directionFromCameraPosition = worldCoords.calcSub(camera.getPosition()).normalize();
final float distanceTo = world.calcMinDistance(worldCoords, directionFromCameraPosition, 10000);

final SimpleVector collisionPointCoords = new SimpleVector(directionFromCameraPosition);
collisionPointCoords.scalarMul(distanceTo);
collisionPointCoords.add(worldCoords);

If I add a primitive Object3d to test and I translate it to collisionPointCoords, it adds it to the world exactly where the collision point should be on my larger sphere.

How would I correlate this collision point vector to a point (xy) on my texture?

Any help would be greatly appreciated,
Thanks
Title: Re: Help getting position on a texture
Post by: EgonOlsen on January 31, 2013, 08:30:47 pm
Interesting question... ;D I haven't tried this myself, but it should work somehow like this:


Might work, might be total nonsense...

Title: Re: Help getting position on a texture
Post by: cloak on February 01, 2013, 08:15:36 am
Thanks for the prompt and helpful reply Egon, much appreciated. I will try your suggestion and give feedback.

Why would PolygonManager getTextureUV return null? I checked the javadocs and it doesn't specify. The other examples I have found of this methods' usage do not bother to check for null. What am I missing? getTransformedVertex works as expected, then when I call getTextureUV I am getting null for that polygonID and vertexNumber(s).

Edit: I got getTextureUV to work by removing my call to strip() on my sphere object.
Title: Re: Help getting position on a texture
Post by: EgonOlsen on February 01, 2013, 10:34:46 am
Edit: I got getTextureUV to work by removing my call to strip() on my sphere object.
I see. I should mention it in the docs, i guess...
Title: Re: Help getting position on a texture
Post by: cloak on February 01, 2013, 03:17:34 pm
Thanks a ton Egon, a bit of playing around and your suggestion worked perfectly for me ;D Multiplied the textureUV values with my texture matrix.  From there I worked out a mean value for the xy coords (good enough). Then used those values as percentages against my texture size to work out xy.