Beispiel #1
0
 MPhysicsObject GetPhysics()
 {
     if (_physics == null)
     {
         _physics = (MPhysicsObject)FindModuleByType(EType.PhysicsObject);
     }
     return(_physics);
 }
Beispiel #2
0
 public MNPC(MSceneObject parent, string inname = "") : base(EType.NPCPlayer, inname)
 {
     OriginalRotation             = parent.transform.Rotation;
     OriginalPosition             = parent.transform.Position;
     model                        = (MAnimatedModel)parent;
     _physics                     = (MPhysicsObject)model.FindModuleByType(EType.PhysicsObject);
     _physics._rigidBody.Friction = 0.4;
 }
Beispiel #3
0
 public void SetSceneObject(MSceneObject so)
 {
     Target   = so;
     _physics = null;
     if (Target != null)
     {
         _physics = (MPhysicsObject)Target.FindModuleByType(EType.PhysicsObject);
     }
 }
Beispiel #4
0
        //either transform or physics
        public void SetPosition(Vector3d p)
        {
            MPhysicsObject po = (MPhysicsObject)FindModuleByType(EType.PhysicsObject);

            if (po != null)
            {
                po.SetPosition(p);
            }
            else
            {
                transform.Position = p;
            }
        }
Beispiel #5
0
        //either transform or physics
        public void SetPosition(Vector3d p)
        {
            //a phyics module may be added at any time, so we need to query for it
            MPhysicsObject po = GetPhysics();

            if (po != null)
            {
                po.SetPosition(p);
            }
            else
            {
                transform.Position = p;
            }
        }
Beispiel #6
0
        //private MSceneObject parent;
        public MTeleportOneShot(MSceneObject inparent, Vector3d inTargetPos, Quaterniond inTargetRot) : base(EType.Teleport, "TeleportAnim")
        {
            Parent        = inparent;
            StartPosition = inparent.transform.Position;
            StartRotation = inparent.transform.Rotation;

            TargetPosition = inTargetPos;
            TargetRotation = inTargetRot;
            MPhysicsObject po = (MPhysicsObject)Parent.FindModuleByType(EType.PhysicsObject);

            if (po != null)
            {
                po.SetActive(false);
            }
            Start = 0;
        }
Beispiel #7
0
        public void LookAt(Vector3d p)
        {
            if (p.Equals(transform.Position))
            {
                p += Vector3d.UnitZ;
            }
            MPhysicsObject po = (MPhysicsObject)FindModuleByType(EType.PhysicsObject);

            //Matrix4d mat = Matrix4d.LookAt(this.transform.Position , p , Vector3d.UnitY);
            Quaterniond q = Extensions.LookAt(this.transform.Position, p, Vector3d.UnitY);

            if (po != null)
            {
                po.SetRotation(q);
            }
            transform.Rotation = q;
        }
Beispiel #8
0
 public void SetupPhysics()
 {
     if (IsSetup == false)
     {
         return;
     }
     if (_physics == null)
     {
         stopwatch.Start();
         Console.WriteLine("MTerrainTile.SetupPhysics " + TileX + "," + TileY);
         //string sText = string.Format("PHYSICS: Cache\\earth\\{0}\\biome\\{1}_{2}.png", ZoomLevel, TileX, TileY);
         _physics = new MPhysicsObject(this, "Terrain_collider", 0, MPhysicsObject.EShape.ConcaveProxy, false, this.transform.Scale);
         stopwatch.Stop();
         Console.WriteLine("MTerrainTile.SetupPhysics " + TileX + "," + TileY + " completed in  " + stopwatch.ElapsedTicks);
         DoSetupPhysics = false;
     }
 }
Beispiel #9
0
        public void SetRotation(Quaterniond q, bool NotifyDescendents = true)
        {
            MPhysicsObject po = (MPhysicsObject)FindModuleByType(EType.PhysicsObject);

            if (po != null)
            {
                po.SetRotation(q);
            }
            else
            {
                transform.Rotation = q;
            }

            if (NotifyDescendents == true)
            {
                ParentChanged();
            }
        }
