Beispiel #1
0
        // -------------------------------------------------------------------------------
        //
        // -------------------------------------------------------------------------------
        public static bool IsOppositeDirection(Vector3 v1, Vector3 v2)
        {
            DirectionType dir1 = Vector3Helper.CardinalDirection(v1);
            DirectionType dir2 = Vector3Helper.CardinalDirection(v2);

            return(IsOppositeDirection(dir1, dir2));
        }
Beispiel #2
0
            public void Read(Stream s)
            {
                var r = new BinaryReader(s);

                Flags                = r.ReadUInt32();
                IndexX               = r.ReadUInt32();
                IndexY               = r.ReadUInt32();
                Layers               = r.ReadUInt32();
                DoodadRefs           = r.ReadUInt32();
                OffsetMCVT           = r.ReadUInt32();
                OffsetMCNR           = r.ReadUInt32();
                OffsetMCLY           = r.ReadUInt32();
                OffsetMCRF           = r.ReadUInt32();
                OffsetMCAL           = r.ReadUInt32();
                SizeMCAL             = r.ReadUInt32();
                OffsetMCSH           = r.ReadUInt32();
                SizeMCSH             = r.ReadUInt32();
                AreaId               = r.ReadUInt32();
                MapObjectRefs        = r.ReadUInt32();
                Holes                = r.ReadUInt32();
                LowQualityTextureMap = new uint[4];
                for (int i = 0; i < 4; i++)
                {
                    LowQualityTextureMap[i] = r.ReadUInt32();
                }
                PredTex            = r.ReadUInt32();
                NumberEffectDoodad = r.ReadUInt32();
                OffsetMCSE         = r.ReadUInt32();
                SoundEmitters      = r.ReadUInt32();
                OffsetMCLQ         = r.ReadUInt32();
                SizeMCLQ           = r.ReadUInt32();
                Position           = Vector3Helper.Read(s);
                OffsetMCCV         = r.ReadUInt32();
            }
Beispiel #3
0
        public static WorldModelHeader Read(Stream s)
        {
            var r   = new BinaryReader(s);
            var ret = new WorldModelHeader();

            ret.CountMaterials = r.ReadUInt32();
            ret.CountGroups    = r.ReadUInt32();
            ret.CountPortals   = r.ReadUInt32();
            ret.CountLights    = r.ReadUInt32();
            ret.CountModels    = r.ReadUInt32();
            ret.CountDoodads   = r.ReadUInt32();
            ret.CountSets      = r.ReadUInt32();
            ret.AmbientColor   = r.ReadUInt32();
            ret.WmoId          = r.ReadUInt32();
            ret.BoundingBox    = new Vector3[2];
            ret.BoundingBox[0] = Vector3Helper.Read(s);
            ret.BoundingBox[1] = Vector3Helper.Read(s);
            ret.ExtraFlag      = r.ReadUInt16();

            /*
             * _t flag_attenuate_vertices_based_on_distance_to_portal : 1;
             * uint16_t flag_skip_base_color : 1; // do not add base (ambient) color (of MOHD) to MOCVs. apparently does more, e.g. required for multiple MOCVs
             * uint16_t flag_liquid_related : 1; // fills the whole WMO with water (used for underwater WMOs). (possibly - LiquidType related, see below in the MLIQ).
             * uint16_t flag_has_some_outdoor_group : 1; // possibly - has some group that is outdoors
             * uint16_t Flag_Lod : 1;
             */
            ret.numLod = r.ReadUInt16();
            return(ret);
        }
Beispiel #4
0
        public void SetParameters(Material material)
        {
            if (material.InternalEffect != null)
            {
                if (material.InternalEffect is BasicEffect)
                {
                    BasicEffect be = (BasicEffect)material.InternalEffect;

                    alphaEffect.Alpha              = be.Alpha;
                    alphaEffect.DiffuseColor       = be.DiffuseColor;
                    alphaEffect.Texture            = be.Texture;
                    alphaEffect.VertexColorEnabled = be.VertexColorEnabled;
                }
                else
                {
                    Log.Write("Passed internal effect is not BasicEffect, so we can not apply the " +
                              "effect to this shader", Log.LogLevel.Warning);
                }
            }
            else
            {
                alphaEffect.Alpha        = material.Diffuse.W;
                alphaEffect.DiffuseColor = Vector3Helper.GetVector3(material.Diffuse);
                alphaEffect.Texture      = material.Texture;
            }
        }
