Esempio n. 1
0
        protected override void Update(double deltaTime)
        {
            base.Update(deltaTime);

            showtime -= deltaTime;

            var l = logs.Count - 1;

            for (var i = l; i > (l - 30) && i >= 0; i--)
            {
                logs[i].position.X = MMWMath.Lerp(logs[i].position.X, 8.0f, MMWMath.Saturate((float)deltaTime * 12.0f));
            }

            if (Input.Ctrl && Input.IsKeyDown(OpenTK.Input.Key.Down))
            {
                Scroll  -= (float)deltaTime * ScrollSpeed;
                showtime = ShowTime;
            }
            else if (Input.Ctrl && Input.IsKeyDown(OpenTK.Input.Key.Up))
            {
                Scroll  += (float)deltaTime * ScrollSpeed;
                showtime = ShowTime;
            }

            var max = logs.Sum(log => log.tex.Size.Height + Interval) + 8.0f - Size.Y;

            if (max < 0.0f)
            {
                max = 0.0f;
            }
            Scroll = MMWMath.Clamp(Scroll, 0.0f, max);
        }
        public override void Draw(Graphics g, double deltaTime)
        {
            base.Draw(g, deltaTime);

            Vector2 sub = Size * MMWMath.Lerp(0.95f, 1.0f, rate);

            var pos = WorldLocation + (Size - sub) * 0.5f;
            var add = (SelectedPanel == this ? 0.15f : 0.0f);
            var r   = MMWMath.Lerp(0.75f, 1.0f, rate);

            r += Connected ? 0.3f : 0.0f;

            Drawer.DrawTextureScaled(texImage, pos.X, pos.Y, sub.X, sub.Y, new Color4(backColor.R * r, backColor.G * r + add, backColor.B * r, 1.0f));

            if (texIcon != null && texIcon.Loaded)
            {
                var iconSize = texIcon.Size.ToVector2();
                iconSize = new Vector2(64.0f);
                var iconPos = WorldLocation + (Size - iconSize) * 0.5f;
                Drawer.DrawTextureScaled(texIcon, iconPos.X, WorldLocation.Y + 24.0f, iconSize.X, iconSize.Y, Color4.White);
            }

            var size = g.MeasureString(Info.WorldName, DefaultFont);

            g.DrawString(Info.WorldName, DefaultFont, Brushes.White, WorldLocation.X + (Size.X - size.Width) * 0.5f, WorldLocation.Y + (Size.Y - size.Height) * 0.5f + 24.0f);
            size = g.MeasureString(Info.HostName, DefaultFontS);
            g.DrawString(Info.HostName, DefaultFontS, Brushes.LightGray, WorldLocation.X + (Size.X - size.Width) * 0.5f, WorldLocation.Y + (Size.Y - size.Height) * 0.5f + 48.0f);

            Icons.DrawConnection(g, WorldLocation.X + Size.X - 50.0f, WorldLocation.Y + 20.0f, 20.0f, 20.0f, Connected ? 2 : 0);
        }
        public override void Update(Graphics g, double deltaTime)
        {
            base.Update(g, deltaTime);

            if (IsMouseOn || SelectedPanel == this)
            {
                rate = MMWMath.Lerp(rate, 1.0f, (float)deltaTime * 6.0f);
            }
            else
            {
                rate = MMWMath.Lerp(rate, 0.0f, (float)deltaTime * 6.0f);
            }
        }
Esempio n. 4
0
        public override void Update(Graphics g, double deltaTime)
        {
            base.Update(g, deltaTime);

            if (IsMouseOn)
            {
                rate = MMWMath.Lerp(rate, 1.0f, (float)deltaTime * 10.0f);
            }
            else
            {
                rate = 0.0f;
            }
        }
Esempio n. 5
0
        public override void Update(Graphics g, double deltaTime)
        {
            base.Update(g, deltaTime);

            if (IsMouseOn && Input.MouseWheel != 0)
            {
                targetHeight -= Input.MouseWheel * 100.0f;
                targetHeight  = MMWMath.Clamp(targetHeight, -((panels.Count - 1) / 2) * 180.0f, 0.0f);
            }

            dummy.LocalLocation = new Vector2(dummy.LocalLocation.X, MMWMath.Lerp(dummy.LocalLocation.Y, targetHeight, (float)deltaTime * 6.0f));

            foreach (var p in panels)
            {
                p.Update(g, deltaTime);
            }
        }
