Ejemplo n.º 1
0
 /// <summary>
 /// Generates a Landscape which uses Quad Tree spatial partitioning
 /// </summary>
 /// <param name="game">Game Class</param>
 /// <param name="blocksize">Size of each landscape block</param>
 /// <param name="heightmap">Heightmap Asset Name</param>
 /// <param name="camera">Camera Class</param>
 public Landscape(Game game, int blocksize, string heightmap, BasicCamera camera)
     : base(game)
 {
     BlockSize = blocksize;
     HeightMap = heightmap;
     Camera    = camera;
 }
Ejemplo n.º 2
0
        protected override void InitializeScene()
        {
            LayerManager.RegisterLayer("raycast", new Layer(1, 2));
            int hybridLayer = LayerManager.RegisterLayer("hybrid", new Layer(1, 1 | 2));

            LayerManager.RegisterLayer("physics", new Layer(1, 1));


            BasicCamera c = new BasicCamera(
                Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f),
                                                     GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero);

            LoadTestScene(c);
            LoadGameScene(camera);
            Texture bg = null;

            if (!ComesFromMenu)
            {
                bg = TextureLoader.ColorToTexture(Color.Black);
            }

            LoadLoadingScreen(bg);
            LoadTimer = new GeneralTimer(0.0015f, FinalizeLoad, true);
            AddComponent(LoadTimer);
            TextureGenerator.OnProcessFinished += FinishedTexGen;
            LoadTime = Stopwatch.StartNew();
            TextureGenerator.Process();
        }
Ejemplo n.º 3
0
        protected override void OnInitialize()
        {
            base.OnInitialize();

            InitializeUI();

            StaticTaskQueue.TaskQueue.CreateRepeatingTask("AccelRotate", ModelRotate, 15);
            StaticTaskQueue.TaskQueue.CreateRepeatingTask("Animate", ModelAnimate, 1000 / 30);

            _consoleCommands.Register(StaticConsole.Console);

            _camera = new FuncCamera(GraphicsContext, () => _editor.CameraPosition.AsVector())
            {
                ZoomDistance = 4
            };

            _effect          = GraphicsContext.CreateEffect("defaultAmbient.fx");
            _techniqueHandle = _effect.CreateHandle("TVertexAndPixelShader");

            _consoleRenderer = new ConsoleRenderer(GraphicsContext, StaticConsole.Console)
            {
                Visible = false
            };
            _modelRenderer = new EpicModelRenderer(GraphicsContext);
            _modelRenderer.SetMaterials(_editor.Materials);

            _coordinateMarkerRenderer = new CoordinateMarkerRenderer(GraphicsContext);

            GraphicsContext.ClearColour    = Color.CornflowerBlue.ToColor4();
            GraphicsContext.ZBufferEnabled = true;
        }
Ejemplo n.º 4
0
        private void Vitaboy_Load(object sender, EventArgs e)
        {
            Content.Init(@"C:\Program Files\Maxis\The Sims Online\TSOClient\", canvas.GraphicsDevice);

            var content = Content.Get();

            foreach (var binding in content.AvatarBindings.List())
            {
                bindingsList.Items.Add(binding);
            }

            foreach (var outfit in content.AvatarOutfits.List())
            {
                outfitList.Items.Add(outfit);
            }

            foreach (var animation in content.AvatarAnimations.List())
            {
                animationsList.Items.Add(animation);
            }


            _3D    = new _3DLayer();
            Camera = new BasicCamera(canvas.GraphicsDevice, new Vector3(10.0f, 10.0f, 10.0f), new Vector3(5.0f, 5.0f, 5.0f), Vector3.Up);
            Scene  = new _3DScene(canvas.GraphicsDevice, Camera);
            _3D.Add(Scene);
            canvas.Screen.Add(_3D);

            Animator = new Animator();
            Scene.Add(Animator);
        }
Ejemplo n.º 5
0
        protected override void InitializeScene()
        {
            TextureGenerator.Initialize(true);


            BasicCamera mainCamera =
                new BasicCamera(
                    Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f),
                                                         GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero);

            object mc = mainCamera;

            //EngineConfig.LoadConfig("assets/configs/camera_menu.xml", ref mc);
            Add(mainCamera);
            SetCamera(mainCamera);
            menubg = GenerateMenuBackground();
            UiImageRendererComponent bg =
                new UiImageRendererComponent(menubg.Copy(), false, 1, DefaultFilepaths.DefaultUiImageShader);

            GameObject bgobj = new GameObject("BG");

            bgobj.AddComponent(new BackgroundMover());
            bgobj.AddComponent(bg);
            Add(bgobj);
            //Positions are wrong(0.5 => 5) out of the screen because the correct positions are defined in CreateButtonAnimation.
            CreateButton("assets/textures/btn/btn", "Start Game", new Vector2(-5f, 0.5f), new Vector2(0.2f, 0.1f),
                         CreateButtonAnimation(new Vector2(-0.5f, 0.5f), 0), btnStartGame);
            CreateButton("assets/textures/btn/btn", "Credits", new Vector2(-5f, 0.25f), new Vector2(0.2f, 0.1f),
                         CreateButtonAnimation(new Vector2(-0.5f, 0.25f), 0.2f));
            CreateButton("assets/textures/btn/btn", "Exit", new Vector2(-5f, 0.0f), new Vector2(0.2f, 0.1f),
                         CreateButtonAnimation(new Vector2(-0.5f, 0.0f), 0.4f), btnExit);
            DebugConsoleComponent c = DebugConsoleComponent.CreateConsole().GetComponent <DebugConsoleComponent>();

            Add(c.Owner);
        }
