Ejemplo n.º 1
0
 public Matrix(Vector xAxis, Vector yAxis, Vector zAxis, Vector pos)
 {
     xx=	xAxis.x;	xy=	xAxis.y;	xz=	xAxis.z;
     yx=	yAxis.x;	yy=	yAxis.y;	yz=	yAxis.z;
     zx=	zAxis.x;	zy=	zAxis.y;	zz=	zAxis.z;
     ox=	pos.x;	oy=	pos.y;	oz=	pos.z;
 }
Ejemplo n.º 2
0
 public BaseCamera()
 {
     view=	Matrix.IDENTITY;
     up=	Vector.UNIT_Y;
     //		minX=	MathExt.toRadians(-75f);
     //		maxX=	MathExt.toRadians(75f);
     //		rotX=	0;
 }
Ejemplo n.º 3
0
        public Mouse(OpenTK.GLControl form)
        {
            ctrl=	form;
            bManualMove=	false;
            position=	Point.ORIGIN;
            movement=	Vector.ZERO;
            buttonsPressed=	MBL.NONE;
            form.MouseMove+=	delegate(object sender, Wfx.MouseEventArgs args)
            {
                if(bManualMove)
                {
                    bManualMove=	false;
                    return;
                }

                // Variables
                Point	np=	new Point(args.X, args.Y);

                movement=	np.subtract(position);
                position=	np;
            };
            form.MouseDown+=	delegate(object sender, Wfx.MouseEventArgs args)
            {
                if((args.Button&Wfx.MouseButtons.Left)!= 0)
                    buttonsPressed|=	MBL.LMB;
                if((args.Button&Wfx.MouseButtons.Middle)!= 0)
                    buttonsPressed|=	MBL.MMB;
                if((args.Button&Wfx.MouseButtons.Right)!= 0)
                    buttonsPressed|=	MBL.RMB;
                if((args.Button&Wfx.MouseButtons.XButton1)!= 0)
                    buttonsPressed|=	MBL.XB1;
                if((args.Button&Wfx.MouseButtons.XButton2)!= 0)
                    buttonsPressed|=	MBL.XB2;
            };
            form.MouseUp+=	delegate(object sender, Wfx.MouseEventArgs args)
            {
                if((args.Button&Wfx.MouseButtons.Left)!= 0)
                    buttonsPressed=	(MBL)((byte)buttonsPressed-(byte)(MBL.LMB));
                if((args.Button&Wfx.MouseButtons.Middle)!= 0)
                    buttonsPressed=	(MBL)((byte)buttonsPressed-(byte)(MBL.MMB));
                if((args.Button&Wfx.MouseButtons.Right)!= 0)
                    buttonsPressed=	(MBL)((byte)buttonsPressed-(byte)(MBL.RMB));
                if((args.Button&Wfx.MouseButtons.XButton1)!= 0)
                    buttonsPressed=	(MBL)((byte)buttonsPressed-(byte)(MBL.XB1));
                if((args.Button&Wfx.MouseButtons.XButton2)!= 0)
                    buttonsPressed=	(MBL)((byte)buttonsPressed-(byte)(MBL.XB2));
            };
            form.MouseWheel+=	delegate(object sender, Wfx.MouseEventArgs args)
            {
                wheel=	args.Delta; // Work with this when you have a mouse and not a track pad
            };
            form.MouseHover+=	delegate(object sender, EventArgs args)
            {
                wheel=	0;
                movement=	Vector.ZERO;
            };
        }
Ejemplo n.º 4
0
 // Gets the dot product of this vector and the given vector
 public float getDotProduct(Vector vec)
 {
     return (x*vec.x)+(y*vec.y)+(z*vec.z);
 }
Ejemplo n.º 5
0
 // Gets the vector that is perpendicular to this vector and the given vector
 public Vector getCrossProduct(Vector vec)
 {
     return new Vector((y*vec.z-z*vec.y), (z*vec.x-x*vec.z), (x*vec.y-y*vec.x));
 }
Ejemplo n.º 6
0
 // Adds the vector to another vector to get a new vector
 public Vector add(Vector vec)
 {
     return new Vector(x+vec.x, y+vec.y, z+vec.z);
 }
Ejemplo n.º 7
0
 public Ray(Point pos, Vector dir)
 {
     position=	pos;
     direction=	dir;
 }
Ejemplo n.º 8
0
 public static Matrix createLookAt(Point eye, Vector dir, Vector up)
 {
     return createLookAt(eye, eye+dir, up);
 }
Ejemplo n.º 9
0
 // Subtracts the given vector from the point
 public Point subtract(Vector vec)
 {
     return new Point(x-vec.x, y-vec.y, z-vec.z);
 }
Ejemplo n.º 10
0
 public void setScale(Vector scale)
 {
     setScale(scale.x, scale.y, scale.z);
 }
Ejemplo n.º 11
0
        // Rotates the matrix using a 3d vector and a given radians
        public void rotate(Vector axis, float radians)
        {
            // Variables
            float	sin=	(float)(Math.Sin(radians));
            float	cos=	(float)(Math.Cos(radians));
            float	a=	1f-cos;
            float	ax=	a*axis.x;
            float	ay=	a*axis.y;
            float	az=	a*axis.z;

            xx=	ax*axis.x+cos;
            xy=	ax*axis.y+axis.z*sin;
            xz=	ax*axis.z-axis.y*sin;

            yx=	ay*axis.x-axis.z*sin;
            yy=	ay*axis.y+cos;
            yz=	ay*axis.z+axis.x*sin;

            zx=	az*axis.x+axis.y*sin;
            zy=	az*axis.y-axis.x*sin;
            zz=	ax*axis.z+cos;
        }
Ejemplo n.º 12
0
 // Multiples a 3d vector to affect it
 public Vector multiply(Vector vec)
 {
     return new Vector
     (
         xx*vec.x+yx*vec.y+zx*vec.z+ox,
         xy*vec.x+yy*vec.y+zy*vec.z+oy,
         xz*vec.x+yz*vec.y+zz*vec.z+oz
     );
 }
Ejemplo n.º 13
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;
        }
Ejemplo n.º 14
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;
        }
Ejemplo n.º 15
0
 public static Matrix createScale(Vector scale)
 {
     return createScale(scale.x, scale.y, scale.z);
 }
Ejemplo n.º 16
0
 // Substracts the vector to another vector to get a new vector
 public Vector subtract(Vector vec)
 {
     return new Vector(x-vec.x, y-vec.y, z-vec.z);
 }
Ejemplo n.º 17
0
 // Adds the given vector to the point
 public Point add(Vector vec)
 {
     return new Point(x+vec.x, y+vec.y, z+vec.z);
 }
Ejemplo n.º 18
0
 public void translate(Vector translation)
 {
     translate(translation.x, translation.y, translation.z);
 }
Ejemplo n.º 19
0
        // Rotates the camera about the given axis by the given radians
        public virtual void rotate(Vector axis, float radians)
        {
            // Variables
            Matrix	temp=	Matrix.IDENTITY;

            temp.rotate(axis, radians);
            temp*=	view;
            view=	temp;
            update();
        }
Ejemplo n.º 20
0
        // Returns a new matrix that is looking at the given target
        public static Matrix createLookAt(Point eye, Point target, Vector up)
        {
            // Variables
            Matrix	m=	Matrix.IDENTITY;

            m.lookAt(eye, target, up);

            return m;
        }