Esempio n. 6
0
        public override void Draw(Graphics g, double deltaTime)
        {
            var s   = g.MeasureString(Text, Font);
            var l   = GetLocation(s.Width, s.Height, Alignment);
            var pos = new Vector2(l.X + WorldLocation.X, l.Y + WorldLocation.Y);

            g.DrawString(Text, Font, Brush, pos.X, pos.Y);

            g.DrawLine(pen, pos.X, pos.Y + s.Height, MMWMath.Lerp(pos.X, pos.X + s.Width, rate), pos.Y + s.Height);

            if (rate > 0.0f)
            {
                Drawer.DrawTexturePixeledAlignment(
                    texStar,
                    ContentAlignment.TopLeft,
                    MMWMath.Lerp(pos.X, pos.X + s.Width, rate) - texStar.Size.Width * 0.5f,
                    pos.Y + s.Height - texStar.Size.Height * 0.5f,
                    Color4.White,
                    -(float)MMW.TotalElapsedTime * 2.0f,
                    1.0f / 32.0f);
            }
        }
Esempio n. 7
0
        protected override void Update(double deltaTime)
        {
            if (Input.MouseWheel > 0)
            {
                Distance *= 1.1f;
            }
            if (Input.MouseWheel < 0)
            {
                Distance *= 0.9f;
            }
            MMW.MainCamera.Near = Distance * 0.01f;
            MMW.MainCamera.Far  = Distance * 1000.0f;

            var delta = Vector2.Zero;

            if (Input.IsButtonDown(OpenTK.Input.MouseButton.Middle))
            {
                var d = Input.MouseDelta;
                if (d != Vector2.Zero)
                {
                    var up = Vector3.TransformVector(Vector3.UnitY, Matrix4.CreateRotationX(height));
                    up = Vector3.TransformVector(up, Matrix4.CreateRotationY(-rotate));
                    var zz = (MMW.MainCamera.Target - MMW.MainCamera.Transform.Position).Normalized();

                    Vector3 x, y;
                    y = up;
                    x = Vector3.Cross(y, zz);

                    y *= d.Y * Distance * 0.002f;
                    x *= d.X * Distance * 0.002f;

                    Target += y + x;
                }
            }
            else if (Input.IsButtonDown(OpenTK.Input.MouseButton.Right))
            {
                delta = Input.MouseDelta;
            }

            Rotate += delta.X * 0.01f;
            Height += delta.Y * 0.01f;
            Height  = MMWMath.Clamp(Height, -1.5f, 1.5f);

            rotate = MMWMath.Lerp(rotate, Rotate, (float)deltaTime * 30.0f);
            height = MMWMath.Lerp(height, Height, (float)deltaTime * 30.0f);

            Vector3 v;

            v.X = (float)(Math.Sin(rotate) * Math.Cos(height));
            v.Z = (float)(-Math.Cos(rotate) * Math.Cos(height));
            v.Y = (float)Math.Sin(height);

            v *= Distance;
            var dir = -v;

            v += Target;

            MMW.MainCamera.Transform.Position = v;
            MMW.MainCamera.Target             = Target;

            MMW.DirectionalLight.Direction = dir;
        }