Beispiel #5
0
        protected override void Initialize()
        {
            base.Initialize();

            textureName = "fire";

            duration           = TimeSpan.FromSeconds(2);
            durationRandomness = 1;

            minHorizontalVelocity = 0;
            maxHorizontalVelocity = 15;

            minVerticalVelocity = -10;
            maxVerticalVelocity = 10;

            // Set gravity upside down, so the flames will 'fall' upward.
            gravity = Vector3Helper.Get(0, 15, 0);

            minColor = new Color(0, 0, 0, 10);
            maxColor = new Color(255, 255, 255, 40);

            minStartSize = 5;
            maxStartSize = 10;

            minEndSize = 10;
            maxEndSize = 40;

            blendState = BlendState.Additive;
        }
Beispiel #6
0
        protected override void Initialize()
        {
            base.Initialize();

            textureName = "smoke";

            duration = TimeSpan.FromSeconds(4);

            minHorizontalVelocity = 0;
            maxHorizontalVelocity = 50;

            minVerticalVelocity = -10;
            maxVerticalVelocity = 50;

            gravity = Vector3Helper.Get(0, -20, 0);

            endVelocity = 0;

            minColor = Color.LightGray;
            maxColor = Color.White;

            minRotateSpeed = -2;
            maxRotateSpeed = 2;

            minStartSize = 10;
            maxStartSize = 10;

            minEndSize = 100;
            maxEndSize = 200;
        }
Beispiel #7
0
        public void Read(Stream s)
        {
            var r = new BinaryReader(s);

            Magic                   = r.ReadBytes(4);
            Version                 = r.ReadUInt32();
            LengthModelName         = r.ReadUInt32();
            OffsetName              = r.ReadUInt32();
            ModelFlags              = r.ReadUInt32();
            CountGlobalSequences    = r.ReadUInt32();
            OffsetGlobalSequences   = r.ReadUInt32();
            CountAnimations         = r.ReadUInt32();
            OffsetAnimations        = r.ReadUInt32();
            CountAnimationLookup    = r.ReadUInt32();
            OffsetAnimationLookup   = r.ReadUInt32();
            CountBones              = r.ReadUInt32();
            OffsetBones             = r.ReadUInt32();
            CountKeyBoneLookup      = r.ReadUInt32();
            OffsetKeyBoneLookup     = r.ReadUInt32();
            CountVertices           = r.ReadUInt32();
            OffsetVertices          = r.ReadUInt32();
            CountViews              = r.ReadUInt32();
            CountColors             = r.ReadUInt32();
            OffsetColors            = r.ReadUInt32();
            CountTextures           = r.ReadUInt32();
            OffsetTextures          = r.ReadUInt32();
            CountTransparency       = r.ReadUInt32();
            OffsetTransparency      = r.ReadUInt32();
            CountUvAnimation        = r.ReadUInt32();
            OffsetUvAnimation       = r.ReadUInt32();
            CountTexReplace         = r.ReadUInt32();
            OffsetTexReplace        = r.ReadUInt32();
            CountRenderFlags        = r.ReadUInt32();
            OffsetRenderFlags       = r.ReadUInt32();
            CountBoneLookup         = r.ReadUInt32();
            OffsetBoneLookup        = r.ReadUInt32();
            CountTexLookup          = r.ReadUInt32();
            OffsetTexLookup         = r.ReadUInt32();
            CountTexUnits           = r.ReadUInt32();
            OffsetTexUnits          = r.ReadUInt32();
            CountTransLookup        = r.ReadUInt32();
            OffsetTransLookup       = r.ReadUInt32();
            CountUvAnimLookup       = r.ReadUInt32();
            OffsetUvAnimLookup      = r.ReadUInt32();
            VertexBox               = new Vector3[2];
            VertexBox[0]            = Vector3Helper.Read(s);
            VertexBox[1]            = Vector3Helper.Read(s);
            VertexRadius            = r.ReadSingle();
            BoundingBox             = new Vector3[2];
            BoundingBox[0]          = Vector3Helper.Read(s);
            BoundingBox[1]          = Vector3Helper.Read(s);
            BoundingRadius          = r.ReadSingle();
            CountBoundingTriangles  = r.ReadUInt32();
            OffsetBoundingTriangles = r.ReadUInt32();
            CountBoundingVertices   = r.ReadUInt32();
            OffsetBoundingVertices  = r.ReadUInt32();
            CountBoundingNormals    = r.ReadUInt32();
            OffsetBoundingNormals   = r.ReadUInt32();
        }
