Question: X_SCREEN2WORLD, X_COLLISIONRAY und X_GETFACE

Previous topic - Next topic

Det

Hello again,
today it's me again having problems with the above functions.
I built up a small testscenario to check a collision with ny 3d-object.
Goal: Read out the coordinates under the mouseposition in the uv-map of my texture.
Test: Created a 3d-object in blender, exported as obj and converted to ddd. Result: All neat. Object visible at (0,0,0) (I think), camera in distance 15 along the x-axis, looking at (0,0,0) as well.
Now I use X_COLLISIONRAY: Stuffed in two point-coordinates: I decided that the first point is my camerapostion: (15,0,0) the othe one is wherever the user touched (positioned the mouse). I understood tha I have to transform the Screencoordinates the the user gave with the mouse have to be converted using "X_SCREEN2WORLD" (right?).
Now I get some collisions listed. BUT: The area that detects a collision is far smaller than the visible object. How come? Is it because of my Screen2World-Z-Parameter? Don't know what this is used for and cannot imagine a possible value. 1 did at least the trick... (Help please!)

Next problem: (Ignoring the first). I get a faceId. But: I do not at all understand the faces-array (not because I don't understand the two-dimensional arrays, but because of the values in nodes...) So: The face consists of three edges (nodes). This be my first dimension. But: Why can I ask a node for it's "texture-coordinates" (at index 3 and 4)? As value for face[0][3] I get something like:
Tx: 0.6175429821 ty:0.3996520042
I had thought of a more "direkt" coordinate. How am I supposed to transform this value back to my texture-map?

Some samplecode:
Code (glbasic) Select
LOADSPRITE "Media/WorldTexture.jpg", 0
X_LOADOBJ "Media/MyWorldResized.ddd", 0
LOCAL mx,my,b1,b2
LOCAL col
LOCAL cx,cy,cz
LOCAL faceIdx, face[]

SYSTEMPOINTER 1

WHILE TRUE
MOUSESTATE mx,my,b1,b2
X_SCREEN2WORLD mx, my, 1, cx,cy,cz

col = X_COLLISIONRAY(0, 0, 15,0,0, cx,cy,cz)
IF (col<>0)
DEBUG ("Coll det" + col + ".."+ "\n")
faceIdx=X_GETCOLLISIONFACE()
X_GETFACE 0,0,faceIdx,face[]
DEBUG ("Tx: " + face[0][3] + " ty:" + face[0][4] + "\n");
ELSE
DEBUG ("NO Coll det " + "\n")
ENDIF

X_MAKE3D 1, 50, 45
X_CAMERA 15,0,0,0,0,0
X_SETTEXTURE 0, -1

X_ROTATION 0,0,1,0
X_ROTATION 0,0,0,1
X_DRAWAXES 10,10,10
X_DRAWOBJ 0,0
SHOWSCREEN
WEND


As always: I'd be very glad for any input.
TIA
Det
Adopt, adapt and improve