Пример #1
0
        protected override void Init()
        {
            _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent;
            _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent;

            _meshComponent.MeshResourceName = "cube";
        }
Пример #2
0
        protected override void Init()
        {
            /* todo: re-use rendercomponent, like cube !! */
            _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent;
            _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent;

            Rings = 16;
            Segments = 16;
        }
Пример #3
0
        protected override void Init()
        {
            _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent;
            _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent;
            _textComponent = Components.Single(c => c.Id == TextComponentId) as TextComponent;
            _textComponent.FontName = "bmpfont";
            _meshComponent.Material.TextureName = "bmpfont_0.text";

            DistanceSorting = true;
        }
Пример #4
0
        public override bool InternalLoad()
        {
            base.InternalLoad();

            _renderComponent = GameObject.Components.FirstOrDefault(c => c is MeshRenderComponent) as MeshRenderComponent;
            _meshComponent = GameObject.Components.FirstOrDefault(c => c is MeshComponent) as MeshComponent;
            _rigidBodyComponent = GameObject.Components.FirstOrDefault(c => c is RigidBodyBaseComponent) as RigidBodyBaseComponent;

            /* loaded if textcomponent is found */
            return _renderComponent != null && _meshComponent != null;
        }
Пример #5
0
        protected override void Init()
        {
            /* todo: re-use rendercomponent, like cube !! */
            _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent;
            _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent;
            _rigidBodyComponent = Components.Single(c => c.Id == RigidBodyFarseerComponentId) as RigidBodyFarseerComponent;
            _sphereColliderComponent = Components.Single(c => c.Id == SphereColliderFarseerComponentId) as SphereColliderFarseerComponent;

            Rings = 16;
            Segments = 16;
        }
Пример #6
0
        public override bool InternalLoad()
        {
            base.InternalLoad();

            _meshComponent = GameObject.Components.FirstOrDefault(c => c is MeshComponent) as MeshComponent;

            _ambientAlpha = _meshComponent.Material.Ambient.W;
            _diffuseAlpha = _meshComponent.Material.Diffuse.W;
            _specularAlpha = _meshComponent.Material.Specular.W;

            return true;
        }
Пример #7
0
        public Cube(float depth, float height, float width)
        {
            Depth = depth;
            Height = height;
            Width = width;

            var halfWidth = Width / 2.0f;
            var halfHeight = Height / 2.0f;
            var halfDepth = Depth / 2.0f;

            _meshComponent = new MeshComponent(this);

            /* create cube vertices */
            var vertices = new Vector3[8];
            vertices[0] = new Vector3(-halfWidth, -halfHeight, halfDepth);
            vertices[1] = new Vector3(halfWidth, -halfHeight, halfDepth);
            vertices[2] = new Vector3(halfWidth, halfHeight, halfDepth);
            vertices[3] = new Vector3(-halfWidth, halfHeight, halfDepth);
            vertices[4] = new Vector3(-halfWidth, -halfHeight, -halfDepth);
            vertices[5] = new Vector3(halfWidth, -halfHeight, -halfDepth);
            vertices[6] = new Vector3(halfWidth, halfHeight, -halfDepth);
            vertices[7] = new Vector3(-halfWidth, halfHeight, -halfDepth);

            /* create indices */
            var indices = new short[]{
             // front face
                0, 1, 2, 2, 3, 0,
                // top face
                3, 2, 6, 6, 7, 3,
                // back face
                7, 6, 5, 5, 4, 7,
                // left face
                4, 0, 3, 3, 7, 4,
                // bottom face
                0, 1, 5, 5, 4, 0,
                // right face
                1, 5, 6, 6, 2, 1 };

            _meshComponent.Vertices = vertices;
            _meshComponent.Indices = indices;

            _meshComponent.CalculateNormals();

             AddComponent(_meshComponent);

            _meshRenderComponent = new MeshRenderComponent(this);

            AddComponent(_meshRenderComponent);
        }