Beispiel #8
0
        public void AddTorque(IPhysicsObject physObj, float timeStep, Vector3 torque)
        {
            if (!objectIDs.ContainsKey(physObj))
            {
                return;
            }

            HavokDllBridge.add_torque(objectIDs[physObj], timeStep, Vector3Helper.ToFloats(torque));
        }
Beispiel #9
0
        public void SetAngularVelocity(IPhysicsObject physObj, Vector3 velocity)
        {
            if (!objectIDs.ContainsKey(physObj))
            {
                return;
            }

            HavokDllBridge.set_angular_velocity(objectIDs[physObj], Vector3Helper.ToFloats(velocity));
        }
Beispiel #10
0
            public void Read(Stream s)
            {
                var r = new BinaryReader(s);
                var startingOffset = s.Position;

                Flags                = (MapChunkHeaderFlags)r.ReadUInt32();
                IndexX               = r.ReadUInt32();
                IndexY               = r.ReadUInt32();
                Layers               = r.ReadUInt32();
                DoodadRefs           = r.ReadUInt32();
                HighResHoleL         = r.ReadUInt32();
                HighResHoleH         = r.ReadUInt32();
                OffsetMCLY           = r.ReadUInt32();
                OffsetMCRF           = r.ReadUInt32();
                OffsetMCAL           = r.ReadUInt32();
                SizeMCAL             = r.ReadUInt32();
                OffsetMCSH           = r.ReadUInt32();
                SizeMCSH             = r.ReadUInt32();
                AreaId               = r.ReadUInt32();
                MapObjectRefs        = r.ReadUInt32();
                LowResHoles          = r.ReadUInt16();
                HolesAlign           = r.ReadUInt16();
                LowQualityTextureMap = new uint[4];
                for (int i = 0; i < 4; i++)
                {
                    LowQualityTextureMap[i] = r.ReadUInt32();
                }
                PredTex            = r.ReadUInt32();
                NumberEffectDoodad = r.ReadUInt32();
                OffsetMCSE         = r.ReadUInt32();
                SoundEmitters      = r.ReadUInt32();
                OffsetMCLQ         = r.ReadUInt32();
                SizeMCLQ           = r.ReadUInt32();
                Position           = Vector3Helper.Read(r.BaseStream);
                OffsetMCCV         = r.ReadUInt32();
                OffsetMCLV         = r.ReadUInt32();
                unused             = r.ReadUInt32();

                //string sigString = "MCVT";
                //var arr = Encoding.ASCII.GetBytes(sigString);
                //Array.Reverse(arr);
                //uint sigInt = BitConverter.ToUInt32(arr, 0);

                long currentPos = s.Position;
                var  sig        = r.ReadUInt32();
                var  size       = r.ReadUInt32();

                while (sig != 0x4D435654 && s.CanRead) // 0x4D435654 = MCVT reversed
                {
                    Console.WriteLine("I had to read more data");
                    s.Position = currentPos + size;
                    currentPos = s.Position;
                    sig        = r.ReadUInt32();
                    size       = r.ReadUInt32();
                }
                MCVTDataOffsetComputed = (uint)(s.Position - startingOffset);
            }
Beispiel #11
0
 // -------------------------------------------------------------------------------
 //
 // -------------------------------------------------------------------------------
 private void OnTurned()
 {
     facingDirection = Vector3Helper.CardinalDirection(transform.forward);
     if (!Finder.battle.InBattle)
     {
         enabled = true;
     }
     changedDirection = true;
     OnPlayerTurned();
 }
 public virtual void SetParameters(GoblinXNA.Graphics.Environment environment)
 {
     basicEffect.FogEnabled = environment.FogEnabled;
     if (environment.FogEnabled)
     {
         basicEffect.FogStart = environment.FogStartDistance;
         basicEffect.FogEnd   = environment.FogEndDistance;
         basicEffect.FogColor = Vector3Helper.GetVector3(environment.FogColor);
     }
 }
Beispiel #13
0
        private void ReadBoundingNormals(Stream s)
        {
            s.Seek(Header.OffsetBoundingNormals, SeekOrigin.Begin);

            Normals = new Vector3[Header.CountBoundingNormals];
            for (int i = 0; i < Header.CountBoundingNormals; i++)
            {
                Normals[i] = Vector3Helper.Read(s);
            }
        }
