Exemplo n.º 1
0
        private void glControl_Load(object sender, EventArgs e)
        {
            glControl.MakeCurrent();
            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.Lighting);
            GL.Disable(EnableCap.Texture2D);
            GL.Disable(EnableCap.CullFace);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.ClearColor(0.5f, 0.5f, 1.0f, 1.0f);

            plane     = new Physics.Plane(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0, 1, 0));
            rigidBody = new RigidBody();

            rigidBody.m_fMass           = 1.0f;
            rigidBody.m_v3Position      = new Vector3(0, 6.0f, 0);
            rigidBody.m_fGravity        = new Vector3(0, -9.81f, 0);
            rigidBody.m_fRestitution    = 0.0f;
            rigidBody.m_fFriction       = 1.0f;
            rigidBody.m_fLinearDamping  = 0.5f;
            rigidBody.m_fAngularDamping = 0.5f;
            rigidBody.m_v3Rotate        = new Vector3(ToRadian(30.0f), 0, ToRadian(20.0f));

            rigidBody.m_listPoints.Add(new Vector3(-2.0f, -1.0f, -1.5f));
            rigidBody.m_listPoints.Add(new Vector3(+2.0f, -1.0f, -1.5f));
            rigidBody.m_listPoints.Add(new Vector3(-2.0f, +1.0f, -1.5f));
            rigidBody.m_listPoints.Add(new Vector3(+2.0f, +1.0f, -1.5f));
            rigidBody.m_listPoints.Add(new Vector3(-2.0f, -1.0f, +1.5f));
            rigidBody.m_listPoints.Add(new Vector3(+2.0f, -1.0f, +1.5f));
            rigidBody.m_listPoints.Add(new Vector3(-2.0f, +1.0f, +1.5f));
            rigidBody.m_listPoints.Add(new Vector3(+2.0f, +1.0f, +1.5f));

            // back
            rigidBody.m_listIndices.AddRange(new int[] { 3, 1, 0 });
            rigidBody.m_listIndices.AddRange(new int[] { 0, 2, 3 });
            // front
            rigidBody.m_listIndices.AddRange(new int[] { 4, 5, 7 });
            rigidBody.m_listIndices.AddRange(new int[] { 7, 6, 4 });
            // left
            rigidBody.m_listIndices.AddRange(new int[] { 6, 2, 0 });
            rigidBody.m_listIndices.AddRange(new int[] { 0, 4, 6 });
            // right
            rigidBody.m_listIndices.AddRange(new int[] { 1, 3, 7 });
            rigidBody.m_listIndices.AddRange(new int[] { 7, 5, 1 });
            // bottom
            rigidBody.m_listIndices.AddRange(new int[] { 0, 1, 5 });
            rigidBody.m_listIndices.AddRange(new int[] { 5, 4, 0 });
            // top
            rigidBody.m_listIndices.AddRange(new int[] { 7, 3, 2 });
            rigidBody.m_listIndices.AddRange(new int[] { 2, 6, 7 });

            rigidBody.Create();

            DispatcherTimer timer = new DispatcherTimer();

            timer.Tick    += Timer_Tick;
            timer.Interval = TimeSpan.FromSeconds(0);
            timer.Start();
        }
Exemplo n.º 2
0
        private void glControl_Load(object sender, EventArgs e)
        {
            glControl.MakeCurrent();
            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.Lighting);
            GL.Disable(EnableCap.Texture2D);
            GL.Disable(EnableCap.CullFace);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.ClearColor(0.5f, 0.5f, 1.0f, 1.0f);

            plane      = new Physics.Plane(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0, 1, 0));
            rigidBody1 = new RigidBody();

            loader = new OBJLoader();
            loader.LoadFromFile("", "henger.obj");

            Vector3 v3Gravity = new Vector3(0, -9.81f, 0);

            rigidBody1.m_fMass           = 1.0f;
            rigidBody1.m_v3Position      = new Vector3(0f, 5.0f, 0);
            rigidBody1.m_fGravity        = v3Gravity;
            rigidBody1.m_fRestitution    = 0.0f;
            rigidBody1.m_fFriction       = 1.0f;
            rigidBody1.m_v3Rotate        = new Vector3(ToRadian(0.0f), 0, ToRadian(60.0f));
            rigidBody1.m_fLinearDamping  = 0.2f;
            rigidBody1.m_fAngularDamping = 0.2f;

            float scale = 0.1f;

            foreach (Vector3 v in loader.vertices)
            {
                rigidBody1.m_listPoints.Add(new Vector3(v.X * scale, v.Y * scale, v.Z * scale));
            }

            foreach (OBJLoader.Material mat in loader.materials)
            {
                for (int i = 0; i < mat.indices.Count; i += 3)
                {
                    int i0 = mat.indices[i + 0].id_vertex;
                    int i1 = mat.indices[i + 1].id_vertex;
                    int i2 = mat.indices[i + 2].id_vertex;

                    rigidBody1.m_listIndices.AddRange(new int[] { i0, i1, i2 });
                }
            }

            rigidBody1.Create();

            loader = new OBJLoader();
            loader.LoadFromFile("", "sphere.obj");

            rigidBody2 = new RigidBody();

            rigidBody2.m_fMass           = 1.0f;
            rigidBody2.m_v3Position      = new Vector3(2f, 10.0f, 2);
            rigidBody2.m_fGravity        = v3Gravity;
            rigidBody2.m_fRestitution    = 0.0f;
            rigidBody2.m_fFriction       = 1.0f;
            rigidBody2.m_v3Rotate        = new Vector3(ToRadian(0.0f), 0, ToRadian(-15.0f));
            rigidBody2.m_fLinearDamping  = 0.2f;
            rigidBody2.m_fAngularDamping = 0.2f;

            foreach (Vector3 v in loader.vertices)
            {
                rigidBody2.m_listPoints.Add(new Vector3(v.X * scale, v.Y * scale, v.Z * scale));
            }

            foreach (OBJLoader.Material mat in loader.materials)
            {
                for (int i = 0; i < mat.indices.Count; i += 3)
                {
                    int i0 = mat.indices[i + 0].id_vertex;
                    int i1 = mat.indices[i + 1].id_vertex;
                    int i2 = mat.indices[i + 2].id_vertex;

                    rigidBody2.m_listIndices.AddRange(new int[] { i0, i1, i2 });
                }
            }

            rigidBody2.Create();

            DispatcherTimer timer = new DispatcherTimer();

            timer.Tick    += Timer_Tick;;
            timer.Interval = TimeSpan.FromSeconds(0);
            timer.Start();
        }