Esempio n. 1
0
        static void Main(string[] args)
        {
            //Matrix4x4 m1 = new Matrix4x4(-0.0198209956f, -0.328598410f, -0.944261789f, 396.734772f, -0.999803603f, 0.00651442632f, 0.0187198818f, 54.7861862f, 0.000000000f, 0.944447339f, -0.328662962f, 30.0000000f, 0, 0, 0, 1);
            //Matrix4x4 m2 = new Matrix4x4(-0.0198209956f, -0.328598410f, -0.944261789f, 396.734772f, -0.999803603f, 0.00651442632f, 0.0187198818f, 54.7861862f, 0.000000000f, 0.944447339f, -0.328662962f, 30.0000000f, 0, 0, 0, 1);
            //Matrix4x4 m3 = LR.Multiply(m1, m2);
            //Transform t = new Transform(m1);
            //Transform t2 = LR.Multiply(LR.Scale(10, 10, 10), t);

            Transform         t11      = new Transform(new Matrix4x4(-0.0198209956f, -0.328598410f, -0.944261789f, 396.734772f, -0.999803603f, 0.00651442632f, 0.0187198818f, 54.7861862f, 0.000000000f, 0.944447339f, -0.328662962f, 30.0000000f, 0, 0, 0, 1));
            Transform         t22      = new Transform(new Matrix4x4(-0.0198209956f, -0.328598410f, -0.944261789f, 396.734772f, -0.999803603f, 0.00651442632f, 0.0187198818f, 54.7861862f, 0.000000000f, 0.944447339f, -0.328662962f, 30.0000000f, 0, 0, 0, 1));
            AnimatedTransform cam2word = new AnimatedTransform(t11, 0, t22, 1);

            float[] screen = new float[4] {
                -1, 1, -1, 1
            };
            Film film = new Film();

            film.xResolution = 700;
            film.yResolution = 700;
            OrthoCamera  orthoCamera  = new OrthoCamera(cam2word, screen, 0, 1, 0, 0, film);
            CameraSample cameraSample = new CameraSample(689.738220f, 678.709778f, 0.559352338f, 0.253510952f, 0.562246382f);

            //cameraSample.imageX = 689.738220f;
            RayDifferential rd;

            orthoCamera.GenerateRayDifferential(cameraSample, out rd);
        }
Esempio n. 2
0
        /// <summary>
        /// This method will be called when the RenderTarget and views are created.
        /// Here you must create the scene, cameras and all the elements that you need
        /// </summary>
        private void OnInitializeRender()
        {
            // To render sprites, we do not need the depth
            renderView.State.DepthEnabled = false;

            // A new Scene!!
            scene = new Scene();

            camera = new OrthoCamera(new StringBuilder("camera"));

            renderView.State.CullMode = CULLMODE_STATE.NONE;

            // Each scene is composed of nodes

            scene.Root.AddChildren(node = new Node());

            // We need a material for this sprite

            Material      material = new Material("standard");
            MaterialLayer layer    = material.CreateLayer();

            layer.DiffuseMap = editorEngine.Textures.CreateTexture2DFromFile(new StringBuilder("stone"));

            // Creates a new sprite
            sp          = editorEngine.Sprites.Create(100, 100);
            sp.Material = material;

            // Add the sprite to the node
            node.AddRenderable(sp);
        }
Esempio n. 3
0
 public void Init()
 {
     fbo   = new Framebuffer(shadowMapWidth, shadowMapHeight);
     s_cam = new OrthoCamera(-5, 5, -5, 5, -5, 5);
     fbo.Init();
     s_cam.Far = splitDist;
 }
Esempio n. 4
0
        public override void ClientInitialise(Client client)
        {
            this.camera = new OrthoCamera(client.Viewport.Size);

            this.container        = new UIContainer(78, 170);
            this.container.Camera = this.camera;
            this.SetupUI(client);
            this.RegisterClientObject(this.container);


            this.perfinfo = new PerformanceInfo(client, null, new Asset("embedded", "ibm-plex-mono.regular.ttf"), 14);
            this.perfinfo.MaxDisplayCounters = 8;
            this.RegisterClientObject(this.perfinfo);

            base.ClientInitialise(client);
        }