Beispiel #14
0
        private void ReadVertices(Stream s)
        {
            s.Seek(Header.OffsetBoundingVertices, SeekOrigin.Begin);

            Vertices = new Vector3[Header.CountBoundingVertices];
            for (int i = 0; i < Header.CountBoundingVertices; i++)
            {
                Vertices[i] = Vector3Helper.Read(s);
            }
        }
        public void SetParameters(Material material)
        {
            if (material.InternalEffect != null)
            {
                if (material.InternalEffect is BasicEffect)
                {
                    internalEffect       = (BasicEffect)material.InternalEffect;
                    internalEffect.Alpha = originalAlphas[internalEffect] * material.Diffuse.W;
                    if (MixMaterialDiffuseWithTexture)
                    {
                        internalEffect.DiffuseColor *= Vector3Helper.GetVector3(material.Diffuse);
                    }

                    if (lightsChanged)
                    {
                        internalEffect.LightingEnabled        = basicEffect.LightingEnabled;
                        internalEffect.PreferPerPixelLighting = basicEffect.PreferPerPixelLighting;
                        internalEffect.AmbientLightColor      = basicEffect.AmbientLightColor;
                        if (basicEffect.LightingEnabled)
                        {
                            DirectionalLight[] lights = { internalEffect.DirectionalLight0,
                                                          internalEffect.DirectionalLight1, internalEffect.DirectionalLight2 };

                            int numLightSource = lightSources.Count;
                            for (int i = 0; i < numLightSource; i++)
                            {
                                lights[i].Enabled       = true;
                                lights[i].DiffuseColor  = Vector3Helper.GetVector3(lightSources[i].Diffuse);
                                lights[i].Direction     = lightSources[i].Direction;
                                lights[i].SpecularColor = Vector3Helper.GetVector3(lightSources[i].Specular);
                            }
                            for (int i = numLightSource; i < MaxLights; i++)
                            {
                                lights[i].Enabled = false;
                            }
                        }
                    }
                }
                else
                {
                    Log.Write("Passed internal effect is not BasicEffect, so we can not apply the " +
                              "effect to this shader", Log.LogLevel.Warning);
                }
            }
            else
            {
                basicEffect.Alpha          = material.Diffuse.W;
                basicEffect.DiffuseColor   = Vector3Helper.GetVector3(material.Diffuse);
                basicEffect.SpecularColor  = Vector3Helper.GetVector3(material.Specular);
                basicEffect.EmissiveColor  = Vector3Helper.GetVector3(material.Emissive);
                basicEffect.SpecularPower  = material.SpecularPower;
                basicEffect.TextureEnabled = material.HasTexture;
                basicEffect.Texture        = material.Texture;
            }
        }
Beispiel #16
0
        public Vector3 GetPosition(IPhysicsObject physObj)
        {
            if (!objectIDs.ContainsKey(physObj))
            {
                return(Vector3.Zero);
            }

            float[] position = new float[3];
            HavokDllBridge.get_body_position(objectIDs[physObj], position);
            return(Vector3Helper.FromFloats(position));
        }
Beispiel #17
0
            public void Read(Stream s)
            {
                var r = new BinaryReader(s);

                MmidIndex    = r.ReadUInt32();
                UniqueId     = r.ReadUInt32();
                Position     = Vector3Helper.Read(s);
                Rotation     = Vector3Helper.Read(s);
                DecimalScale = r.ReadUInt16();
                Flags        = r.ReadUInt16();
            }
Beispiel #18
0
        public void InitializePhysics()
        {
            Vector3 g = info.Gravity * info.GravityDirection;

            if (!HavokDllBridge.init_world(Vector3Helper.ToFloats(g), info.WorldSize,
                                           info.CollisionTolerance, info.HavokSimulationType, info.HavokSolverType,
                                           info.FireCollisionCallbacks, info.EnableDeactivation))
            {
                throw new GoblinException("Failed to initialize Havok physics");
            }
        }
