Results 1 to 4 of 4

Thread: Hi

  1. #1

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    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
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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.

  3. #3

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    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
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  4. #4

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    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
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width