Esempio n. 5
0
        public override void Setup(GraphicsDevice graphics, AudioDevice audio, Window window)
        {
            this.kerningTextColour = Colour.White;
            this.camera            = new OrthoCamera(graphics.Viewport.Size);
            this.center            = (Vector2)graphics.Viewport.Size / 2;
            this.font          = Font.LoadFromStream(GetEmbeddedStream("TextTest.ibm-plex-mono.regular.ttf"), FontFormat.TrueType);
            this.font.FontSize = 38;
            this.txtrenderer   = graphics.CreateTextRenderer(this.camera, this.font);

            var ds = new DrawState()
            {
                Blend     = BlendMode.Alpha,
                DepthTest = DepthTestMode.None
            };

            graphics.DefaultDrawState = ds;
            window.OnMouseMoved      += OnMouseMoved;
        }
Esempio n. 6
0
        public override void Setup(GraphicsDevice graphics, AudioDevice audio, Window window)
        {
            this.cursorSmile = new Smile()
            {
                colour = Colour.White
            };

            this.rng    = new Random();
            this.smiles = new List <Smile>();

            this.viewportSize = graphics.Viewport.Size;

            this.listener             = audio;
            this.listener.Orientation = Orientation.Ortho;
            this.scream    = audio.LoadSound(GetEmbeddedStream("RendererTest.scream.wav"), AudioFormat.Wav);
            this.placement = audio.LoadSound(GetEmbeddedStream("RendererTest.retrojump.ogg"), AudioFormat.OggVorbis);

            this.screamer               = audio.CreateSpeaker(this.scream);
            this.screamer.Loop          = true;
            this.screamer.MaxDistance   = 400;
            this.screamer.MinDistance   = 100f;
            this.screamer.DistanceScale = 0.2f;
            this.screamer.Volume        = 0.6f;

            this.placementEmitter          = audio.CreateSpeaker(this.placement);
            this.placementEmitter.Loop     = false;
            this.placementEmitter.Position = null;
            this.placementEmitter.Volume   = 1f;

            this.camera = new OrthoCamera(this.viewportSize);

            this.spriteRenderer = graphics.CreateSpriteRenderer(this.camera, SpriteRenderer.DrawOrder.Reversed);

            this.smiley = graphics.CreateTexture2D(GetEmbeddedStream("RendererTest.smiley.png"), ImageFormat.PNG);

            graphics.DefaultDrawState = new DrawState()
            {
                Blend     = BlendMode.Alpha,
                DepthTest = DepthTestMode.None
            };

            window.OnMouseButtonPressed += this.MousePressed;
            window.OnMouseMoved         += this.MouseMoved;
        }
        // --------------------------------------------------------------------

        public void CreateCamera()
        {
            mCameraPivotTop = new SceneObject("CameraPivotTop");

            mCameraPivotXZRot        = new SceneObject("CameraPivotXZ");
            mCameraPivotXZRot.Parent = mCameraPivotTop;

            mCameraPivotZMov        = new SceneObject("CameraPivotZMov");
            mCameraPivotZMov.Parent = mCameraPivotXZRot;

            mNavigationCamera        = new PerspectiveCamera("MainCamera", MathHelper.DegreesToRadians(60), 1.5f);
            mNavigationCamera.Parent = mCameraPivotZMov;

            mOrthoCamera        = new OrthoCamera("OrthoCamera", 5f, 5f);
            mOrthoCamera.Parent = mCameraPivotZMov;

            mCameraPivotTop.Transform.LocalPosition = new Vector3(0, 0.5f, 3);

            mSelectedCamera = mNavigationCamera;
        }
Esempio n. 8
0
 protected override void OnViewChanged()
 {
     base.OnViewChanged();
     //((Control)Root).Size = new Vector2(View.Size.Width, View.Size.Height);
     //Camera = new OrthoCamera
     //{
     //    Width = View.Size.Width,
     //    Height = View.Size.Height,
     //    Position = new Vector3(View.Size.Width / 2f, View.Size.Height / 2f, 0)
     //};
     ((Control)Root).Size = new Vector2(View.GraphicsDevice.Settings.Resolution.Width, View.GraphicsDevice.Settings.Resolution.Height);
     Camera = new OrthoCamera
     {
         Width    = View.GraphicsDevice.Settings.Resolution.Width,
         Height   = View.GraphicsDevice.Settings.Resolution.Height,
         Position = new Vector3(View.GraphicsDevice.Settings.Resolution.Width / 2f, View.GraphicsDevice.Settings.Resolution.Height / 2f, 0),
         ZNear    = 0,
         ZFar     = 100
     };
     Application.Log("Screen Resolution: " + View.GraphicsDevice.Settings.Resolution);
 }
 public void Init()
 {
     fbo = new Framebuffer(shadowMapWidth, shadowMapHeight);
     s_cam = new OrthoCamera(-5, 5, -5, 5, -5, 5);
     fbo.Init();
     s_cam.Far = splitDist;
 }
