OSDN Git Service

* Implemented camera smoothing thanks to Moon Metty
authorLatif Khalifa <latifer@streamgrid.net>
Sun, 10 Jul 2011 11:11:39 +0000 (11:11 +0000)
committerLatif Khalifa <latifer@streamgrid.net>
Sun, 10 Jul 2011 11:11:39 +0000 (11:11 +0000)
* Don't try to reload all the rendering data from files if we did it already (allows scene window to be reopened)

git-svn-id: https://radegast.googlecode.com/svn/trunk@963 f7a694da-4d33-11de-9ad6-1127a62b9fcd

Radegast/GUI/Rendering/Rendering.cs
Radegast/GUI/Rendering/RenderingHelpers.cs

index d2afa78..e4466b2 100644 (file)
@@ -318,13 +318,13 @@ namespace Radegast.Rendering
 \r
         void AvatarAnimationChanged(object sender, AvatarAnimationEventArgs e)\r
         {\r
-     \r
+\r
             // We don't currently have UUID -> RenderAvatar mapping so we need to walk the list\r
             foreach (RenderAvatar av in Avatars.Values)\r
             {\r
                 if (av.avatar.ID == e.AvatarID)\r
                 {\r
-                    foreach(Animation anim in e.Animations)\r
+                    foreach (Animation anim in e.Animations)\r
                     {\r
                         Client.Assets.RequestAsset(anim.AnimationID, AssetType.Animation, false, animRecievedCallback);\r
                         av.animlist.Add(anim.AnimationID, anim);\r
@@ -339,13 +339,13 @@ namespace Radegast.Rendering
             if (transfer.Success)\r
             {\r
                 BinBVHAnimationReader b = new BinBVHAnimationReader(asset.AssetData);\r
-                \r
+\r
             }\r
         }\r
 \r
         void Avatars_AvatarAppearance(object sender, AvatarAppearanceEventArgs e)\r
         {\r
-               // We don't currently have UUID -> RenderAvatar mapping so we need to walk the list\r
+            // We don't currently have UUID -> RenderAvatar mapping so we need to walk the list\r
             foreach (RenderAvatar av in Avatars.Values)\r
             {\r
                 if (av.avatar.ID == e.AvatarID)\r
@@ -631,7 +631,7 @@ namespace Radegast.Rendering
                         direction.Normalize();\r
                         Vector3 vy = direction % new Vector3(0f, 0f, 1f);\r
                         Vector3 vx = vy % direction;\r
-                        Vector3 vxy = vx * deltaY * pixelToM + vy * deltaX * pixelToM;\r
+                        Vector3 vxy = vx * deltaY * pixelToM * 3 + vy * deltaX * pixelToM * 3;\r
                         Camera.Position += vxy;\r
                         Camera.FocalPoint += vxy;\r
                     }\r
@@ -685,7 +685,6 @@ namespace Radegast.Rendering
                             }\r
                             else if (ModifierKeys == Keys.Alt)\r
                             {\r
-                                Camera.TimeToTarget = timeToFocus;\r
                                 Camera.FocalPoint = PrimPos(picked.Prim);\r
                                 Cursor.Position = glControl.PointToScreen(new Point(glControl.Width / 2, glControl.Height / 2));\r
                             }\r
@@ -695,7 +694,6 @@ namespace Radegast.Rendering
                             RenderAvatar av = (RenderAvatar)clicked;\r
                             if (ModifierKeys == Keys.Alt)\r
                             {\r
-                                Camera.TimeToTarget = timeToFocus;\r
                                 Vector3 pos = PrimPos(av.avatar);\r
                                 pos.Z += 1.5f; // focus roughly on the chest area\r
                                 Camera.FocalPoint = pos;\r
@@ -1071,7 +1069,7 @@ namespace Radegast.Rendering
                 else\r
                 {\r
                     GLAvatar ga = new GLAvatar();\r
-                    \r
+\r
                     //ga.morph(av);\r
                     RenderAvatar ra = new Rendering.RenderAvatar();\r
                     ra.avatar = av;\r
@@ -1245,7 +1243,7 @@ namespace Radegast.Rendering
                             // Prim roation and position\r
                             //GL.MultMatrix(Math3D.CreateTranslationMatrix(av.avatar.Position));\r
                             //GL.MultMatrix(Math3D.CreateRotationMatrix(av.avatar.Rotation));\r
-                            GL.MultMatrix(Math3D.CreateSRTMatrix(new Vector3(1,1,1),av.avatar.Rotation,av.avatar.Position));\r
+                            GL.MultMatrix(Math3D.CreateSRTMatrix(new Vector3(1, 1, 1), av.avatar.Rotation, av.avatar.Position));\r
 \r
                             // Special case for eyeballs we need to offset the mesh to the correct position\r
                             // We have manually added the eyeball offset based on the headbone when we\r
@@ -1333,7 +1331,7 @@ namespace Radegast.Rendering
                 GL.DisableClientState(ArrayCap.NormalArray);\r
                 GL.DisableClientState(ArrayCap.VertexArray);\r
                 GL.DisableClientState(ArrayCap.TextureCoordArray);\r
-                \r
+\r
             }\r
         }\r
         #endregion avatars\r
@@ -1600,7 +1598,7 @@ namespace Radegast.Rendering
                                         Vector3 point = parentav.glavatar.skel.getOffset(apoint.joint) + apoint.position;\r
                                         Quaternion qrot = parentav.glavatar.skel.getRotation(apoint.joint) * apoint.rotation;\r
                                         //Vector3 point = Bone.getOffset(apoint.joint) + apoint.position;\r
-                                       // Quaternion qrot = Bone.getRotation(apoint.joint) * apoint.rotation;\r
+                                        // Quaternion qrot = Bone.getRotation(apoint.joint) * apoint.rotation;\r
 \r
                                         GL.MultMatrix(Math3D.CreateTranslationMatrix(point));\r
                                         GL.MultMatrix(Math3D.CreateRotationMatrix(qrot));\r
@@ -1648,7 +1646,7 @@ namespace Radegast.Rendering
                                 //Quaternion qrot = Bone.getRotation(apoint.joint) * apoint.rotation;\r
                                 Vector3 point = parentav.glavatar.skel.getOffset(apoint.joint) + apoint.position;\r
                                 Quaternion qrot = parentav.glavatar.skel.getRotation(apoint.joint) * apoint.rotation;\r
-                                \r
+\r
                                 GL.MultMatrix(Math3D.CreateTranslationMatrix(point));\r
                                 GL.MultMatrix(Math3D.CreateRotationMatrix(qrot));\r
                             }\r
@@ -1888,10 +1886,6 @@ namespace Radegast.Rendering
                 Frustum.CalculateFrustum(ProjectionMatrix, ModelMatrix);\r
                 UpdateCamera();\r
                 Camera.Modified = false;\r
-            }\r
-\r
-            if (Camera.TimeToTarget != 0)\r
-            {\r
                 Camera.Step(lastFrameTime);\r
             }\r
 \r
@@ -2410,7 +2404,7 @@ namespace Radegast.Rendering
                     mesh.applyjointweights();\r
                 }\r
 \r