Ejemplo n.º 6
0
        //public static int CompareQuadTreeNodesByDistance(QuadTreeNode x, QuadTreeNode y)
        //{
        //  int retval = x.distanceFromCamera.CompareTo(y.distanceFromCamera);
        //  if(retval < 0)
        //    return -1;
        //  if(retval > 0)
        //    return 1;

        //  return 0;
        //}

        public static Matrix CreateDecalViewProjectionMatrix(BasicCamera camera, float cursorSize)
        {
            Matrix decalView = Matrix.CreateLookAt(camera.Position, new Vector3(camera.Target.X, 0f, camera.Target.Z), Vector3.Forward);
            Matrix decalProj = Matrix.CreateOrthographic(cursorSize, cursorSize, camera.NearPlane, camera.FarPlane);

            return(decalView * decalProj);
        }
Ejemplo n.º 7
0
 public WaterPlane(Game game, int w, int h, BasicCamera camera)
     : base(game)
 {
     Camera  = camera;
     _width  = w;
     _height = h;
 }
Ejemplo n.º 8
0
        protected override void InitializeScene()
        {
            Add(DebugConsoleComponent.CreateConsole());
            Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView(
                MathHelper.DegreesToRadians(75f), //Field of View Vertical
                16f / 9f,                         //Aspect Ratio
                0.1f,                             //Near Plane
                1000f);                           //Far Plane

            BasicCamera bc = new BasicCamera(proj, Vector3.Zero);

            Add(bc);                                                     //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events
            SetCamera(bc);                                               //Sets the Camera as the "active" camera that the scene will be rendered from.

            GameObject box = new GameObject(-Vector3.UnitZ * 4, "Box");  //Creating a new Empty GameObject
            LitMeshRendererComponent lmr = new LitMeshRendererComponent( //Creating a Renderer Component
                DefaultFilepaths.DefaultLitShader,                       //The OpenGL Shader used(Unlit and Lit shaders are provided)
                Prefabs.Cube,                                            //The Mesh that is going to be used by the MeshRenderer
                TextureLoader.ColorToTexture(Color.Red),                 //Diffuse Texture to put on the mesh
                1);                                                      //Render Mask (UI = 1 << 30)

            box.AddComponent(lmr);                                       //Attaching the Renderer to the GameObject
            box.AddComponent(new RotateSelfComponent());                 //Adding a component that rotates the Object on the Y-Axis
            Add(box);                                                    //Adding the Object to the Scene.
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Sets the camera of the Scene
 /// </summary>
 /// <param name="c"></param>
 public void SetCamera(BasicCamera c)
 {
     if (c != null)
     {
         Camera = c;
     }
 }
Ejemplo n.º 10
0
 public static void RenderPrimitivs(GraphicsDevice device, BasicCamera camera)
 {
     for (int i = 0; i < Componates.Count; i++)
     {
         Componates[i].InternalRenderPrimitives(device, camera);
     }
 }
Ejemplo n.º 11
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            Globals.ObjectAdded    += OnObjectAdded;
            Globals.ObjectSelected += OnObjectSelected;
            Globals.ObjectRemoved  += OnObjectRemoved;
            Globals.Draw           += OnDraw;
            Globals.Update         += OnUpdate;

            // Store this for quick access to our drop down pgrid editors
            Globals.RenderWindow = this;

            Camera          = new BasicCamera(Globals.Game);
            Camera.Position = new Vector3(0, 1, 50);

            // Create our Resolution Ruler Marks
            SceneMarkers = new ResolutionMarkers(Globals.Game);
            SceneMarkers.Initialize();

            // Create our Scene Manager
            SceneManager = new SceneManager(Globals.Game);
            SceneManager.Initialize();

            // Create our Game Screen for Rendering
            RenderWindow = new RendererWindow(Globals.Game);

            // Add our Game Screen for rendering to it
            SceneManager.Load(RenderWindow);
        }