Beispiel #19
0
        public void ApplyHardKeyFrame(IPhysicsObject physObj, Vector3 newPos, Quaternion newRot, float timeStep)
        {
            if (!objectIDs.ContainsKey(physObj))
            {
                return;
            }

            float[] pos = Vector3Helper.ToFloats(ref newPos);
            float[] rot = { newRot.X, newRot.Y, newRot.Z, newRot.W };

            HavokDllBridge.apply_hard_keyframe(objectIDs[physObj], pos, rot, timeStep);
        }
Beispiel #20
0
        // -------------------------------------------------------------------------------
        // LoadFloor
        // -------------------------------------------------------------------------------
        public void LoadFloor()
        {
            interactables.Clear();

            if (currentDungeonConfig != null)
            {
                map = LoadDungeon(currentDungeonConfig);
            }

            if (map != null)
            {
                LoadMapConfig();
                ClearMap();

                for (int x = 0; x < map.Size.x; x++)
                {
                    for (int y = 0; y < map.Size.y; y++)
                    {
                        ScriptableTile tile = map.GetTile(x, y);

                        if (tile is DungeonTileStart)
                        {
                            startPos = new Vector3(x, Finder.navi.baseHeightOffset, y);
                            startDir = Vector3Helper.CardinalDirection(((DungeonTileStart)tile).facingDirection);
                            CreateDungeonFloor(x, y, false, ((DungeonTileStart)tile).floorPrefab);
                            CreateDungeonCeiling(x, y, ((DungeonTileStart)tile).ceilingPrefab);
                        }
                         else if (tile is DungeonTileWall)
                        {
                            CreateDungeonFloor(x, y, true, ((DungeonTileWall)tile).floorPrefab);
                            CreateDungeonWall(x, y, ((DungeonTileWall)tile));
                            CreateDungeonCeiling(x, y, ((DungeonTileWall)tile).ceilingPrefab);
                        }
                        else if (tile is DungeonTileFloor)
                        {
                            CreateDungeonFloor(x, y, true, ((DungeonTileFloor)tile).floorPrefab, (DungeonTileFloor)tile);
                            CreateDungeonCeiling(x, y, ((DungeonTileFloor)tile).ceilingPrefab, (DungeonTileFloor)tile);
                        }
                        else if (tile is DungeonTileEvent)
                        {
                            CreateDungeonObject(x, y, (DungeonTileEvent)tile);
                            CreateDungeonFloor(x, y, false, ((DungeonTileEvent)tile).floorPrefab);
                            CreateDungeonCeiling(x, y, ((DungeonTileEvent)tile).ceilingPrefab);
                        }
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("tile map could not be loaded from map config!");
            }
        }
Beispiel #21
0
            public static LiquidHeader Read(Stream s)
            {
                var ret = new LiquidHeader();
                var r   = new BinaryReader(s);

                ret.CountXVertices = r.ReadUInt32();
                ret.CountYVertices = r.ReadUInt32();
                ret.Width          = r.ReadUInt32();
                ret.Height         = r.ReadUInt32();
                ret.BaseLocation   = Vector3Helper.Read(s);
                ret.MaterialId     = r.ReadUInt16();
                return(ret);
            }
Beispiel #22
0
        // -------------------------------------------------------------------------------
        // CreateDungeonObject
        // -------------------------------------------------------------------------------
        private void CreateDungeonObject(int x, int y, DungeonTileEvent tile)
        {
            if (tile != null)
            {
                GameObject instance = (GameObject)GameObject.Instantiate(tile.objectPrefab);

                if (Vector3Helper.CardinalDirection(tile.facingDirection) != Vector3.zero)
                {
                    instance.transform.forward = Vector3Helper.CardinalDirection(tile.facingDirection);
                }

                instance.transform.position = new Vector3(x, tile.offsetHeight, y);

                if (tile.facingDirection != DirectionType.None && !tile.interactFromBothSides)
                {
                    instance.transform.position -= instance.transform.forward / 3;
                }

                instance.transform.parent = MapContainer;
                instance.name             = string.Format("{0}_{1}", x, y);
                interactables.Add(new Interactable {
                    FacePlayer = tile.facePlayer, transform = instance.transform, ID = x.ToString() + y.ToString()
                });

                DungeonObjectEvent co = instance.GetComponent <DungeonObjectEvent>();

                co.tile = tile;

                co.Location = new Location {
                    template = currentDungeonConfig, X = x, Y = y
                };

                if (Finder.party.InteractedObjects.Any(i => i.Location.Equals(co.Location)))
                {
                    co.SetInteraction(true);
                }

                if (tile.StartsDeactivated || Finder.party.DeactivatedObjects.Any(i => i.Location.Equals(co.Location)))
                {
                    co.Deactivate();
                }
                else
                {
                    co.Activate();
                }
            }
            else
            {
                Debug.LogErrorFormat("Error: No tile defined at position: {0}, {1}", x, y);
            }
        }
Beispiel #23
0
        // ===============================================================================
        // TELEPORT & MOVEMENT
        // ===============================================================================

        // -------------------------------------------------------------------------------
        // TeleportPlayer
        // -------------------------------------------------------------------------------
        public void TeleportPlayer(Location location)
        {
            if (location == null || location.locationType == LocationType.None)
            {
                return;
            }

            if (location.template == null)
            {
                location.template = location.targetMap;
            }

            Finder.ui.DeactivateAll();

            // -- Teleport to Worldmap
            if (location.locationType == LocationType.Worldmap)
            {
                WarpWorldmap();
                return;
            }

            // -- Teleport to Town
            if (location.locationType == LocationType.Town)
            {
                WarpTown((TemplateMetaTown)location.template);
                return;
            }

            // -- Teleport to Outro
            if (location.locationType == LocationType.Outro)
            {
                WarpOutro();
                return;
            }

            // -- Teleport to Dungeon
            if (location.locationType == LocationType.Dungeon)
            {
                WarpDungeon((TemplateMetaDungeon)location.template, false);

                Finder.party.transform.position = new Vector3(location.X, Finder.navi.baseHeightOffset, location.Y);

                if (Vector3Helper.CardinalDirection(location.facingDirection) != Vector3.zero)
                {
                    Finder.party.transform.forward = Vector3Helper.CardinalDirection(location.facingDirection);
                }

                Finder.navi.enabled = true;
            }
        }
Beispiel #24
0
 // -------------------------------------------------------------------------------
 //
 // -------------------------------------------------------------------------------
 public void OnMoved()
 {
     Finder.audio.PlaySFX(SFX.Footstep);
     NormalizeTransform();
     Finder.map.UpdateInteractableDirection();
     Finder.party.MapExplorationInfo.AddExploredSpace(Finder.map.MapName, new Vector2(Finder.party.transform.position.x, Finder.party.transform.position.z));
     facingDirection = Vector3Helper.CardinalDirection(transform.forward);
     if (!Finder.battle.InBattle)
     {
         enabled = true;
     }
     changedDirection = false;
     OnPlayerMoved();
 }
Beispiel #25
0
        private static CustomMesh CreateLayer(Vector2 dimension)
        {
            CustomMesh mesh = new CustomMesh();

            VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[4];
            Vector2 halfExtent = dimension / 2;

            Vector3 v0 = Vector3Helper.Get(-halfExtent.X, 0, -halfExtent.Y);
            Vector3 v1 = Vector3Helper.Get(-halfExtent.X, 0, halfExtent.Y);
            Vector3 v2 = Vector3Helper.Get(halfExtent.X, 0, halfExtent.Y);
            Vector3 v3 = Vector3Helper.Get(halfExtent.X, 0, -halfExtent.Y);

            vertices[0].Position = v0;
            vertices[1].Position = v1;
            vertices[2].Position = v2;
            vertices[3].Position = v3;

            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i].Normal = Vector3.UnitY;
            }

            vertices[1].TextureCoordinate = new Vector2(0, 1);
            vertices[0].TextureCoordinate = new Vector2(0, 0);
            vertices[2].TextureCoordinate = new Vector2(1, 1);
            vertices[3].TextureCoordinate = new Vector2(1, 0);

            mesh.VertexDeclaration = new VertexDeclaration(State.Device,
                                                           VertexPositionNormalTexture.VertexElements);

            mesh.VertexBuffer = new VertexBuffer(State.Device,
                                                 VertexPositionNormalTexture.SizeInBytes * vertices.Length, BufferUsage.None);
            mesh.VertexBuffer.SetData(vertices);

            short[] indices = new short[6];

            indices[0] = 0; indices[1] = 2; indices[2] = 1;
            indices[3] = 2; indices[4] = 0; indices[5] = 3;

            mesh.IndexBuffer = new IndexBuffer(State.Device, typeof(short), 6,
                                               BufferUsage.None);
            mesh.IndexBuffer.SetData(indices);

            mesh.SizeInBytes        = VertexPositionNormalTexture.SizeInBytes;
            mesh.NumberOfVertices   = 4;
            mesh.NumberOfPrimitives = 2;

            return(mesh);
        }