Beispiel #10
0
        public void SetRotation(Quaterniond q, bool NotifyDescendents = true)
        {
            //a phyics module may be added at any time, so we need to query for it
            MPhysicsObject po = GetPhysics();

            if (po != null)
            {
                _physics.SetRotation(q);
            }
            else
            {
                transform.Rotation = q;
            }

            if (NotifyDescendents == true)
            {
                ParentChanged();
            }
        }
Beispiel #11
0
        public void TeleportComplete()
        {
            MPhysicsObject po  = (MPhysicsObject)Parent.FindModuleByType(EType.PhysicsObject);
            MSceneObject   msp = (MSceneObject)Parent;

            msp.SetPosition(TargetPosition);
            msp.SetRotation(TargetRotation);
            if (po != null)
            {
                po.SetActive(true);
                po.StopAllMotion();
            }

            if (TeleportCompleteHandler != null)
            {
                TeleportCompleteHandler(this, new MoveEvent(Parent.InstanceID, TargetPosition, TargetRotation));
            }

            Parent.Remove(this);
            Dispose();
        }
Beispiel #12
0
        public override void CopyTo(MObject m1)
        {
            base.CopyTo(m1);

            MSceneObject mo = (MSceneObject)m1;

            mo.transform.Scale          = transform.Scale;
            mo.transform.RotationOffset = transform.RotationOffset;

            //we don't want to use the template position, since these will be set by the world map
            //mo.transform.Position = transform.Position;
            //mo.transform.Rotation = transform.Rotation;
            mo.SetMaterial(material);
            mo.TemplateID     = TemplateID;
            mo.IsAvatar       = IsAvatar;
            mo.CastsShadow    = CastsShadow;
            mo.BoundingBox    = BoundingBox;
            mo.IndicesLength  = IndicesLength;
            mo.VerticesLength = VerticesLength;
            mo.IsTransparent  = IsTransparent;

            foreach (MObject m in Modules)
            {
                if (m.Type == EType.PhysicsObject)
                {
                    MPhysicsObject p1 = (MPhysicsObject)m;
                    MPhysicsObject p2 = new MPhysicsObject(mo, mo.Name, (float)p1.Mass, p1.Shape, false, p1.CreateScale);
                    p2.Name = p1.Name;
                    p2.SetDamping(p1._rigidBody.LinearDamping, p1._rigidBody.AngularDamping);
                    p2._rigidBody.AngularFactor = p1._rigidBody.AngularFactor;
                    p2._rigidBody.LinearFactor  = p1._rigidBody.LinearFactor;
                    p2._rigidBody.Restitution   = p1._rigidBody.Restitution;
                    p2.SetPosRot(mo.transform.Position, mo.transform.Rotation);
                    //p2.SetPosition(mo.transform.Position);
                    //p2.SetRotation(mo.transform.Rotation);
                    p2.StopAllMotion();
                }

                if (m.Type == EType.PointLight)
                {
                    MPointLight p = new MPointLight(m.Name);
                    MScene.LightRoot.Add(p);
                    m.CopyTo(p);
                    mo.Add(p);
                }

                if (m.Type == EType.Sound)
                {
                    MSound os = (MSound)m;
                    MSound s  = new MSound();
                    os.CopyTo(s);
                    s.Error = os.Error;
                    s.Load(os.Filename, mo);
                    mo.Add(s);
                }

                //network objects can only be owned by the user. When the user is offline the network object is dormant
                //if (mo.OwnerID.Equals(Globals.UserAccount.UserID))
                if (m.Type == EType.NetworkObject)
                {
                    MNetworkObject mn = (MNetworkObject)m.FindModuleByType(MObject.EType.NetworkObject);
                    if (mn != null)
                    {
                        mo.Add(mn);
                    }
                }

                if (m.Type == EType.NPCPlayer)
                {
                    MNPC p = new MNPC(mo, m.Name);
                    m.CopyTo(p);
                    mo.Add(p);
                }

                if (m.Type == EType.Door)
                {
                    MDoor d2 = new MDoor(mo);
                    m.CopyTo(d2);
                    mo.Add(d2);
                }
            }
        }