Ejemplo n.º 12
0
        private void LoadTestScene(BasicCamera c)
        {
            camera = c;

            GameEngine.Instance.CurrentScene.Add(camera);
            GameEngine.Instance.CurrentScene.SetCamera(camera);

            DebugConsoleComponent dbg = DebugConsoleComponent.CreateConsole().GetComponent <DebugConsoleComponent>();

            dbg.AddCommand("reload", cmd_ReLoadScene);
            dbg.AddCommand("mov", cmd_Move);
            dbg.AddCommand("rot", cmd_Rotate);
            GameEngine.Instance.CurrentScene.Add(dbg.Owner);

            WFCMapGenerator preview = WFCMapGenerator
                                      .CreateWFCPreview(Vector3.Zero, "assets/WFCTiles", false,
                                                        (input) => CreateMap(input, DefaultFilepaths.DefaultLitShader))
                                      .GetComponent <WFCMapGenerator>();

            preview.Height = 256;
            preview.Width  = 32;

            int tries = 1;

            Add(preview.Owner);
            preview.Generate(1);

            while (!preview.Success)
            {
                Logger.Log(DebugChannel.Log | DebugChannel.Game, "Generating map Try " + tries, 8);
                preview.Generate(1);
                tries++;
            }
        }
Ejemplo n.º 13
0
        public static Vector3 CalcPosOnPlane(GraphicsDevice Device, BasicCamera Camera, float X, float Y)
        {
            Vector3 nearsource = new Vector3(X, Y, 0f);
            Vector3 farsource  = new Vector3(X, Y, 1f);

            Vector3 nearPoint = Device.Viewport.Unproject(nearsource, Camera.Projection, Camera.View, Matrix.Identity);
            Vector3 farPoint  = Device.Viewport.Unproject(farsource, Camera.Projection, Camera.View, Matrix.Identity);

            Vector3 direction = farPoint - nearPoint;

            // Normalize our result
            direction.Normalize();

            Ray ray = new Ray(nearPoint, direction);

            float?result = ray.Intersects(new Plane(Vector3.Up, 0));

            if (result != null)
            {
                Vector3 temp = direction * result.Value;

                Vector3 final = Camera.Position + temp;

                return(final);
            }

            return(Vector3.Zero);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Generates a Landscape which uses Quad Tree spatial partitioning.
 /// </summary>
 /// <param name="game">Game Class</param>
 /// <param name="blockSize" value="int" remarks="Must be in powers of 2">Size of each block of landscape in the Qaud Tree</param>
 /// <param name="width" value="int" remarks="Must be in powers of 2">Total width of landscape</param>
 /// <param name="height" value="int" remarks="Must be in powers of 2">Total height of landscape</param>
 /// <param name="camera" value="CTBaseCamera">Camera Class</param>
 public Landscape(Game game, int blockSize, int width, int height, BasicCamera camera)
     : base(game)
 {
     Camera    = camera;
     Height    = height;
     Width     = width;
     BlockSize = blockSize;
 }
Ejemplo n.º 15
0
    // Start is called before the first frame update
    void Start()
    {
        thePlayer = FindObjectOfType <PlayerController>();
        thePlayer.transform.position = transform.position;

        theCamera = FindObjectOfType <BasicCamera>();
        theCamera.transform.position = new Vector3(transform.position.x, transform.position.y, theCamera.transform.position.z);
    }
Ejemplo n.º 16
0
 /// <summary>
 /// Generates a Landscape which uses Quad Tree spatial partitioning.
 /// </summary>
 /// <param name="game">Game Class</param>
 /// <param name="blockSize">Size of each block of the landscape in the Quad Tree</param>
 /// <param name="stream">Memory Stream of the Heightmap to generate</param>
 /// <param name="camera">Camera Class</param>
 public Landscape(Game game, int blockSize, Stream stream, BasicCamera camera)
     : base(game)
 {
     // Load heightmap from stream
     Camera          = camera;
     BlockSize       = blockSize;
     HeightMapStream = stream;
 }
        public conCameraSettings(BasicCamera cam)
        {
            InitializeComponent();

            pgCamera.SelectedObject = cam;

            SetGuid("6ff4f13d-5442-4f1d-a433-4e4b7c39c038");
        }
Ejemplo n.º 18
0
        /// <summary>
        ///     デバイスマネージャと設定を指定して新しいShellウィンドウを作成します.
        /// </summary>
        public ShellWindow(
            GraphicDeviceManager deviceManager,
            ShellHookWindow shellHook,
            ShellGlobalConfig globalConfig)
        {
            ShowActivated = false;

            _deviceManager = deviceManager;
            _shellHook     = shellHook;
            _globalConfig  = globalConfig;

            globalConfig.Substituted += globalConfig_Substituted;

            // フックの登録
            shellHook.WindowActivated += shellHook_WindowActivated;

            // ウィンドウサイズの決定
            var wndSize = new Size(1, 1);

            ////
            // 描画用コンテキストの準備
            // レンダーコンテキストの作成
            _renderContext = RenderContext.CreateContext(deviceManager);
            // GDI互換コンテクストの初期化
            _gdiContext = new GdiCompatibleContext(deviceManager);
            _gdiContext.TargetsInitialized += context_TargetsInitialized;
            _gdiContext.TargetsDestroying  += context_TargetsDestroying;
            // MMF描画コンテクストの初期化
            var camera     = new BasicCamera(new Vector3(0, 0, -1000), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            var projection = new OrthogonalProjectionMatrixProvider();

            projection.InitializeProjection(
                wndSize.Width / globalConfig.PixelPerUnitLength,
                wndSize.Height / globalConfig.PixelPerUnitLength, 1, 2000);
            var matrixManager = new MatrixManager(new BasicWorldMatrixProvider(), camera, projection);

            _textureTargetContext = new TextureTargetContext(_renderContext, matrixManager, wndSize,
                                                             new SampleDescription(globalConfig.MultiSampleCount, globalConfig.MultiSampleQuality))
            {
                BackgroundColor = new Color4(0)
            };
            _renderContext.LightManager = new LightMatrixManager(_textureTargetContext.MatrixManager);
            _renderContext.Timer        = new MotionTimer(_renderContext);
            _renderContext.UpdateRequireWorlds.Add(_textureTargetContext.WorldSpace);

            // ウィンドウサイズの適用
            Size    = wndSize;
            Opacity = _globalConfig.Opacity;

            // 追加のフラグを指定して作成
            WindowStylesEx extra = WindowStylesEx.ToolWindow | WindowStylesEx.TopMost;

            if (globalConfig.PerviousMouse)
            {
                extra |= WindowStylesEx.Transparent;
            }
            base.Create(extra);
        }
Ejemplo n.º 19
0
        protected override void InitializeScene()
        {
            Add(DebugConsoleComponent.CreateConsole());
            Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView(
                MathHelper.DegreesToRadians(75f), //Field of View Vertical
                16f / 9f,                         //Aspect Ratio
                0.1f,                             //Near Plane
                1000f);                           //Far Plane

            BasicCamera bc = new BasicCamera(proj, Vector3.Zero);

            Add(bc);       //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events
            SetCamera(bc); //Sets the Camera as the "active" camera that the scene will be rendered from.



            int          texWidth  = 128;    //Width of the input texture
            int          texHeight = 128;    //Height of the input texture
            MemoryBuffer buffer    =         //Creating the Input Buffer
                                     Clapi.CreateEmpty <byte>(
                Clapi.MainThread,            //We use the Main thread instance
                texWidth * texHeight * 4,    //The image size in bytes
                MemoryFlag.ReadWrite);       //We want to read and write to the texture

            Interpreter i = new Interpreter( //Creating an interpreter instance
                Clapi.MainThread,            //We use the main thread
                "assets/filter/red.fl",      //The file to execute
                DataTypes.Uchar1,            //The Data type of our input buffer
                buffer,                      //The buffer
                texWidth,                    //Width
                texHeight,                   //Height
                1,                           //Depth, for images always 1
                4,                           //Channel count(BGRA)
                "assets/kernel/",            //Directory for all kernels
                true);                       //the "brk" statement is ignored.

            do
            {
                i.Step(); //Step through the Instructions one by one until the script terminated.
            } while (!i.Terminated);


            //Create a texture from the output.
            Texture tex = TextureLoader.BytesToTexture(i.GetResult <byte>(), texWidth, texHeight);


            GameObject box = new GameObject(-Vector3.UnitZ * 4, "Box");  //Creating a new Empty GameObject
            LitMeshRendererComponent lmr = new LitMeshRendererComponent( //Creating a Renderer Component
                DefaultFilepaths.DefaultLitShader,                       //The OpenGL Shader used(Unlit and Lit shaders are provided)
                Prefabs.Cube,                                            //The Mesh that is going to be used by the MeshRenderer
                tex,                                                     //Diffuse Texture to put on the mesh
                1);                                                      //Render Mask (UI = 1 << 30)

            box.AddComponent(lmr);                                       //Attaching the Renderer to the GameObject
            box.AddComponent(new RotatingComponent());                   //Adding a component that rotates the Object on the Y-Axis
            Add(box);                                                    //Adding the Object to the Scene.
        }
Ejemplo n.º 20
0
        public void Test()
        {
            Camera          = new BasicCamera(this);
            Camera.Position = new Vector3(0, 5, -20);
            Components.Add(Camera);


            Run();
        }
Ejemplo n.º 21
0
        protected override void InitializeScene()
        {
            Add(DebugConsoleComponent.CreateConsole());
            BasicCamera bc =
                new BasicCamera(
                    Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75), 16 / 9f, 0.1f, 1000f),
                    new Vector3(0, 5, 7)); //Creating a Basic Camera

            SetCamera(bc);
            Add(bc);
            bc.AddComponent(new MouseTrackerComponent());

            GameObject box = new GameObject(Vector3.UnitX * 3, "Box");
            LitMeshRendererComponent boxlmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader,
                                                                           Prefabs.Cube,
                                                                           TextureLoader.ColorToTexture(Color.Red), 1);

            box.AddComponent(boxlmr);
            Add(box);

            GameObject box2 = new GameObject(Vector3.UnitX * -3, "Box");
            LitMeshRendererComponent box2lmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader,
                                                                            Prefabs.Cube,
                                                                            TextureLoader.ColorToTexture(Color.Red), 1);

            box2.AddComponent(box2lmr);
            Add(box2);

            //Creating the Collider Shapes
            Entity boxShape = new Box(
                Physics.BEPUutilities.Vector3.Zero,
                2f,
                2f,
                2f);

            Entity box2Shape = new Box(
                Physics.BEPUutilities.Vector3.Zero,
                2f,
                2f,
                2f);


            //Creating A physics layer to be able to control which objects are meant to collide with each other
            int raycastLayerID = LayerManager.RegisterLayer("raycast", new Layer(1, 1));

            //Creating the Components for the Physics Engine
            //Note: There are different ways to get the LayerID than storing it.
            Collider boxCollider  = new Collider(boxShape, raycastLayerID);
            Collider box2Collider = new Collider(box2Shape, LayerManager.LayerToName(raycastLayerID));


            //Adding the Components
            box.AddComponent(boxCollider);
            box2.AddComponent(box2Collider);
            //Making the Camera LookAt the origin
            bc.LookAt(Vector3.Zero);
        }
