Skip to main content

3D to 2D coordinates

2 replies [Last post]
adrianoaristarco
Offline
Joined: 2007-11-02

Given a Point3D in virtual universe coordinates (relative to Locale object) I simply need to know where this point will be eventually projected in a Canvas3D object.

I suppose that 2d coordinates depends of some factor like View position and orientation, canvas size, view policy, field of view.

I've found a lot of documentation like this page on wikipedia http://en.wikipedia.org/wiki/3D_projection
but I don't understand the difference between camera position and viewer position.

If someone can help me, i would appreciate it.
Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
weiland
Offline
Joined: 2005-08-05

This question keeps coming up. Here's some code I chopped out of something else (and repurposed); I would suggest people comment/correct it. Not clear to me right now where the left/right eye transform differences would come into play (seems like they should).

Bill

[code]
public Point2d getProjectedPoint(Canvas3D canvas, Point3d point) {
Transform3D fromVworldToImagePlate = new Transform3D();
canvas.getVworldToImagePlate(fromVworldToImagePlate);

Point3d imagePlatePoint = new Point3d(point);
fromVworldToImagePlate.transform(imagePlatePoint);
Point2d projectedPoint = new Point2d();
canvas.getPixelLocationFromImagePlate(imagePlatePoint, projectedPoint);

return projectedPoint;
}
[/code]

adrianoaristarco
Offline
Joined: 2007-11-02

Many thanks for your answer.
I think it's correct, I have also found another piece of code from David Selman's book (you can read it here: http://www.tecgraf.puc-rio.br/~ismael/Cursos/Cidade_CG/labs/Java3D/Java3... )

From 2.2.1:

private int xScreenCenter = 320/2;
private int yScreenCenter = 240/2;
private Vector3d screenPosition = new Vector3d( 0, 0, 20 );
private Vector3d viewAngle = new Vector3d( 0, 90, 180 );
private static final double DEG_TO_RAD = 0.017453292;
private double modelScale = 10;

CT = Math.cos( DEG_TO_RAD * viewAngle.x );
ST = Math.sin( DEG_TO_RAD * viewAngle.x );
CP = Math.cos( DEG_TO_RAD * viewAngle.y );
SP = Math.sin( DEG_TO_RAD * viewAngle.y );

public void projectPoint( Point3d input, Point3d output )
{
double x = screenPosition.x + input.x * CT - input.y * ST;
double y = screenPosition.y + input.x * ST * SP + input.y * CT * SP
+ input.z * CP;
double temp = viewAngle.z / (screenPosition.z + input.x * ST * CP
+ input.y * CT * CP - input.z * SP );

output.x = xScreenCenter + modelScale * temp * x;
output.y = yScreenCenter - modelScale * temp * y;
output.z = 0;
}

Where ScreenPosition it's the ViewPlatform position.
Regards
Adriano Aristarco