View previous topic :: View next topic |
Author |
Message |
Karynax
Joined: 21 Mar 2008 Posts: 2
|
Posted: Fri Mar 21, 2008 5:34 am Post subject: Patch for fixing camera "spasms" |
|
|
I've observed that when ever your view passes through the "south" line (i.e. 180degree turn from the start view) it would "spasm".
I traced the problem to the Spring class. My first impression is that it was going the long way around the circle line up the tail's angle(camera) and the head's angle(ship). However when added a fix for this I found that it still spasmed, although differently.
Looking closer I found that when it crossed the south the angle the angles produced by Matrix.toAxis() were widely different. Although the two angles are widely different, they are functionally very similar to a viewer but when interpolated between the difference becomes very obvious.
The solution I came up with was to convert the facing to Euler angles and do interpolation with those and convert them back into the transform.
This works well as far as I've tested but I can't help but feel there is a better solution to this.
Code: |
Index: src/yage/util/spring.d
===================================================================
--- src/yage/util/spring.d (revision 61)
+++ src/yage/util/spring.d (working copy)
@@ -7,6 +7,7 @@
module yage.util.spring;
import std.stdio;
+import std.math;
import yage.core.all;
import yage.node.all;
@@ -54,10 +55,33 @@
/// Update the position of the floater relative to what it's attached to.
void update(float delta){
- Vec3f h = head.getAbsoluteRotation();
- Vec3f t = tail.getAbsoluteRotation();
- tail.setRotation(Vec3f((t.x+h.x)/2, (t.y+h.y)/2, (t.z+h.z)/2));
+ float dt = delta * stiffness;
+ if(dt > 1) {
+ dt = 1;
+ } else if (dt < 0) {
+ dt = 0;
+ }
+ //This may break if h passes straight through directly "up" or "down"
+ Vec3f h = head.getAbsoluteTransform().toEuler();
+ Vec3f t = tail.getAbsoluteTransform().toEuler();
+ //Gets an angle that is amt ratio from angle a to angle b.
+ //Assumes a and b are 2*PI at most apart.
+ float midangle(float a, float b, float amt) {
+ float d = b - a;
+ if(d > PI) {
+ d -= 2 * PI;
+ } else if(d < -PI) {
+ d += 2 * PI;
+ }
+ return a + d * amt;
+ }
+ Vec3f m = Vec3f(midangle(t.x, h.x, dt), midangle(t.y, h.y, dt), midangle(t.z, h.z, dt));
+ Matrix n;
+ n.setEuler(m);
+ tail.setRotation(n.toAxis());
+
+
Vec3f dist = head.getAbsolutePosition() - tail.getAbsolutePosition() + distance.rotate(head.getAbsoluteTransform());
Vec3f vel = dist.scale(min(stiffness, 1/delta)); // scale by 1/delta when framerate is low to prevent jerkiness.
|
|
|
Back to top |
|
|
JoeCoder
Joined: 29 Oct 2005 Posts: 294
|
Posted: Wed Apr 02, 2008 11:04 am Post subject: |
|
|
I noticed that also. It's actually a regression that came up when Deformative was converting the input system to a better implementation, a few revisions ago. Unfortunately my life's circumstances have made me busy every hour of every day and I don't have time for fun projects any more. I definitely want to continue Yage again someday though.
[Edit]
Didn't want to cast Deformative in a bad light, despite that one regression he's made significant contributions. |
|
Back to top |
|
|
JoeCoder
Joined: 29 Oct 2005 Posts: 294
|
Posted: Tue May 13, 2008 7:25 pm Post subject: |
|
|
This is now fixed. You can check out my change in the Spring class in the repo. It's basically just reverting back to rev56 of the file, which has no angular interpolation for the tail of the spring, but I've found that things look just fine without it (at least to me).
I'm hoping I'll start having more time in the future to start working on Yage again, but time will tell. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|