Beispiel #26
0
 void Update()
 {
     if (this.checkAngle)
     {
         float angle = Vector3Helper.GetAngleInRadians(Player.Instance.transform.forward, this.transform.position - Player.Instance.transform.position, Vector3.up);
         if (Mathf.Abs(angle) < MathConstants.Rad15Deg)
         {
             this.ActivateInteraction();
         }
         else
         {
             this.DeactivateInteraction();
         }
     }
 }
Beispiel #27
0
        public static DoodadInstance Read(Stream s)
        {
            var r   = new BinaryReader(s);
            var ret = new DoodadInstance();

            ret.FileOffset = r.ReadUInt32();
            ret.Position   = Vector3Helper.Read(s);
            ret.QuatW      = r.ReadSingle();
            ret.QuatX      = r.ReadSingle();
            ret.QuatY      = r.ReadSingle();
            ret.QuatZ      = r.ReadSingle();
            ret.Scale      = r.ReadSingle();
            ret.LightColor = r.ReadUInt32();
            return(ret);
        }
Beispiel #28
0
        public BoundingBox GetAxisAlignedBoundingBox(IPhysicsObject physObj)
        {
            if (!objectIDs.ContainsKey(physObj))
            {
                return(new BoundingBox());
            }

            float[] min = new float[3];
            float[] max = new float[3];
            HavokDllBridge.get_AABB(objectIDs[physObj], min, max);
            Vector3Helper.FromFloats(min, out tmpVec1);
            Vector3Helper.FromFloats(max, out tmpVec2);

            return(new BoundingBox(tmpVec1, tmpVec2));
        }
