|
Thread: Hi
-
Sep 20th, 2002, 07:41 AM
#1
Thread Starter
Fanatic Member
Hi
I am done with a 3D object programming..
I am using isometric projection.. I want to do prespective projection.. Can any body tell me the matrix to transform to prespective projection..
I have
| ax , ay cos(A) - az Sin(A), ay Sin(A) + az Cos(A) |
| |
|Ax Cos() + Az Sin(B) , Ay , Az Cos(B) - Ax Sin(B) |
| |
|Ax Cos(G) - Ay Sin(G) , Ay Cos(G) + Ax Sin(G), Az|
I use the above matrix to transform 3d to 2d..
here the camera is at infinite..
But i want it to be at finite point..
Can anybody help me out..
Thanks,
Pradeep
-
Sep 20th, 2002, 08:09 AM
#2
Frenzied Member
Here is my own Perspective matrix function.
Code:
VOID MatrixMatrixPerspectiveFovLH(MATRIX* r, float fov, float aspect, float fNear, float fFar)
{
MatrixZero(&r);
float w,h,Q;
w = aspect * ( cosf(fov/2.0f)/sinf(fov/2.0f) );
h = cosf(fov/2.0f)/sinf(fov/2.0f);
Q = fFar / ( fFar - fNear );
r->_11 = w;
r->_22 = h;
r->_33 = Q;
r->_34 = 1.0f;
r->_43 = -Q*fNear;
return;
}
Yes, it is C++, but you should be able to figure out what is going on.
Here is my View matrix function:
Code:
VOID MatrixMatrixLookAtLH(MATRIX* r, VECTOR* eye, VECTOR* at, VECTOR* up)
{
VECTOR xaxis;
VECTOR yaxis;
VECTOR zaxis;
VECTOR temp;
temp = *at - *eye;
VectorNormalize(&zaxis, &temp);
VectorCross(&temp, up, &zaxis);
VectorNormalize(&xaxis, &temp);
VectorCross(&temp, &zaxis, &xaxis);
VectorNormalize(&yaxis, &temp);
MatrixMatrixIdentity(&r);
r->_11 = xaxis.x;
r->_21 = xaxis.y;
r->_31 = xaxis.z;
r->_12 = yaxis.x;
r->_22 = yaxis.y;
r->_32 = yaxis.z;
r->_13 = zaxis.x;
r->_23 = zaxis.y;
r->_33 = zaxis.z;
r->_41 = -1.0f * ((DotProduct(&xaxis, eye)));
r->_42 = -1.0f * ((DotProduct(&yaxis, eye)));
r->_43 = -1.0f * ((DotProduct(&zaxis, eye)));
return;
}
Again, C++, you will have to port it to VB yourself. When you have the two matrices created, you must then multiply them together, along with any transformation matrices you have in this order:
Code:
R = MatMul(Trans, View)
R = MatMul(R, Proj)
Z.
-
Sep 20th, 2002, 08:16 AM
#3
Thread Starter
Fanatic Member
Hi
First of all Thanks..
Can you send me the whole code in C..
I need to know what is VECTOR structure..
I also wanted to know one more stuff.. I have many points on sphear.. i have to create a mesh..
Currently i am finding the neighbour of each points and then connect them by lines.. Is there any good method.. I am new to graphics...
Thanks,
Pradeep
-
Sep 23rd, 2002, 03:59 AM
#4
Thread Starter
Fanatic Member
Prespective Projection
Hi,
I have found the solution..
After transforming the points .. To convert them to prespective..
do the following
PresPec = 1 - (POINTS(index).Z ) /Zc
POINTS(index) is an array of 3D points.
Zc is the camera distance from the origin
and the PresPec is the multiplication factor for the transformed X and Y coordinates..
X' = X \ PresPec
Y' = Y \ PresPec
It is obious that
Z = 0
Since we are projecting on X-Y plane.
Thanks,
Pradeep
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|