Пример #8
0
        protected override void Init()
        {
            base.Init();

            _rigidBodyComponent = this.Components.Single(c => c is RigidBodyFarseerComponent) as RigidBodyFarseerComponent;
            _meshComponent = this.Components.Single(c => c is MeshComponent) as MeshComponent;

            _rigidBodyComponent.IsGravitySource = true;
            _rigidBodyComponent.GravityRange = 1.0f;
            _rigidBodyComponent.IsStatic = true;
            _rigidBodyComponent.Mass = 1000;

            _selectionCube = this.Children.Single(c => c.Id == SelectionCubeId) as Cube;
            _selectionCube.OnMouseDown += SphereMagnet_OnMouseDown;
            _selectionCube.Visible = false;

            _haloPlane = this.Children.Single(c => c.Id == HaloPlaneId) as MagnetHalo;
            _haloPlane.Material.TextureName = "MagnetHalo";

            this.OnScale += new EventHandler<Engine.Events.ScaleEvent>(SphereMagnet_OnScale);
        }
Пример #9
0
        public override void InternalLoad()
        {
            /* find mesh component and load it if needed */

            _meshComponent = GameObject.Components.FirstOrDefault(c => c is MeshComponent) as MeshComponent;
            if (_meshComponent == null) throw new InvalidOperationException("No mesh component to render");

            if (!_meshComponent.IsLoaded) _meshComponent.Load();

            /* create buffers to store vertex data */

            GL.GenBuffers(4, _bufferIds);
            GL.BindBuffer(BufferTarget.ArrayBuffer, _bufferIds[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(_meshComponent.Vertices.Length * (Vector3.SizeInBytes)),
                          _meshComponent.Vertices.ToArray(), BufferUsage.StaticDraw);

            GL.BindBuffer(BufferTarget.ArrayBuffer, _bufferIds[1]);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(_meshComponent.Normals.Length * (Vector3.SizeInBytes)),
                          _meshComponent.Vertices.ToArray(), BufferUsage.StaticDraw);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, _bufferIds[2]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(_meshComponent.Indices.Length * sizeof(short)),
                          _meshComponent.Indices.ToArray(), BufferUsage.StaticDraw);
        }
Пример #10
0
        private void LoadGizmo()
        {
            YDirectionArrow.Scale = new Vector3(1, 3, 1);

            YDirectionArrow.Position = new Vector3(0, ArrowLength, 0);

            var mesh = new MeshComponent();

            var vertices = new Vector3[5];

            vertices[0] = new Vector3(-1, -0.5f, -1);
            vertices[1] = new Vector3(-1, -0.5f, 1);
            vertices[2] = new Vector3(0, 0.5f, 0);
            vertices[3] = new Vector3(1, -0.5f, 1);
            vertices[4] = new Vector3(1, -0.5f, -1);

            var indices = new short[18];
            int index = 0;

            indices[index++] = 0;
            indices[index++] = 1;
            indices[index++] = 2;

            indices[index++] = 1;
            indices[index++] = 3;
            indices[index++] = 2;

            indices[index++] = 3;
            indices[index++] = 4;
            indices[index++] = 2;

            indices[index++] = 4;
            indices[index++] = 0;
            indices[index++] = 2;

            indices[index++] = 3;
            indices[index++] = 1;
            indices[index++] = 0;

            indices[index++] = 0;
            indices[index++] = 4;
            indices[index++] = 3;

            mesh.Vertices = vertices;
            mesh.Indices = indices;
            mesh.UV = new Vector2[vertices.Length];

            mesh.Material.Ambient = new Vector4(0, 0, 1, 1);
            mesh.Material.Diffuse = Vector4.Zero;
            mesh.CalculateNormals();

            var render = new MeshRenderComponent();

            YDirectionArrow.AddComponent(mesh);
            YDirectionArrow.AddComponent(render);

            ZDirectionArrow.Rotation = new Vector3((float)(System.Math.PI / 2.0f), 0, 0);
            ZDirectionArrow.Scale = new Vector3(1, 3, 1);
            ZDirectionArrow.Position = new Vector3(0, 0, ArrowLength);

            var zMesh = new MeshComponent();

            zMesh.Vertices = mesh.Vertices;
            zMesh.Normals = mesh.Normals;
            zMesh.Indices = mesh.Indices;
            zMesh.UV = mesh.UV;
            zMesh.Material.Ambient = new Vector4(1, 0, 0, 1);
            zMesh.Material.Diffuse = Vector4.Zero;

            render = render.CloneForReuse();

            ZDirectionArrow.AddComponent(zMesh);
            ZDirectionArrow.AddComponent(render);

            XDirectionArrow.Rotation = new Vector3(0, 0, -(float)(System.Math.PI / 2.0f));
            XDirectionArrow.Scale = new Vector3(1, 3, 1);
            XDirectionArrow.Position = new Vector3(ArrowLength, 0, 0);

            var xMesh = new MeshComponent();

            xMesh.Vertices = mesh.Vertices;
            xMesh.Normals = mesh.Normals;
            xMesh.Indices = mesh.Indices;
            xMesh.UV = mesh.UV;
            xMesh.Material.Ambient = new Vector4(0, 1, 0, 1);
            xMesh.Material.Diffuse = Vector4.Zero;

            render = render.CloneForReuse();

            XDirectionArrow.AddComponent(xMesh);
            XDirectionArrow.AddComponent(render);

            _xDirection.Scale = new Vector3(ArrowLength, 0.5f, 0.5f);
            _xDirection.Position = new Vector3((ArrowLength / 2.0f) - 0.25f, 0, 0);
            ((Cube)_xDirection).Material.Ambient = new Vector4(0, 1, 0, 1);
            ((Cube)_xDirection).Material.Diffuse = Vector4.Zero;

            _yDirection.Scale = new Vector3(0.5f, ArrowLength, 0.5f);
            _yDirection.Position = new Vector3(0, (ArrowLength / 2.0f) - 0.25f, 0);
            ((Cube)_yDirection).Material.Ambient = new Vector4(0, 0, 1, 1);
            ((Cube)_yDirection).Material.Diffuse = Vector4.Zero;

            _zDirection.Scale = new Vector3(0.5f, 0.5f, ArrowLength);
            _zDirection.Position = new Vector3(0, 0, (ArrowLength / 2.0f) - 0.25f);
            ((Cube)_zDirection).Material.Ambient = new Vector4(1, 0, 0, 1);
            ((Cube)_zDirection).Material.Diffuse = Vector4.Zero;

            Scale = new Vector3(0.1f, 0.1f, 0.1f);

            Designer = true;

            UniformSphere.Material.Ambient = new Vector4(1, 1, 1, 1);
            UniformSphere.Scale = new Vector3(3);
            UniformSphere.Visible = ShowUniformSphere;
            UniformSphere.Enabled = ShowUniformSphere;
        }
