示例#1
0
        protected override void Initialize()
        {
            //testMatrices();

            // make all bodies
            bodiesList = new List <JBody3D> {
            };
            // var coordinatesystem = new CoordSystem(new JVertex3D(0, 0, 0, 1), new JVertex3D(20, 20, 20, 0));
            // bodiesList.Add(coordinatesystem);
            var xpoint = new JRigidBody3D();

            xpoint.Position = new JVertex3D(0, 0, 0, 1);
            xpoint.Rotation = new JQuaternion3D(new JVertex3D(1, 0, 0, 0), 0);
            xpoint.Scale    = new JVertex3D(1, 1, 1, 0);
            xpoint.Color    = white;
            xpoint.Vertices = new JVertex3D[1] {
                new JVertex3D(1, 0, 0, 1)
            };
            xpoint.Lines = new JLine3D[0] {
            };
            bodiesList.Add(xpoint.ToJBody3D());

            // bodies to array
            bodies = bodiesList.ToArray();

            // camera
            camera = new JCamera(new JVertex3D(0, 100, 0, 1), new JVertex3D(0, 1, 0, 0));
            //camera.CenterToPoint(new JVertex3D(0, 0, 0, 1));

            // game stuff
            graphicsGame = Output.Graphics;

            frameCounter = 0;
        }
示例#2
0
        private void drawBodies(JCamera cam)
        {
            // get transformation matrix from world space to view space (W2V)
            var translateW2V = new JTranslationMatrix3D(-cam.Position);
            var rotateW2V    = new JRotationMatrix3D(-cam.Rotation);
            var tW2V         = translateW2V * rotateW2V;

            // get transformation matrix from view space to projected space (V2P)
            var tV2P = new JOrthoProject3D(cam);

            // W2P
            var tW2P = tV2P * tW2V;

            foreach (JBody3D b in bodies)
            {
                // get transformation matrix from body space to world space (B2W)
                var scaleB2W     = new JScaleMatrix3D(b.Scale);
                var translateB2W = new JTranslationMatrix3D(b.Position);
                var rotateB2W    = new JRotationMatrix3D(b.Rotation);

                var tB2W = translateB2W * scaleB2W * rotateB2W;

                foreach (JRigidBody3D rb in b.RigidBodies)
                {
                    // get transformation matrix form rigidbody space to body spacy (RB2B)
                    var scaleRB2B     = new JScaleMatrix3D(rb.Scale);
                    var translateRB2B = new JTranslationMatrix3D(rb.Position);
                    var rotateRB2B    = new JRotationMatrix3D(rb.Rotation);

                    var tRB2B = translateRB2B * scaleRB2B * rotateRB2B;

                    // get full transformation matrix to projected space
                    var t = tW2P * tB2W * tRB2B;

                    // draw all vertices
                    foreach (JVertex3D v in rb.Vertices)
                    {
                        var r = t * v;
                        var p = cam.GetImagePoint(r);

                        graphicsGame.Point(rb.Color, p);
                    }

                    // draw all lines
                    foreach (JLine3D l in rb.Lines)
                    {
                        var start = t * l.Start;
                        var stop  = t * l.Stop;

                        var p1 = cam.GetImagePoint(start);
                        var p2 = cam.GetImagePoint(stop);

                        graphicsGame.Line(rb.Color, p1, p2);
                    }
                }
            }
        }