-           }\r
+            }\r
         }\r
 \r
         private void textBox_vparamid_TextChanged(object sender, EventArgs e)\r
@@ -2427,11 +2421,11 @@ namespace Radegast.Rendering
                 Bone b;\r
                 if (av.glavatar.skel.mBones.TryGetValue(bone, out b))\r
                 {\r
-                    textBox_sx.Text = (b.scale.X-1.0f).ToString();\r
-                    textBox_sy.Text = (b.scale.Y-1.0f).ToString();\r
-                    textBox_sz.Text = (b.scale.Z-1.0f).ToString();\r
+                    textBox_sx.Text = (b.scale.X - 1.0f).ToString();\r
+                    textBox_sy.Text = (b.scale.Y - 1.0f).ToString();\r
+                    textBox_sz.Text = (b.scale.Z - 1.0f).ToString();\r
 \r
-                    float x,y,z;\r
+                    float x, y, z;\r
                     b.rot.GetEulerAngles(out x, out y, out z);\r
                     textBox_x.Text = x.ToString();\r
                     textBox_y.Text = y.ToString();\r
@@ -2440,7 +2434,7 @@ namespace Radegast.Rendering
                 }\r
 \r
             }\r
-            \r
+\r
 \r
         }\r
 \r
@@ -2482,7 +2476,7 @@ namespace Radegast.Rendering
 \r
             }\r
 \r
