示例#1
0
        public void InitDungeon(R_Landblock landblock, Model.BoundingBox box)
        {
            var size = box.Size;

            var center = box.Center;

            // draw a view plane from NW to SE
            var p1 = new Vector3(box.Mins.X, box.Maxs.Y, center.Z);
            var p2 = new Vector3(box.Maxs.X, box.Mins.Y, center.Z);

            var length = Vector3.Distance(p1, p2);

            var unit_length = (float)Math.Sqrt(length * length / 2);

            var dist_scalar = 0.75f;

            unit_length *= dist_scalar;

            // move camera out in -x, -y by this distance
            Position    = center;
            Position.X -= unit_length;
            Position.Y -= unit_length;
            Position.Z += unit_length;

            Dir = Vector3.Normalize(box.Center - Position);

            Up    = Vector3.UnitZ;
            Speed = World_Speed;

            CreateLookAt();
        }
示例#2
0
        public void InitModel(Model.BoundingBox box)
        {
            //var box = setup.BoundingBox;
            var size = box.Size;

            var facing = box.GetTargetFace();
            var face   = box.Faces[(int)facing];
            var center = face.Center;
            //Console.WriteLine("TargetFace: " + facing);

            var largest = Math.Max(face.Width, face.Height);

            largest = Math.Max(largest, 1.2f);
            var isAdjustWidth = face.Width > face.Height;
            var adjustWidth   = face.Width / face.Height;

            //var ratio = 1280.0f / 720.0f;

            Position = new Vector3(center.X, center.Y, center.Z);

            var factor = 1.414f;
            //var factor = 1.2f;

            //Console.WriteLine($"Width: {face.Width}, Height: {face.Height}");

            var gfxObjMode = ModelViewer.Instance.GfxObjMode;

            if (facing == Facing.Front || facing == Facing.Back)
            {
                if (gfxObjMode)
                {
                    Position.Y -= largest * factor;
                }
                else
                {
                    Position.Y += largest * factor;
                }

                //Position.Z *= factor;

                Up = Vector3.UnitZ;
            }
            else if (facing == Facing.Left || facing == Facing.Right)
            {
                if (gfxObjMode)
                {
                    Position.X -= largest * factor;
                }
                else
                {
                    Position.X += largest * factor;
                }

                Up = Vector3.UnitZ;
            }
            else if (facing == Facing.Top)
            {
                var front = box.Faces[(int)Facing.Front];
                var left  = box.Faces[(int)Facing.Left];

                //Console.WriteLine("Front area: " + front.Area);
                //Console.WriteLine("Left area: " + left.Area);
                //Console.WriteLine("Top area: " + face.Area);

                Position.Z += largest * factor;

                Up = -Vector3.UnitY;
            }

            //Console.WriteLine("Camera pos: " + Position);

            var lookAt = box.Center;

            //lookAt.Z += size.Z * 0.1f;

            Dir = Vector3.Normalize(lookAt - Position);

            Speed = Model_Speed;

            CreateLookAt();
        }