Пример #11
0
 protected override void Init()
 {
     _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent;
     _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent;
 }
Пример #12
0
        protected override void Init()
        {
            _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent;
            _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent;
            _rigidBodyComponent = Components.Single(c => c.Id == RigidBodyFarseerComponentId) as RigidBodyFarseerComponent;
            _circleColliderComponent = Components.Single(c => c.Id == CircleColliderFarseerComponentId) as CircleColliderFarseerComponent;
            _fixedRevoluteJoinComponent = Components.Single(c => c.Id == FixedRevoluteJointComponentId) as FixedRevoluteJointComponent;

            _meshComponent.MeshResourceName = "cylinder";
            _meshComponent.Material.TextureName = "fabric";
        }
Пример #13
0
        public override bool InternalLoad()
        {
            /* find mesh component and load it if needed */

            _meshComponent = GameObject.Components.FirstOrDefault(c => c is MeshComponent) as MeshComponent;
            if (_meshComponent == null)
            {
                return false;
            }

            if (!_meshComponent.IsLoaded) _meshComponent.Load();

            int[] cachedBuffers;
            if (!Game.InDesignMode && !string.IsNullOrEmpty(_meshComponent.MeshResourceName) &&
                GameObject.Scene.MeshBufferCache.TryGetValue(_meshComponent.MeshResourceName, out cachedBuffers))
            {
                /* can reuse a rendercomponent + gl buffers */
                _bufferIds = cachedBuffers;
                _isClone = true;
            }
            else if (!_isClone)
            {

                /* create buffers to store vertex data */

                GL.GenBuffers(2, _bufferIds);

                GLVertex[] glVertices = new GLVertex[_meshComponent.Vertices.Length];

                bool hasUV = _meshComponent.UV.Length == _meshComponent.Vertices.Length;

                for (int i = 0; i < glVertices.Length; i++)
                {
                    glVertices[i].X = (short)(_meshComponent.Vertices[i].X * _shortFloatFactor);
                    glVertices[i].Y = (short)(_meshComponent.Vertices[i].Y * _shortFloatFactor);
                    glVertices[i].Z = (short)(_meshComponent.Vertices[i].Z * _shortFloatFactor);
                    glVertices[i].NX = (short)(_meshComponent.Normals[i].X * _shortFloatFactor);
                    glVertices[i].NY = (short)(_meshComponent.Normals[i].Y * _shortFloatFactor);
                    glVertices[i].NZ = (short)(_meshComponent.Normals[i].Z * _shortFloatFactor);

                    if (hasUV)
                    {
                        glVertices[i].U = (short)(_meshComponent.UV[i].X * _shortFloatFactor);
                        glVertices[i].V = (short)(_meshComponent.UV[i].Y * _shortFloatFactor);
                    }
                }

                unsafe
                {
                    fixed (GLVertex* data = glVertices)
                    {
                        GL.BindBuffer(BufferTarget.ArrayBuffer, _bufferIds[0]);
                        GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(glVertices.Length * sizeof(GLVertex)),
                                   (IntPtr)data, BufferUsage.StaticDraw);
                    }

                    fixed (short* data = _meshComponent.Indices.ToArray())
                    {
                        GL.BindBuffer(BufferTarget.ElementArrayBuffer, _bufferIds[1]);
                        GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(_meshComponent.Indices.Length * sizeof(short)),
                              (IntPtr)data, BufferUsage.StaticDraw);
                    }
                }

                if (!Game.InDesignMode && !string.IsNullOrEmpty(_meshComponent.MeshResourceName))
                {
                    GameObject.Scene.MeshBufferCache.Add(_meshComponent.MeshResourceName, _bufferIds);
                }
            }

            return true;
        }