Esempio n. 8
0
        public override void CalcTransform()
        {
            if (bones == null)
            {
                return;
            }
            // 計算済みの場合は何もしない
            if (!dataChanged)
            {
                return;
            }

            for (var i = 0; i < TransformSize; i++)
            {
                bmvs[i].Init();
            }

            Array.Copy(transforms, oldTransforms, transforms.Length);

            // morph
            if (morpher != null)
            {
                foreach (var m in motionDic.Values)
                {
                    if (m.Rate == 0.0f)
                    {
                        continue;
                    }

                    foreach (var sm in m.Motion.SkinMotions.Values)
                    {
                        if (!morpher.HasMorph(sm.MorphName))
                        {
                            continue;
                        }

                        var values = GetKeyAndRate(sm.Keys, 0.0f);
                        if (values.Item3 == -1.0f)
                        {
                            continue;
                        }

                        var w = MMWMath.Lerp(values.Item1.Value, values.Item2.Value, values.Item3);
                        morpher.SetRate(sm.MorphName, w);
                    }
                }

                var bms = morpher.GetBoneTransforms();
                foreach (var bm in bms)
                {
                    bmvs[bm.Index].location = bm.Location;
                    bmvs[bm.Index].rotation = bm.Rotation;
                }
            }

            // bone
            foreach (var m in motionDic.Values)
            {
                if (m.Rate == 0.0f)
                {
                    continue;
                }

                foreach (var bm in m.Motion.BoneMotions.Values)
                {
                    int index;
                    if (!indexDic.TryGetValue(bm.BoneName, out index))
                    {
                        continue;
                    }

                    var values = GetKeyAndRate(bm.Keys, BoneMotionValue.Identity);
                    if (values.Item3 == -1.0f)
                    {
                        continue;
                    }

                    BoneMotionValue bmv;
                    BoneMotionValue.Lerp(ref values.Item1.Value, ref values.Item2.Value, values.Item3, out bmv);
                    bmv *= m.Rate;
                    if (bmvs[index] == BoneMotionValue.Identity)
                    {
                        bmvs[index] = bmv;
                    }
                    else
                    {
                        bmvs[index] += bmv;
                    }
                }
            }

            // update transform
            for (var i = 0; i < boneTranses.Length; i++)
            {
                BoneTransforms[i].Position = initBoneTransforms[i].ExtractTranslation() + bmvs[i].location;
                BoneTransforms[i].Rotation = bmvs[i].rotation * userRotations[i];
                BoneTransforms[i].Scale    = bmvs[i].scale * userScales[i];
            }

            // TODO: IKボーン変形
            var iks = Array.FindAll(bones, b => b.BoneType == "IK");

            if (iks.Length > 0)
            {
                foreach (var ik in iks)
                {
                    if (bmvs[ik.Index].location == Vector3.Zero)
                    {
                        continue;
                    }

                    var ts = new List <FastTransform>();
                    for (var i = ik.IKLinks.Length - 1; i >= 0; i--)
                    {
                        ts.Add(BoneTransforms[ik.IKLinks[i].Bone.Index]);
                    }

                    ts.Add(BoneTransforms[ik.IKTarget.Index]);

                    ts.Reverse();

                    var target = BoneTransforms[ik.Index].WorldPosition;

                    // loop回数繰り返す
                    var loop = 0;
                    var end  = ik.IKLoop / 3;
                    for (loop = 0; loop < end; loop++)
                    {
                        for (var c = 1; c < ts.Count; c++)
                        {
                            var t    = ts[c];
                            var tPos = t.WorldPosition;
                            var pt   = ts[0];

                            //内積, 外積を求める
                            var v   = (pt.WorldPosition - tPos).Normalized();
                            var vt  = (target - tPos).Normalized();
                            var dot = Vector3.Dot(v, vt);

                            if (dot < 1.0f)
                            {
                                // 角度を求める
                                var rot = (float)Math.Acos(dot);

                                var cross = Vector3.Cross(v, vt);

                                // 制限角度以上ならclamp
                                if (rot > ik.IKRotLimit)
                                {
                                    rot = ik.IKRotLimit;
                                }

                                // 姿勢を変形
                                var r = Quaternion.FromAxisAngle(cross, rot);
                                t.Rotation *= r;
                                if (ik.IKLinks[c - 1].LimitAngle)
                                {
                                    var euler = t.Rotation.ToEuler();
                                    //var p = BoneTransforms[ik.IKLinks[c - 1].Bone.Index].WorldTransform.ExtractRotation();
                                    //if (loop == 0 && ik.Name == "右足IK") Console.WriteLine(p);
                                    var l = ik.IKLinks[c - 1].LowerLimitAngle;
                                    var u = ik.IKLinks[c - 1].UpperLimitAngle;
                                    euler      = Vector3.Clamp(euler, l, u);
                                    t.Rotation = euler.ToQuaternion();
                                }
                            }
                        }

                        var length = (ts[0].WorldPosition - target).Length;
                        if (length < 0.02f)
                        {
                            break;
                        }
                    }

                    ts.RemoveAt(0);

                    for (var i = 0; i < ik.IKLinks.Length; i++)
                    {
                        var idx = ik.IKLinks[i].Bone.Index;
                        bmvs[idx].rotation = ts[i].Rotation;
                    }
                }
            }


            for (var i = 0; i < boneTranses.Length; i++)
            {
                if (bmvs[i] == BoneMotionValue.Identity)
                {
                    boneTranses[i] = Matrix4.Identity;
                }
                else
                {
                    boneTranses[i] = bmvs[i].CreateTransform();
                }
            }

            // FKボーンを確定
            {
                var iden = Matrix4.Identity;
                var all  = Array.FindAll(bones, b => b.Parent == null);
                for (var i = all.Length - 1; i >= 0; i--)
                {
                    ConfirmTransforms(all[i], ref iden);
                }
            }

            dataChanged = false;
        }
        protected override void Update(double deltaTime)
        {
            base.Update(deltaTime);

            var cam     = MMW.MainCamera;
            var prevPos = cam.Transform.Position;

            if (CameraType == "third person")
            {
                GameObject.GetComponent <MeshRenderer>().Visible = true;
                MMW.MainCamera.FoV = 1.2f;
                var center = Target != null ? Target.WorldPosition : Vector3.Zero;

                targetRot    -= Input.MouseDelta.X * 0.005f;
                targetHeight += Input.MouseDelta.Y * 0.005f;
                targetHeight  = MMWMath.Clamp(targetHeight, -MathHelper.PiOver6, MathHelper.PiOver2 - 0.3f);

                rot    = MMWMath.Lerp(rot, targetRot, (float)deltaTime * 16.0f);
                height = MMWMath.Lerp(height, targetHeight, (float)deltaTime * 16.0f);
                Vector3.Lerp(ref target, ref center, (float)deltaTime * 6.0f, out target);

                var y = Math.Sin(height);
                var x = Math.Cos(height) * Math.Sin(rot);
                var z = Math.Cos(height) * Math.Cos(rot);

                var dx = (float)Math.Sin(MMW.TotalElapsedTime * 0.5);
                var dy = (float)Math.Cos(MMW.TotalElapsedTime * 0.7);
                var dz = (float)Math.Cos(MMW.TotalElapsedTime * 0.3);

                var pos = new Vector3((float)x, (float)y, (float)z) * Distance;
                pos += target;

                var rays = Physics.Bullet.RayTest(target, Vector3.Lerp(target, pos, 1.1f), GameObject);
                if (rays.Count > 0)
                {
                    var l   = rays.Min(r => r.Rate);
                    var ray = rays.Find(r => r.Rate == l);
                    if (ray != null)
                    {
                        pos = Vector3.Lerp(target, ray.Position, 0.9f);
                    }
                }

                var nx = Noise.Fbm((float)MMW.TotalElapsedTime * 0.15f * NoiseSpeed, 3) * 0.01f;
                var ny = Noise.Fbm((float)MMW.TotalElapsedTime * 0.1f * NoiseSpeed, 4) * 0.01f;
                var nz = Noise.Fbm((float)MMW.TotalElapsedTime * 0.05f * NoiseSpeed, 5) * 0.01f;
                var rt = new Vector3(nx, ny, nz) * NoiseIntensity * 7.0f;
                var rp = new Vector3(ny, nz, nx) * NoiseIntensity * 4.0f;

                cam.Up                 = Matrix3.CreateRotationZ(nx * NoiseIntensity * 2.0f) * Vector3.UnitY;
                cam.Target             = target + rt;
                cam.Transform.Position = pos + rp;
            }
            else if (CameraType == "first person")
            {
                GameObject.GetComponent <MeshRenderer>().Visible = false;
                MMW.MainCamera.FoV  = 1.4f;
                Transform.Rotate.Y += Input.MouseDelta.X * 0.005f;

                var t = new Vector4(pi.Character.EyePosition, 1.0f) * Transform.WorldTransform;
                cam.Transform.Position = t.Xyz;

                fpHeight -= Input.MouseDelta.Y * 0.005f;
                fpHeight  = MMWMath.Clamp(fpHeight, -MathHelper.PiOver2 + 0.1f, MathHelper.PiOver2 - 0.1f);
                var dir = ct.WorldDirectionZ;
                dir   *= (float)Math.Cos(fpHeight);
                dir.Y += (float)Math.Sin(fpHeight);

                var target = dir + t.Xyz;
                Vector3.Lerp(ref nowDir, ref target, (float)deltaTime * 30.0f, out nowDir);
                cam.Target = nowDir;
            }
        }