Ejemplo n.º 22
0
        public RenderEngine(int height, int width, string title, Vector3?cameraPos = null)
            : base(new GameWindowSettings(), new NativeWindowSettings() { Size = new Vector2i(width, height), Title = title })
        {
            Stopwatch = new Stopwatch();
            Stopwatch.Start();

            Camera       = new BasicCamera(cameraPos ?? new Vector3(1, 1, 1), width / (float)height, this);
            FrameLimiter = new FrameLimiter(120, true);
        }
Ejemplo n.º 23
0
        public UI3DDGRP(uint guid) : base(guid)
        {
            Camera = new BasicCamera(GameFacade.GraphicsDevice, new Vector3(3, 1, 0), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            Scene  = new _3DScene(GameFacade.GraphicsDevice, Camera);
            var cube = new _3DCube(Color.Red, new Vector3(1, 0.1f, 1));

            cube.Position = new Vector3(-0.5f, -0.1f, -0.5f);
            Scene.Add(cube);
            Scene.Initialize(GameFacade.Scenes);
        }
Ejemplo n.º 24
0
        private MatrixManager InitializeMatricies()
        {
            BasicCamera Camera = new BasicCamera(new Vector3(0, 20, -40), new Vector3(0, 3, 0), new Vector3(0, 1, 0));
            BasicProjectionMatrixProvider Projection = new BasicProjectionMatrixProvider();

            Projection.InitializeProjection((float)Math.PI / 4f, 1.618f, 1, 2000);
            MatrixManager matrixManager = new MatrixManager(new BasicWorldMatrixProvider(), Camera, Projection);

            this.LightManager = new LightMatrixManager(matrixManager);
            return(matrixManager);
        }
Ejemplo n.º 25
0
        public void Test()
        {
            camera          = new BasicCamera(this);
            camera.Position = new Vector3(-50, 25, 50);
            Components.Add(camera);

            barnModel = new Model(this, "barn_rev3", camera);
            Components.Add(barnModel);

            Run();
        }
Ejemplo n.º 26
0
        public UI3DThumb(VMEntity ent)
        {
            Camera           = new BasicCamera(GameFacade.GraphicsDevice, new Vector3(3, 1, 0), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            Camera.NearPlane = 0.001f;
            Scene            = new _3DTargetScene(GameFacade.GraphicsDevice, Camera, new Point(150, 150), 0);
            Scene.Initialize(GameFacade.Scenes);

            if (Comp3D != null)
            {
                foreach (var e in Comp3D)
                {
                    e.Dispose();
                    Scene.Remove(e);
                }
            }
            Comp3D = new List <Debug3DDGRPComponent>();

            BoundingBox?total = null;
            var         pos   = ent.MultitileGroup.GetBasePositions();
            var         i     = 0;

            foreach (var obj in ent.MultitileGroup.Objects)
            {
                var c    = new Debug3DDGRPComponent();
                var dgrp = ((ObjectComponent)obj.WorldUI).DGRP;
                c.Mesh = (dgrp == null) ? null : Content.Content.Get().RCMeshes.Get(dgrp, obj.Object.OBJ); //new DGRP3DMesh(((ObjectComponent)obj.WorldUI).DGRP, obj.Object.OBJ, GameFacade.GraphicsDevice, null);
                Scene.Add(c);
                if (c.Mesh == null)
                {
                    i++;
                    continue;
                }

                var vp = pos[i++];
                c.Position = new Vector3((vp.X - 0.5f), vp.Z, (vp.Y - 0.5f));
                if (total == null)
                {
                    total = OffsetBox(c.Mesh.Bounds ?? new BoundingBox(), c.Position);
                }
                else
                {
                    total = BoundingBox.CreateMerged(total.Value, OffsetBox(c.Mesh.Bounds ?? new BoundingBox(), c.Position));
                }
                c.Initialize();
                Comp3D.Add(c);
            }

            if (total != null)
            {
                Ctr = new Vector3((total.Value.Max.X + total.Value.Min.X) / 2, (total.Value.Max.Y + total.Value.Min.Y) / 2, (total.Value.Max.Z + total.Value.Min.Z) / 2);
                var diag = total.Value.Max - total.Value.Min;
                Size = diag.Length();
            }
        }
Ejemplo n.º 27
0
        public HighwayView(ClientResourceLocator locator)
        {
            m_resources = new ClientResourceManager(locator);

            m_lVolColor = Color.HSVtoRGB(new Vector3(Plugin.Config.GetInt(NscConfigKey.Laser0Color) / 360.0f, 1, 1));
            m_rVolColor = Color.HSVtoRGB(new Vector3(Plugin.Config.GetInt(NscConfigKey.Laser1Color) / 360.0f, 1, 1));

            Camera = new BasicCamera();
            Camera.SetPerspectiveFoV(60, Window.Aspect, 0.01f, 1000);

            m_renderables.Fill(() => new Dictionary <ChartObject, ObjectRenderable3D>());
        }
Ejemplo n.º 28
0
        public Plane(Game game, MemoryStream heightmap, BasicCamera cam)
            : base(game)
        {
            HeightMapStream = heightmap;
            Camera          = cam;

            MaterialColor = Color.White;
            AmbientColor  = Color.Black;
            DiffuseColor  = Color.White;
            SpecularColor = Color.Black;
            EmissiveColor = Color.Black;
        }
Ejemplo n.º 29
0
        protected override void InitializeScene()
        {
            int rayLayer     = LayerManager.RegisterLayer("raycast", new Layer(1, 2));
            int hybLayer     = LayerManager.RegisterLayer("hybrid", new Layer(1, 1 | 2));
            int physicsLayer = LayerManager.RegisterLayer("physics", new Layer(1, 1));

            LayerManager.DisableCollisions(rayLayer, physicsLayer);

            PhysicsDemoComponent phys = new PhysicsDemoComponent();

            AddComponent(phys); //Adding Physics Component to world.


            Add(DebugConsoleComponent.CreateConsole());

            GameObject bgObj = new GameObject(Vector3.UnitY * -3, "BG");

            bgObj.Scale = new Vector3(250, 1, 250);
            bgObj.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Cube,
                                                         TextureLoader.ColorToTexture(Color.Brown), 1));
            Collider groundCol = new Collider(new Box(Vector3.Zero, 500, 1, 500), hybLayer);

            bgObj.AddComponent(groundCol);
            Add(bgObj);

            GameObject boxO = new GameObject(Vector3.UnitY * 3, "Box");

            boxO.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Cube,
                                                        TextureLoader.ColorToTexture(Color.DarkMagenta), 1));
            boxO.AddComponent(new Collider(new Box(Vector3.Zero, 1, 1, 1), physicsLayer));
            boxO.Translate(new Vector3(55, 0, 35));
            Add(boxO);


            GameObject mouseTarget = new GameObject(Vector3.UnitY * -3, "BG");

            mouseTarget.Scale = new Vector3(1, 1, 1);
            mouseTarget.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Sphere,
                                                               TextureLoader.ColorToTexture(Color.GreenYellow), 1));

            Add(mouseTarget);


            BasicCamera c = new BasicCamera(
                Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f),
                                                     GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero);

            c.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(-25));
            c.Translate(new Vector3(1, 30, 45));
            c.AddComponent(new CameraRaycaster(mouseTarget, boxO));
            GameEngine.Instance.CurrentScene.Add(c);
            GameEngine.Instance.CurrentScene.SetCamera(c);
        }