Beispiel #13
0
        public void InitializePlanets()
        {
            //GravityIndicator = Helper.CreateCube(MScene.AstroRoot, "GravitySphere", Vector3d.Zero);
            //GravityIndicator.transform.Scale = new Vector3d(0.05, 0.1, 0.1);
            //GravityIndicator.OwnerID = "MasterAstronomer";
            //MScene.AstroRoot.Add(GravityIndicator);
            //GravityIndicator.SetMaterial((MMaterial)MScene.MaterialRoot.FindModuleByName(MMaterial.DEFAULT_MATERIAL));
            CreateShaders();

            for (int i = 0; i < Bodies.Count; i++)
            {
                MAstroBody m = Bodies[i];
                //m.Radius = m.Radius * 0.5;
                if (m.IsTemplate == true)
                {
                    continue;
                }
                m.ListIndex = i;
                Vector3d    pos  = m.Position + new Vector3d(-m.Radius.X, 0, 0) * (m.HasRings == true ? 3.0 : 1.1);
                MServerZone zone = new MServerZone("MASTER_ASTRONOMER", m.Name, "Astronomical",
                                                   MassiveTools.ToVector3_Server(pos));
                zone.Rotation    = MassiveTools.ArrayFromQuaterniond(Quaterniond.Identity);
                zone.Description = m.Description + " \nRadius:" + m.Radius;
                MMessageBus.AddZone(this, zone);
                //Extensions.LookAt(m.Position + m.Radius * 2, m.Position), m.Name));

                MSceneObject mo;
                //planet files contain uvs for mercator
                if (m.HasAtmosphere)
                {
                    CurrentNear = m;
                    mo          = Helper.CreateModel(MScene.AstroRoot, m.Name, @"Models\planets\earth.3ds", Vector3d.Zero);
                    //mo = Helper.CreateSphere(MScene.AstroRoot, 3, "Planet");
                    //mo.transform.Scale = m.Radius * 1.00055;
                    mo.transform.Scale = m.Radius;
                }
                else
                {
                    mo = Helper.CreateModel(MScene.AstroRoot, m.Name, @"Models\planets\planet_sphere2.3ds", Vector3d.Zero);
                    mo.transform.Scale = m.Radius;
                }

                if (m.HasRings)
                {
                    MModel ring = Helper.CreateModel(MScene.Priority2, m.Name + "_rings", @"Models\planets\planet_rings.3ds", Vector3d.Zero);
                    ring.transform.Position = m.Position;
                    ring.transform.Rotation = Quaterniond.FromEulerAngles(0, 0, 5 * Math.PI / 180);
                    ring.transform.Scale    = m.Radius;
                    ring.InstanceID         = m.Name;
                    ring.TemplateID         = m.Name;
                    ring.DistanceThreshold  = m.Radius.X * 12;
                    ring.OwnerID            = "MasterAstronomer";
                    MMaterial ringmat = new MMaterial(m.Name + "_mat");
                    ringmat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER));
                    MTexture ringtex = Globals.TexturePool.GetTexture(@"Textures\Planets\saturn_rings.png");
                    ringmat.SetDiffuseTexture(ringtex);
                    ring.SetMaterial(ringmat);

                    MPhysicsObject ringpo = new MPhysicsObject(ring, "Physics", 0, MPhysicsObject.EShape.ConcaveMesh, false, m.Radius);
                    ringpo.SetLinearFactor(0, 0, 0);
                    ringpo.SetRestitution(0.5);
                }

                mo.transform.Position = m.Position;
                //mo.transform.Scale = m.Radius * 1.9999;

                mo.InstanceID        = m.Name;
                mo.TemplateID        = m.Name;
                mo.OwnerID           = "MasterAstronomer";
                mo.DistanceThreshold = m.Radius.X * 110002; //distance at which it becomes visible
                //MModel mod = (MModel)mo.FindModuleByType(EType.Model);
                //mod.DistanceThreshold = mo.DistanceThreshold;
                //MMesh met = (MMesh)mod.FindModuleByType(EType.Mesh);
                //if ( met != null ) {
                //met.DistanceThreshold = mo.DistanceThreshold;
                //}
                mo.Tag = m;
                m.Tag  = mo;

                //now that we have a 3d model, apply some progressive textures (will auto-switch with smooth transition in shader)
                MMaterial mat = new MMaterial(m.Name + "_mat");
                mat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER));
                MTexture tex = Globals.TexturePool.GetTexture(m.TextureName);
                mat.SetDiffuseTexture(tex);
                mo.SetMaterial(mat);
                MTexture tex2 = Globals.TexturePool.GetTexture("Textures\\terrain\\sand01b.jpg");
                mat.SetMultiTexture(tex2);
                MTexture tex3 = Globals.TexturePool.GetTexture("Textures\\terrain\\water.jpg");
                mat.SetNormalMap(tex3);

                double dia = 2.0 * Math.PI * m.Radius.X * 0.0000001;
                //double dia = 1;
                mat.Tex2CoordScale = new Vector2((float)dia, (float)dia);
                mo.SetMaterial(mat);

                MScene.MaterialRoot.Add(mat);

                if (m.HasAtmosphere)
                {
                    if (Settings.DrawTerrains == true)
                    {
                        m.AddDynamicTerrain(); //adds tile based terrain (from e.g. tile service)
                    }

                    //MPhysicsObject po = new MPhysicsObject(mo, "Physics", 0, MPhysicsObject.EShape.ConcaveMesh,
                    //false, m.Radius);
                    MPhysicsObject po = new MPhysicsObject(mo, "Physics", 0, MPhysicsObject.EShape.Sphere,
                                                           false, m.Radius);
                    //po.SetLinearFactor(0, 0, 0);
                    //po.SetRestitution(0.5);
                    //MSphere moc = Helper.CreateSphere(MScene.AstroRoot, 3, m.Name+ "Clouds", Vector3d.Zero);

                    MModel moc = Helper.CreateModel(MScene.AstroRoot, m.Name + "_clouds", @"Models\planets\clouds.3ds", Vector3d.Zero);
                    moc.CastsShadow        = false;
                    moc.transform.Position = m.Position;
                    moc.transform.Scale    = m.Radius;
                    moc.DistanceThreshold  = m.Radius.X * 3;
                    //moc.transform.Scale = m.Radius*2.1;
                    moc.InstanceID = m.Name;
                    moc.TemplateID = m.Name;
                    moc.OwnerID    = "MasterAstronomer";
                    moc.Tag        = m;

                    MMaterial cmat = new MMaterial("CloudMat");
                    cmat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER));
                    cmat.Opacity = 1;
                    cmat.IsSky   = 1;
                    // = new MTexture("CloudTex");
                    MTexture ctex = Globals.TexturePool.GetTexture(CloudTexURL);
                    ctex.Additive = false;
                    cmat.SetDiffuseTexture(ctex);
                    moc.SetMaterial(cmat);
                    MScene.MaterialRoot.Add(cmat);

                    MModel sky = Helper.CreateModel(MScene.AstroRoot, m.Name + "_sky", @"Models\sky.3ds", Vector3d.Zero);
                    sky.CastsShadow        = false;
                    sky.transform.Position = m.Position;
                    sky.transform.Scale    = m.Radius;
                    //moc.transform.Scale = m.Radius*2.1;
                    sky.InstanceID = m.Name;
                    sky.TemplateID = m.Name;
                    sky.OwnerID    = "MasterAstronomer";
                    sky.Tag        = m;
                    sky.SetMaterial(cmat);
                    sky.DistanceThreshold = m.Radius.X * 4;
                    MObjectAnimation ani = new MObjectAnimation();
                    ani.AngleOffset = Quaterniond.FromEulerAngles(0, 0.002, 0);
                    ani.Speed       = 1;
                    sky.Add(ani);

                    sky.SetMaterial(MSkyMaterial);

                    /*MMaterial csky = new MMaterial("Skymat");
                     * csky.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER));
                     * csky.Opacity = 0.5;
                     * csky.IsSky = 1;
                     * // = new MTexture("CloudTex");
                     * MTexture cSkyTex = Globals.TexturePool.GetTexture(OpaqueCloudTexURL);
                     * cSkyTex.Additive = false;
                     * csky.SetDiffuseTexture(cSkyTex);
                     * sky.SetMaterial(csky);
                     * MScene.MaterialRoot.Add(csky);
                     */



                    /* MSphere water = Helper.CreateSphere(MScene.ModelRoot, 5, "Water");
                     * water.transform.Position = m.Position;
                     * water.transform.Scale = m.Radius * 2.00;
                     * MMaterial waterman = new MMaterial("Watermat");
                     * MShader shader = new MShader("watershader");
                     * shader.Load("ocean_vs.glsl", "ocean_fs.glsl");
                     * shader.Bind();
                     * shader.SetInt("diffuseTexture", 0);
                     * shader.SetInt("shadowMap", 1);
                     * waterman.AddShader(shader);
                     * water.SetMaterial(waterman);
                     */
                    //water.SetMaterial((MMaterial)MScene.MaterialRoot.FindModuleByName(MMaterial.DEFAULT_MATERIAL));
                }
                else
                {
                    MPhysicsObject po = new MPhysicsObject(mo, "Physics", 0, MPhysicsObject.EShape.Sphere, false,
                                                           m.Radius * 0.999);
                    po.SetLinearFactor(0, 0, 0);
                    po.SetRestitution(0.5);
                }
                m.Setup();
                //Console.WriteLine("Created:" + mo.Name + ":" + (mo.transform.Position) + " R:" + m.Radius);
            }
        }