Esempio n. 10
0
        protected override void Update(double deltaTime)
        {
            if (time > 0.0)
            {
                time -= deltaTime;
            }

            if (time < 0.0 && totalCoin < maxCoin)
            {
                time += userData.CoinSpownTime;

                var r    = Util.RandomInt(0, 100);
                var coin = cupperCoin;
                if (r >= 90)
                {
                    coin = silverCoin;
                }
                else if (r == 99)
                {
                    coin = goldCoin;
                }

                RayTestResult res  = null;
                int           test = 5;
                while (test > 0)
                {
                    var x   = MMWMath.Lerp(bounds.Min.X, bounds.Max.X, Util.RandomFloat());
                    var z   = MMWMath.Lerp(bounds.Min.Z, bounds.Max.Z, Util.RandomFloat());
                    var pos = new Vector4(x, 0.0f, z, 1.0f) * Transform.WorldTransform;

                    var rays = Bullet.RayTest(new Vector3(pos.X, 100.0f, pos.Z), new Vector3(pos.X, -50.0f, pos.Z));
                    if (rays.Count > 0 && rays[0].GameObject.Tags.Contains("world"))
                    {
                        res = rays[0];
                        break;
                    }

                    test--;
                }

                if (res != null)
                {
                    var go = new NwWalkerGameObject()
                    {
                        CreateDate  = DateTime.Now.ToString(),
                        CreatorName = MMW.GetAsset <UserData>().UserName,
                        Hash        = Util.CreateHash(12),
                        Name        = "coin",
                        ObjectHash  = coin.Hash,
                        Position    = (res.Position + Vector3.UnitY * 0.2f).ToVec3f(),
                        Rotation    = new Vector3f(),
                        Scale       = new Vector3f(1, 1, 1),
                        SessionID   = MMW.GetAsset <UserData>().SessionID,
                        UserID      = MMW.GetAsset <UserData>().UserID,
                    };

                    MMW.FindGameComponent <WalkerScript>().PutGameObject(go, false);
                    totalCoin++;
                }
            }
        }