Community Forum

Project and unproject

Forum Overview >> Scripting

CategoryScripting
Created24.07.2009 12:17


Manuel Leithner - GIANTS Software 24.07.2009 12:28
Hi

I've two question about unproject and project.
I want to convert a node from 3d-space into 2d-screenspace using the project method and the getWorldTranslation function to get the world space coordinates.
If the node is in the visible sector of the screen the x and y coordinate should be in a range between 0 and 1???!!! X coordinate works fine but the y value is very strange :D ( e.g. 3.5 ).



Another question is the 3th return value or the 3th parameter of the unproject function. What's the sense of this coordinate. 2d-screen has only 2 dimensions ?! Is it a kind of distance? It tested a lot but i didn't find out the sense of this strange parameter :D


greetz Face

Stefan Geiger - GIANTS Software 26.07.2009 20:11
2d-screen still has 3 dimensons, the 3rd dimenson is the depth value (perpendicular to the screen).

This is of course used for unproject. If this would be leaved away, the return value should be an array instead of a point.
You can try to find out the effect by calling unproject for a point for some different sz values, eg 0, 0.1, 0.2, 0.3, .. 0.9, 1

The return values are the 3 coordinates in world space.


Project returns x=[0,1] and y=[0,1] if the given point is visible on the screen. Did you use sx,sy,sz = project(x,y,z)?
Eg to render a text at the center of a node you can use:
local x,y,z = getWorldTranslation(nodeId);
local sx,sy,sz = project(x,y,z);
if sz <= 1 then
renderText(sx, sy, 0.02, "text");
end;


Manuel Leithner - GIANTS Software 26.07.2009 23:58
Damn it...

stupid fault....


but now it works fine :D

thx


Note: Log in to post. Create a new account here.