Ejemplo n.º 30
0
        public ScreenContext CreateScreenContext(Control control)
        {
            BasicCamera camera = new BasicCamera(new Vector3(0, 20, -40), new Vector3(0, 3, 0), new Vector3(0, 1, 0));
            BasicProjectionMatrixProvider projection = new BasicProjectionMatrixProvider();

            projection.InitializeProjection((float)Math.PI / 4f, 1.618f, 1, 200);
            MatrixManager matrixManager = new MatrixManager(new BasicWorldMatrixProvider(), camera, projection);
            ScreenContext context       = new ScreenContext(control, this, matrixManager);

            this.screenContexts.Add(control, context);

            return(context);
        }
Ejemplo n.º 31
0
        // Gets the picking ray
        public static Ray getPickingRay(ref BasicCamera cam, ref Viewport viewport)
        {
            // Variables
            double[]	mdlv=	new double[16];
            double[]	proj=	new double[16];
            int[]	v=	new int[4];
            double	mx, my;
            double	nx, ny, nz;
            double	fx, fy, fz;
            MouseState	mouse=	GameInput.getMouseState();
            Ray	ray;

            Gl.glGetDoublev(Gl.GL_PROJECTION_MATRIX, proj);
            Gl.glGetDoublev(Gl.GL_MODELVIEW_MATRIX, mdlv);
            Gl.glGetIntegerv(Gl.GL_VIEWPORT, v);
            mx=	(double)mouse.x;
            my=	(double)v[3]-(double)mouse.y;

            Glu.gluUnProject(mx, my, 0f, mdlv, proj, v, out nx, out ny, out nz);
            Glu.gluUnProject(mx, my, 1f, mdlv, proj, v, out fx, out fy, out fz);

            ray=	new Ray(new Point3f((float)nx, (float)ny, (float)nz), new Point3f((float)fx, (float)fy, (float)fz));

            return ray;
        }