Beispiel #29
0
        public void SetParameters(Material material)
        {
            if (material.InternalEffect != null)
            {
                if (material.InternalEffect is SkinnedEffect)
                {
                    internalEffect       = (SkinnedEffect)material.InternalEffect;
                    internalEffect.Alpha = originalAlphas[alphaIndexer] * material.Diffuse.W;

                    internalEffect.PreferPerPixelLighting = skinnedEffect.PreferPerPixelLighting;
                    internalEffect.AmbientLightColor      = skinnedEffect.AmbientLightColor;

                    if (lightsChanged)
                    {
                        if (lightSources.Count > 0)
                        {
                            DirectionalLight[] lights = { internalEffect.DirectionalLight0,
                                                          internalEffect.DirectionalLight1, internalEffect.DirectionalLight2 };

                            int numLightSource = lightSources.Count;
                            for (int i = 0; i < numLightSource; i++)
                            {
                                lights[i].Enabled       = true;
                                lights[i].DiffuseColor  = Vector3Helper.GetVector3(lightSources[i].Diffuse);
                                lights[i].Direction     = lightSources[i].Direction;
                                lights[i].SpecularColor = Vector3Helper.GetVector3(lightSources[i].Specular);
                            }
                        }
                    }

                    alphaIndexer = (alphaIndexer + 1) % originalAlphas.Length;
                }
                else
                {
                    Log.Write("Passed internal effect is not BasicEffect, so we can not apply the " +
                              "effect to this shader", Log.LogLevel.Warning);
                }
            }
            else
            {
                skinnedEffect.Alpha         = material.Diffuse.W;
                skinnedEffect.DiffuseColor  = Vector3Helper.GetVector3(material.Diffuse);
                skinnedEffect.SpecularColor = Vector3Helper.GetVector3(material.Specular);
                skinnedEffect.EmissiveColor = Vector3Helper.GetVector3(material.Emissive);
                skinnedEffect.SpecularPower = material.SpecularPower;
                skinnedEffect.Texture       = material.Texture;
            }
        }
Beispiel #30
0
        public void StopKeyframe(IPhysicsObject physObj)
        {
            if (!objectIDs.ContainsKey(physObj))
            {
                return;
            }

            Vector3    scale, trans;
            Quaternion quat;

            physObj.PhysicsWorldTransform.Decompose(out scale, out quat, out trans);

            float[] pos = Vector3Helper.ToFloats(ref trans);
            float[] rot = { quat.X, quat.Y, quat.Z, quat.W };

            HavokDllBridge.apply_hard_keyframe(objectIDs[physObj], pos, rot, 0.016f);
        }