Example #1
0
        public void Draw(DrawMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            if (!objectBase.EnableDrawing)
            {
                return;
            }

            PhysicsObject physicsObjectWithActiveCamera = scene.GetPhysicsObjectWithActiveCamera(0);

            if (physicsObjectWithActiveCamera == null)
            {
                return;
            }

            PhysicsCamera activeCamera = physicsObjectWithActiveCamera.Camera;

            if (activeCamera == null)
            {
                return;
            }

            float time = args.Time;

            activeCamera.GetTransposeRotation(ref world);
            Vector3.TransformVector(ref demo.CursorLightDirection, ref world, out localLightDirection);

            activeCamera.View.GetViewMatrix(ref view);
            activeCamera.Projection.GetProjectionMatrix(ref projection);
            objectBase.MainWorldTransform.GetTransformMatrix(ref world);

            if (objectBase.UserDataStr != null)
            {
                GL.Disable(EnableCap.DepthTest);
                GL.DepthMask(false);

                DemoMesh     mesh       = demo.Meshes[objectBase.UserDataStr];
                PhysicsLight sceneLight = scene.Light;

                sceneLight.GetDirection(ref lightDirection);
                sceneLight.SetDirection(ref localLightDirection);

                mesh.Draw(ref world, ref view, ref projection, sceneLight, objectBase.Material, activeCamera, false, demo.EnableWireframe);

                sceneLight.SetDirection(ref lightDirection);

                GL.DepthMask(true);
                GL.Enable(EnableCap.DepthTest);
            }
        }
Example #2
0
        void Draw(DrawMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            PhysicsObject physicsObjectWithActiveCamera = scene.GetPhysicsObjectWithActiveCamera(0);

            if (physicsObjectWithActiveCamera == null)
            {
                return;
            }

            PhysicsCamera activeCamera = physicsObjectWithActiveCamera.Camera;

            if (activeCamera == null)
            {
                return;
            }

            DemoMesh mesh = demo.Meshes[objectBase.UserDataStr];

            if ((mesh == null) || (mesh.Vertices == null))
            {
                return;
            }

            if (mesh.Dynamic && objectBase.Shape.ShapePrimitive.DynamicUpdate)
            {
                objectBase.Shape.GetMeshVertices(1.0f, 1.0f, false, true, mesh.Vertices);
                mesh.SetVertices(mesh.Vertices);
            }

            float time = args.Time;

            objectBase.MainWorldTransform.GetTransformMatrix(ref world);
            activeCamera.View.GetViewMatrix(ref view);
            activeCamera.Projection.GetProjectionMatrix(ref projection);

            PhysicsLight sceneLight = scene.Light;

            if (objectBase.Shape.ShapePrimitive.DynamicUpdateState)
            {
                mesh.Draw(ref world, ref view, ref projection, sceneLight, objectBase.Material, activeCamera, false, demo.EnableWireframe);
            }
            else
            {
                mesh = demo.Meshes[lakeInstanceName];

                mesh.Draw(ref world, ref view, ref projection, sceneLight, objectBase.Material, activeCamera, false, demo.EnableWireframe);
            }
        }
Example #3
0
        public void DrawSky(DrawMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            DemoKeyboardState keyboardState = demo.GetKeyboardState();

            if (keyboardState[Key.J])
            {
                scene.Light.RotationDegAngleX += 0.5f;

                render.SunRotationDegAngleX = scene.Light.RotationDegAngleX;
                render.UpdateSunParameters();
            }

            if (keyboardState[Key.K])
            {
                scene.Light.RotationDegAngleX -= 0.5f;

                render.SunRotationDegAngleX = scene.Light.RotationDegAngleX;
                render.UpdateSunParameters();
            }

            curTime = DateTime.Now.Hour * 60 + DateTime.Now.Minute;

            if (curTime != oldTime)
            {
                oldTime = curTime;

                // Sun position update based on the current time
                //scene.Light.RotationDegAngleX = curTime * 0.25f - 90.0f;

                //render.SunRotationDegAngleX = scene.Light.RotationDegAngleX;
                //render.UpdateSunParameters();
            }

            render.GetLightDirection(ref direction);
            render.GetSunColor(ref diffuse);

            Vector3.Multiply(ref diffuse, 0.5f, out diffuse);
            Vector3.Multiply(ref diffuse, 0.4f, out specular);

            scene.Light.SetDirection(ref direction);
            scene.Light.SetDiffuse(ref diffuse);
            scene.Light.SetSpecular(ref specular);

            PhysicsObject physicsObjectWithActiveCamera = scene.GetPhysicsObjectWithActiveCamera(0);

            if (physicsObjectWithActiveCamera == null)
            {
                return;
            }

            PhysicsCamera activeCamera = physicsObjectWithActiveCamera.Camera;

            if (activeCamera == null)
            {
                return;
            }

            if (demo.EnableWireframe)
            {
                return;
            }

            float time = args.Time;

            activeCamera.View.GetViewMatrix(ref view);
            activeCamera.Projection.GetProjectionMatrix(ref projection);

            if (objectBase.UserDataStr != null)
            {
                DemoMesh mesh = demo.Meshes[objectBase.UserDataStr];

                targets[0] = DrawBuffersEnum.ColorAttachment0;
                targets[1] = DrawBuffersEnum.None;
                targets[2] = DrawBuffersEnum.None;
                targets[3] = DrawBuffersEnum.None;

                GL.DrawBuffers(4, targets);

                GL.CullFace(mesh.CullMode);
                GL.Disable(EnableCap.Texture2D);
                GL.DepthMask(false);

                physicsObjectWithActiveCamera.MainWorldTransform.GetPosition(ref position);
                Matrix4.CreateTranslation(ref position, out translation);
                objectBase.MainWorldTransform.GetTransformMatrix(ref transform);
                Matrix4.Mult(ref transform, ref translation, out world);
                //Matrix4.Mult(ref world, ref view, out transform);
                //Matrix4.Mult(ref transform, ref projection, out world);

                //render.SetWorldViewProjection(ref world);
                //render.Texture = mesh.DemoTexture.Handle;
                render.SetWorld(ref world);
                render.SetView(ref view);
                render.SetProjection(ref projection);

                mesh.Draw(render);

                GL.DepthMask(true);
                GL.Enable(EnableCap.Texture2D);

                targets[0] = DrawBuffersEnum.ColorAttachment0;
                targets[1] = DrawBuffersEnum.ColorAttachment1;
                targets[2] = DrawBuffersEnum.ColorAttachment2;
                targets[3] = DrawBuffersEnum.ColorAttachment3;

                GL.DrawBuffers(4, targets);
            }
        }