-                    \r
+\r
 \r
         }\r
 \r
@@ -2516,7 +2510,7 @@ namespace Radegast.Rendering
 \r
         }\r
 \r
-       \r
+\r
 \r
     }\r
 }\r
index 9574ced..b42ebf7 100644 (file)
@@ -286,6 +286,42 @@ namespace Radegast.Rendering
 \r
     public static class RHelp\r
     {\r
+        static float t1 = 0.04f;\r
+        static float t2 = t1 / 5.7f;\r
+\r
+        public static Vector3 Smoothed1stOrder(Vector3 curPos, Vector3 targetPos, double lastFrameTime)\r
+        {\r
+            int numIterations = (int)(lastFrameTime * 100);\r
+            do\r
+            {\r
+                curPos += (targetPos - curPos) * t1;\r
+                numIterations--;\r
+            }\r
+            while (numIterations > 0);\r
+            if (Vector3.DistanceSquared(curPos, targetPos) < 0.000001)\r
+            {\r
+                curPos = targetPos;\r
+            }\r
+            return curPos;\r
+        }\r
+\r
+        public static Vector3 Smoothed2ndOrder(Vector3 curPos, Vector3 targetPos, ref Vector3 accel, double lastFrameTime)\r
+        {\r
+            int numIterations = (int)(lastFrameTime * 100);\r
+            do\r
+            {\r
+                accel += (targetPos - accel - curPos) * t1;\r
+                curPos += accel * t2;\r
+                numIterations--;\r
+            }\r
+            while (numIterations > 0);\r
+            if (Vector3.DistanceSquared(curPos, targetPos) < 0.000001)\r
+            {\r
+                curPos = targetPos;\r
+            }\r
+            return curPos;\r
+        }\r
+\r
         public static OpenTK.Vector2 TKVector3(Vector2 v)\r
         {\r
             return new OpenTK.Vector2(v.X, v.Y);\r
@@ -330,14 +366,24 @@ namespace Radegast.Rendering
         void Modify()\r
         {\r
             mModified = true;\r
-            if (TimeToTarget <= 0)\r
+        }\r
+\r
+        public void Step(double time)\r
+        {\r
+            if (RenderPosition != Position)\r
+            {\r
+                RenderPosition = RHelp.Smoothed1stOrder(RenderPosition, Position, time);\r
+                Modified = true;\r
+            }\r
+            if (RenderFocalPoint != FocalPoint)\r
             {\r
-                RenderPosition = Position;\r
-                RenderFocalPoint = FocalPoint;\r
+                RenderFocalPoint = RHelp.Smoothed1stOrder(RenderFocalPoint, FocalPoint, time);\r
+                Modified = true;\r
             }\r
         }\r
 \r
-        public void Step(double time)\r
+        [Obsolete("Use Step(), left in here for reference")]\r
+        public void Step2(double time)\r
         {\r
             TimeToTarget -= time;\r
             if (TimeToTarget <= time)\r
@@ -1076,6 +1122,7 @@ namespace Radegast.Rendering
 \r
         public byte[] VisualAppearanceParameters = new byte[1024];\r
         bool vpsent = false;\r
+        static bool lindenMeshesLoaded = false;\r
 \r
         public GLAvatar()\r
         {\r
@@ -1101,6 +1148,9 @@ namespace Radegast.Rendering
 \r
         public static void loadlindenmeshes2(string LODfilename)\r
         {\r
+            // Already have mashes loaded?\r
+            if (lindenMeshesLoaded) return;\r
+\r
             attachment_points.Clear();\r
 \r
 \r
@@ -1264,6 +1314,7 @@ namespace Radegast.Rendering
                 }\r
             }\r
 \r
+            lindenMeshesLoaded = true;\r
         }\r
 \r
         public void morphtest(Avatar av, int param, float weight)\r