Beispiel #14
0
        public override void Setup()
        {
            MSceneObject so = (MSceneObject)Parent;

            _physics = (MPhysicsObject)so.FindModuleByType(EType.PhysicsObject);
        }
Beispiel #15
0
        public override void Update()
        {
            if (Idle == true)
            {
                return;
            }
            if (msoParent == null)
            {
                return;
            }

            if (po == null)
            {
                po = (MPhysicsObject)Parent.FindModuleByType(EType.PhysicsObject);
            }

            MSceneObject msp        = (MSceneObject)Parent;
            Vector3d     CurrentPos = msp.transform.Position;
            Quaterniond  CurrentRot = msp.transform.Rotation;

            //CurrentPos = Vector3d.Lerp(CurrentPos, TargetPosition, Time.DeltaTime * Speed);
            Value += Time.DeltaTime * Speed;
            if (Value > 1)
            {
                Value = 1;
            }
            double dist = (Vector3d.Distance(TargetPosition, CurrentPos));

            if (dist > 1000)
            {
                Start = 0.999;
                if (po != null)
                {
                    po.SetActive(false);
                }
            }
            CurrentPos = Vector3d.Lerp(StartPosition, TargetPosition, Value);
            CurrentRot = Quaterniond.Slerp(CurrentRot, TargetRotation, Value);

            //if ( dist< 0.1)
            if (Value >= 1)
            {
                CurrentPos = TargetPosition;
                CurrentRot = TargetRotation;
                Idle       = true;
                //msp.SetPosition(TargetPosition);
                //msp.SetRotation(TargetRotation, false);
                //Console.WriteLine("idle");
                if (po != null)
                {
                    po.SetActive(true);
                }
                Complete();
            }
            else
            {
                if (po != null)
                {
                    po.SetActive(true);
                }
            }

            msp.SetPosition(CurrentPos);
            msp.SetRotation(CurrentRot, false);
        }
Beispiel #16
0
 public MDoor(MSceneObject inParent) : base(EType.Door, "Door")
 {
     OriginalOrientation = inParent.transform.Rotation;
     msoParent           = inParent;
     msoParentPhysics    = (MPhysicsObject)msoParent.FindModuleByType(EType.PhysicsObject);
 }