Esempio n. 10
0
 // Use this for initialization
 void Start()
 {
     orbitCamera = _camera.GetComponent <OrbitCamera>();
     orthoCamera = _camera.GetComponent <OrthoCamera>();
 }
Esempio n. 11
0
 public override void Setup(GraphicsDevice graphics, AudioDevice audio, Window window)
 {
     this.camera          = new OrthoCamera(graphics.Viewport.Size);
     graphics.ClearColour = new RGBA(25, 25, 25);
     this.renderer        = graphics.CreateShapeRenderer(this.camera);
 }
Esempio n. 12
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="type">Orthographic viewport type</param>
 public OrthoViewport(ViewportTypes type)
 {
     mousePrevPos   = new Point();
     mCamera        = new OrthoCamera();
     MViewportTypes = type;
 }
Esempio n. 13
0
        public static Scene FromFile(string filename)
        {
            StreamReader reader = null;

            try
            {
                reader = new StreamReader(filename);
                Scene outScene = new Scene();

                // Camera state
                Camera addCam      = null;
                double imagePlane  = 0;
                double dofAmount   = 0;
                double focalLength = 0;
                Vec4D  focalPoint  = Vec4D.Zero;

                // Primitive state
                IObject obj = null;

                List <Primitive> prims           = new List <Primitive>();
                bool             twoSided        = true;
                bool             invert          = false;
                DoubleColor      emission        = DoubleColor.Placeholder;
                DoubleColor      diffuse         = DoubleColor.Placeholder;
                DoubleColor      specular        = DoubleColor.Placeholder;
                double           shininess       = -1;
                DoubleColor      refraction      = DoubleColor.Placeholder;
                double           refractionIndex = -1;

                stack    = new MatrixStack();                   // Transform stack
                invStack = new MatrixStack();                   // Inverse transforms

                List <Vec4D>  vertices        = new List <Vec4D>();
                List <Vertex> verticesNormals = new List <Vertex>();

                int lineNum = 1;

                while (!reader.EndOfStream)
                {
                    string line        = reader.ReadLine();
                    var    lineMatched = lineRegex.Match(line);

                    if (!lineMatched.Success)
                    {
                        throw new Exception("Line did not match expected format.");
                    }

                    // Line is blank
                    if (lineMatched.Groups[1].Captures.Count > 0)
                    {
                        // Grab the command name from the first capture group.
                        string cmd = lineMatched.Groups[1].Value.ToLowerInvariant();

                        // Pull all the parameters from the matched groups after the command name.
                        paramEnum = lineMatched.Groups.Values.Skip(2).SelectMany((g) => g.Captures).Select((c) => c.Value).GetEnumerator();

#if !DEBUG
                        try
#endif
                        {
                            Vec4D pos;

                            switch (cmd)
                            {
                            case "size":
                                outScene.Width  = NextInt();
                                outScene.Height = NextInt();
                                break;

                            case "background":
                                outScene.BackgroundRGB   = NextRGB();
                                outScene.BackgroundAlpha = NextDbl();
                                break;

                            case "ambient":
                                outScene.AmbientRGB = Next() switch
                                {
                                    "miss" => DoubleColor.Placeholder,
                                    "color" => NextRGB(),
                                    _ => throw new Exception($"Unknown ambient type {paramEnum.Current}."),
                                };
                                break;

                            case "recursion":
                            case "bounce":
                                outScene.Recursion = NextInt();
                                break;

                            case "debug":
                                outScene.DebugGeom = Next() switch
                                {
                                    "geom" => true,
                                    "off" => false,
                                    _ => throw new Exception($"Unknown debug type {paramEnum.Current}."),
                                };
                                break;

                            // Cameras:
                            case "dof":
                                imagePlane = NextDbl();
                                dofAmount  = NextDbl();

                                switch (Next())
                                {
                                case "at":
                                    focalPoint  = NextVecTransf();
                                    focalLength = 0;
                                    break;

                                case "to":
                                    focalLength = NextDbl();
                                    focalPoint  = Vec4D.Zero;
                                    break;

                                case "camera":
                                    focalLength = 0;
                                    focalPoint  = Vec4D.Zero;
                                    break;

                                default:
                                    throw new Exception($"Unknown dof focal command {paramEnum.Current}.");
                                }

                                break;

                            case "camera":
                            case "frustum":
                            case "orthographic":
                                pos = NextVec(1);
                                Vec4D lookAt = NextVec(1);
                                Vec4D up     = Transf(NextVec(0) + pos);
                                pos = Transf(pos);
                                up -= pos;

                                if (cmd == "orthographic")
                                {
                                    addCam = new OrthoCamera(pos, lookAt, up, NextDbl());
                                }
                                else
                                {
                                    addCam = new FrustumCamera(pos, lookAt, up, NextDbl());
                                }
                                break;

                            // Materials:
                            case "twosided":
                                twoSided = NextBool();
                                break;

                            case "invert":
                                invert = NextBool();
                                break;

                            case "emission":
                                emission = NextRGB();
                                break;

                            case "diffuse":
                                diffuse = NextRGB();
                                break;

                            case "specular":
                                specular = NextRGB();
                                break;

                            case "shininess":
                                shininess = NextDbl();
                                if (paramEnum.MoveNext())
                                {
                                    shininess = Math.Pow(shininess, ParseDbl(paramEnum.Current));
                                }
                                break;

                            case "refraction":
                                if (Next() == "off")
                                {
                                    refraction      = DoubleColor.Placeholder;
                                    refractionIndex = -1;
                                }
                                else
                                {
                                    refraction      = new DoubleColor(ParseDbl(paramEnum.Current), NextDbl(), NextDbl());
                                    refractionIndex = NextDbl();
                                }
                                break;

                            // Transforms:
                            case "translate":
                                Vec4D tVec = NextVec(0);
                                stack.Transform(MatrixTransforms.Translate(tVec.X, tVec.Y, tVec.Z));
                                invStack.InvTransform(MatrixTransforms.Translate(-tVec.X, -tVec.Y, -tVec.Z));
                                break;

                            case "scale":
                                Vec4D sVec = NextVec(0);
                                stack.Transform(MatrixTransforms.Scale(sVec.X, sVec.Y, sVec.Z));
                                invStack.InvTransform(MatrixTransforms.Scale(1 / sVec.X, 1 / sVec.Y, 1 / sVec.Z));
                                break;

                            case "rotate":
                                Vec4D  axis  = NextVec(0);
                                double angle = NextDbl();
                                stack.Transform(MatrixTransforms.Rotate(Consts.toRadians(angle), axis));
                                invStack.InvTransform(MatrixTransforms.Rotate(-Consts.toRadians(angle), axis));
                                break;

                            case "pushtransform":
                                stack.Push();
                                invStack.Push();
                                break;

                            case "poptransform":
                                stack.Pop();
                                invStack.Pop();
                                break;

                            // Primitives:
                            case "sphere":
                                prims.Add(new Sphere(NextVec(1), NextDbl()));
                                break;

                            case "plane":
                                prims.Add(new Plane(NextDbl(), NextVec(0)));
                                break;

                            case "vertex":
                                vertices.Add(NextVec(1));
                                break;

                            case "tri":
                                Vec4D p0     = vertices[NextInt()];
                                Vec4D p1     = vertices[NextInt()];
                                Vec4D p2     = vertices[NextInt()];
                                bool  mirror = false;

                                if (paramEnum.MoveNext() && paramEnum.Current == "mirrored")
                                {
                                    mirror = true;
                                }

                                Triangle tri = new Triangle(p0, p1, p2, mirror);
                                prims.Add(tri);
                                break;

                            case "vertexnormal":
                                verticesNormals.Add(new Vertex(NextVec(1), NextVec(0)));
                                break;

                            case "trinormal":
                                Vertex   v0      = verticesNormals[NextInt()];
                                Vertex   v1      = verticesNormals[NextInt()];
                                Vertex   v2      = verticesNormals[NextInt()];
                                Triangle triNorm = new Triangle(v0, v1, v2);
                                prims.Add(triNorm);
                                break;

                            // Objects
                            case "cube":
                                pos = NextVec(1);
                                Vec4D size = NextVec(0);
                                Cube  cube = new Cube(pos, size);
                                obj = cube;

                                if (paramEnum.MoveNext())
                                {
                                    switch (paramEnum.Current)
                                    {
                                    case "all":
                                        prims.AddRange(cube.GetChildren(Cube.AllSides));
                                        break;

                                    case "only":
                                        prims.AddRange(cube.GetChildren(ReadAll().Aggregate(Cube.NoSides, (sides, name) => sides | Cube.GetSide(name))));
                                        break;

                                    case "not":
                                        prims.AddRange(cube.GetChildren(ReadAll().Aggregate(Cube.AllSides, (sides, name) => sides & ~Cube.GetSide(name))));
                                        break;

                                    default:
                                        throw new Exception("Unknown option provided for cube construction: " + paramEnum.Current);
                                    }
                                }

                                prims.AddRange(obj.GetChildren(ObjectConsts.ImplicitInstance));
                                break;

                            // Instancing:
                            case "instance":
                                // Add instances from the previously assigned object (primitive group).
                                prims.AddRange(ReadAll().SelectMany((s) => obj.GetChildren(s)));
                                break;

                            // Other:
                            case "maxverts":
                                break;

                            case "maxvertnorms":
                                break;

                            default:
                                Trace.WriteLine("Unknown command: " + cmd);
                                break;
                            }

                            if (addCam != null)
                            {
                                addCam.imagePlane = imagePlane;
                                addCam.dofAmount  = dofAmount;

                                if (focalPoint != Vec4D.Zero)
                                {
                                    addCam.focalLength = (focalPoint - addCam.position).Length;
                                }
                                else if (focalLength != 0)
                                {
                                    addCam.focalLength = focalLength;
                                }
                                else
                                {
                                    addCam.focalLength = (addCam.initLookAt - addCam.position).Length;
                                }

                                outScene.Cameras.Add(addCam);
                                addCam = null;
                            }

                            foreach (Primitive prim in prims)
                            {
                                prim.TwoSided = twoSided;
                                prim.Invert   = invert;

                                if (emission != DoubleColor.Placeholder)
                                {
                                    prim.Emission = emission;
                                }

                                if (diffuse != DoubleColor.Placeholder)
                                {
                                    prim.Diffuse = diffuse;
                                }

                                if (specular != DoubleColor.Placeholder)
                                {
                                    prim.Specular = specular;
                                }
                                if (shininess != -1)
                                {
                                    prim.Shininess = shininess;
                                }

                                if (refraction != DoubleColor.Placeholder)
                                {
                                    prim.Refraction      = refraction;
                                    prim.RefractiveIndex = refractionIndex;
                                }

                                prim.Transform(stack.Peek(), invStack.Peek());

                                outScene.AddPrimitive(prim);
                            }

                            prims.Clear();
                        }
#if !DEBUG
                        catch (Exception e) when(e is Exception || e is FormatException || e is OverflowException || e is IndexOutOfRangeException)
                        {
                            throw new LoaderException(cmd, lineNum, e);
                        }
#endif
                    }

                    lineNum++;
                }

                return(outScene);
            }
            catch (FileNotFoundException e)
            {
            }
            finally
            {
                reader?.Close();
            }

            return(null);
        }
Esempio n. 14
0
 void Awake()
 {
     Instance = this;
 }
 protected override void OnViewChanged()
 {
     base.OnViewChanged();
     //((Control)Root).Size = new Vector2(View.Size.Width, View.Size.Height);
     //Camera = new OrthoCamera
     //{
     //    Width = View.Size.Width,
     //    Height = View.Size.Height,
     //    Position = new Vector3(View.Size.Width / 2f, View.Size.Height / 2f, 0)
     //};
     ((Control)Root).Size = new Vector2(View.GraphicsDevice.Settings.Resolution.Width, View.GraphicsDevice.Settings.Resolution.Height);
     Camera = new OrthoCamera
     {
         Width = View.GraphicsDevice.Settings.Resolution.Width,
         Height = View.GraphicsDevice.Settings.Resolution.Height,
         Position = new Vector3(View.GraphicsDevice.Settings.Resolution.Width / 2f, View.GraphicsDevice.Settings.Resolution.Height / 2f, 0),
         ZNear = 0,
         ZFar = 100
     };
     Application.Log("Screen Resolution: " + View.GraphicsDevice.Settings.Resolution);
 }