BBF

03-29-2004, 10:07 PM

How to write the projection(..) and unprojecton(..) likes gluProject and gluUnproject?

Does anybody know it? Thanks

Does anybody know it? Thanks

View Full Version : Project and unProject

BBF

03-29-2004, 10:07 PM

How to write the projection(..) and unprojecton(..) likes gluProject and gluUnproject?

Does anybody know it? Thanks

Does anybody know it? Thanks

SmutMonkey

03-29-2004, 11:03 PM

This is explained in the blue book, and should be in the glu source from SGI (http://oss.sgi.com/projects/ogl-sample/)

howie

04-04-2004, 01:51 PM

I don't know why you want to unproject, but this is how you project a point. Do this for each point in your triangle.

// Create your 1/z value

double OneOverZ = ( double )1.0 / ( double )tri[i].z;

// Project the X point

point.X = ((tri[i].x * gfCameraScale) * OneOverZ) + (ScreenWidth / 2);

// Project the Y point

point.Y = ((tri[i].y * (-gfCameraScale)) * OneOverZ) + (ScreenHeight / 2);

// Project the UV of the triangle if need be

tri[i].U = ( double ) NewA[ Count ].U * OneOverZ;

tri[i].V = ( double ) NewA[ Count ].V * OneOverZ;

gfCameraScale is usually a value between 100 and 600 depending on the screen width and height and the angle of the fustrum. I don't know how to calculate that.

// Create your 1/z value

double OneOverZ = ( double )1.0 / ( double )tri[i].z;

// Project the X point

point.X = ((tri[i].x * gfCameraScale) * OneOverZ) + (ScreenWidth / 2);

// Project the Y point

point.Y = ((tri[i].y * (-gfCameraScale)) * OneOverZ) + (ScreenHeight / 2);

// Project the UV of the triangle if need be

tri[i].U = ( double ) NewA[ Count ].U * OneOverZ;

tri[i].V = ( double ) NewA[ Count ].V * OneOverZ;

gfCameraScale is usually a value between 100 and 600 depending on the screen width and height and the angle of the fustrum. I don't know how to calculate that.

howie

04-04-2004, 01:53 PM

do the above with your translated points.

capn_midnight

04-06-2004, 07:34 AM

howie's responce is no where near what it takes to project a point in 3D space. for one thing, it does not take into account parallel projections.

The process of projecting a point is very complex. The red book MIGHT have it (though I don't recall it), I doubt the blue book has it, as that is just documentation on the ogl functions.

Pickup a copy (it's expensive though) of "Computer Graphics: Principles and Practice" by Foley, Va Dam, Feiner, and Hughes. It will have all of what you need, practically for anything related to graphics (unless it's something uber-new). I don't really think I can explain all of what you have to do in order to project a point.

However, once you figure out how to project a point, unprojecting it is easy. You just find the inverse of the projection matrix and use THAT matrix to "project" your point.

The process of projecting a point is very complex. The red book MIGHT have it (though I don't recall it), I doubt the blue book has it, as that is just documentation on the ogl functions.

Pickup a copy (it's expensive though) of "Computer Graphics: Principles and Practice" by Foley, Va Dam, Feiner, and Hughes. It will have all of what you need, practically for anything related to graphics (unless it's something uber-new). I don't really think I can explain all of what you have to do in order to project a point.

However, once you figure out how to project a point, unprojecting it is easy. You just find the inverse of the projection matrix and use THAT matrix to "project" your point.

howie

04-06-2004, 01:44 PM

I've written 2 software rendering, texture mapping, Gouraud shaded, 3D engines. I know how to project a point. Perhaps your thinking about clipping and translation.

The code above assumes the point has been translated by your matrix. Before you project a point, say on a quad or a try, you have to clip all the points to the near Z plain. But that was not part of his question.

He asked how to project a point, and that's how I do it. Perhaps there's more then one way to do it, but that's how I do it.

The code above assumes the point has been translated by your matrix. Before you project a point, say on a quad or a try, you have to clip all the points to the near Z plain. But that was not part of his question.

He asked how to project a point, and that's how I do it. Perhaps there's more then one way to do it, but that's how I do it.

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.