Пример #14
0
        protected override void Init()
        {
            _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent;
            _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent;
            _rigidBodyComponent = Components.Single(c => c.Id == RigidBodyFarseerComponentId) as RigidBodyFarseerComponent;
            _boxColliderComponent = Components.Single(c => c.Id == BoxColliderFarseerComponentId) as BoxColliderFarseerComponent;

            _meshComponent.MeshResourceName = "cube";
        }
Пример #15
0
        protected override void Init()
        {
            base.Init();

            _aimSphere = Children.First(c => c.Id == DisplaySphereId) as Sphere;
            _aimSphere.Name = "aimSphere";
            _aimSphere.Scale = new Vector3(5);
            _aimSphere.Material.Ambient = new Vector4(1, 0, 0, 0.5f);
            _aimSphere.Material.TextureName = "ball";
            _aimSphere.OnMouseDown += new EventHandler<Engine.Events.MouseButtonDownEvent>(_aimSphere_OnMouseDown);
            _aimSphere.OnMouseUp += new EventHandler<Engine.Events.MouseButtonUpEvent>(_aimSphere_OnMouseUp);
            _aimSphere.Visible = false;

            _arrow2d = Children.First(c => c.Id == Arrow2dId) as Arrow2d;

            _lightObject = Children.First(c => c.Id == LightObjectId) as LightObject;
            _lightObject.Visible = false;
            _lightObject.Enabled = false;

            _meshComponent = this.Components.First(c => c is MeshComponent) as MeshComponent;
            _rigidBodyComponent = this.Components.First(c => c is RigidBodyFarseerComponent) as RigidBodyFarseerComponent;

            var circleCollider = this.Components.First(c => c is CircleColliderFarseerComponent) as CircleColliderFarseerComponent;
            //circleCollider.Radius = 0.5f;

            Material.TextureName = "greenball";

            _leftEye = this.Children.First(c => c.Id == LeftEyeId) as Plane;
            _rightEye = this.Children.First(c => c.Id == RightEyeId) as Plane;

            _leftEye.Material.TextureName = "eye";
            _rightEye.Material.TextureName = "eye";

            _leftEye.DistanceSorting = true;
            _rightEye.DistanceSorting = true;

            _leftEye.Position = -_eyePosition;
            _rightEye.Position = _eyePosition;

            _rightEye.Scale = new Vector3(0.1f, 0.1f, 0.1f);
            _leftEye.Scale = new Vector3(0.1f, 0.1f, 0.1f);
        }
Пример #16
0
        protected override void Init()
        {
            base.Init();

            _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent;
            _meshComponent.MeshResourceName = "star";
            _meshComponent.Material.TextureName = "star";

            this.Scale = new Vector3(0.05f, 0.05f, 0.05f);

            var body = Components.Single(c => c is RigidBodyFarseerComponent) as RigidBodyFarseerComponent;
            body.IsSensor = true;

            this.OnObjectCollision += Star_OnObjectCollision;

            _flare = this.Children.Single(c => c.Id == StarFlareId) as StarFlare;
        }