Beispiel #1
0
        // Transforms the matrix to make it look at the target
        public void lookAt(Point eye, Point target, Vector up)
        {
            // Variables
            Vector[]	vec=	new Vector[3];

            vec[0]=	eye-target;
            vec[0].normalizeDest();
            vec[0]*=	-1;
            vec[1]=	up.getCrossProduct(vec[0]);
            vec[1].normalizeDest();
            vec[1]*=	-1;
            vec[2]=	vec[0].getCrossProduct(vec[1]);
            vec[2].normalizeDest();
            vec[2]*=	-1;

            xx=	vec[1].x;
            xy=	vec[1].y;
            xz=	vec[1].z;
            yx=	vec[2].x;
            yy=	vec[2].y;
            yz=	vec[2].z;
            zx=	vec[0].x;
            zy=	vec[0].y;
            zz=	vec[0].z;
            ox=	eye.x;
            oy=	eye.y;
            oz=	eye.z;
        }
Beispiel #2
0
        // Billboards the matrix
        public void billboard(Point objPos, Point camPos, Vector camUp, Vector camForward)
        {
            // Variables
            Vector	right=	(objPos-camPos);
            float	a=	right.getMagnitudeSq();
            Vector[]	cross=	new Vector[2];

            if(a== 0f)
                right=	-camForward;
            else
                right=	(Vector)(right*(1f/(float)Math.Sqrt(a)));
            cross[0]=	camUp.getCrossProduct(right);
            cross[0].normalizeDest();
            cross[1]=	right.getCrossProduct(cross[0]);

            resetToIdentityXO();

            xx=	cross[0].x;
            xy=	cross[0].y;
            xz=	cross[0].z;
            yx=	cross[1].x;
            yy=	cross[1].y;
            yz=	cross[1].z;
            zx=	right.x;
            zy=	right.y;
            zz=	right.z;
        }