Browse Source

*** empty log message ***

Mark Mine 25 years ago
parent
commit
caeaf79805

+ 13 - 8
direct/src/directdevices/DirectJoybox.py

@@ -292,7 +292,7 @@ class DirectJoybox(PandaObject):
             np2planet = Vec3(self.nodePath.getPos(planet))
             # Compute dist
             offsetDist = np2planet.length()
-            # Too high, never mind
+            # Above threshold, leave velocity vec as is
             if offsetDist > (1.2 * radius):
                 pass
             else:
@@ -304,14 +304,19 @@ class DirectJoybox(PandaObject):
                 # Xform fly vec to planet space
                 dPlanet = self.nodePath.getMat(planet).xformVec(Vec3(0, dy, 0))
                 # Compute radial component of fly vec
-                radialComponent = oNorm * oNorm.dot(dPlanet)
-                # If within transition zone, begin subtracting radial component
-                above = offsetDist - radius
-                sf = max(1.0 - (max(above, 0.0)/(0.2 * radius)), 0.0)
-                if offsetDist < radius:
+                dotProd = oNorm.dot(dPlanet)
+                if dotProd < 0:
+                    # Trying to fly below radius, compute radial component
+                    radialComponent = oNorm * dotProd
+                    # How far above?
+                    above = offsetDist - radius
+                    # Set sf accordingly
+                    sf = max(1.0 - (max(above, 0.0)/(0.2 * radius)), 0.0)
+                    # Subtract scaled radial component
                     dPlanet -= radialComponent * (sf * sf)
-                # Convert back to node path space
-                dPos.assign(planet.getMat(self.nodePath).xformVec(dPlanet))
+                    #dPlanet -= radialComponent
+                    # Convert back to node path space
+                    dPos.assign(planet.getMat(self.nodePath).xformVec(dPlanet))
         # Set pos accordingly
         self.nodePath.setPos(self.nodePath, dPos)
 

+ 1 - 0
direct/src/directtools/DirectSession.py

@@ -1,4 +1,5 @@
 from PandaObject import *
+from DirectUtil import *
 from DirectCameraControl import *
 from DirectManipulation import *
 from DirectSelection import *

+ 81 - 0
direct/src/directtools/DirectUtil.py

@@ -0,0 +1,81 @@
+from PandaObject import *
+
+## Background Color ##
+def setBackgroundColor(r,g,b):
+    base.win.getGsg().setColorClearValue(VBase4(r, g, b, 1.0))
+
+def lerpBackgroundColor(r,g,b,duration):
+    def lerpColor(state):
+        dt = globalClock.getDt()
+        state.time += dt
+        sf = state.time / state.duration
+        if sf >= 1.0:
+            setBackgroundColor(state.ec[0], state.ec[1], state.ec[2])
+            return Task.done
+        else:
+            r = sf * state.ec[0] + (1 - sf) * state.sc[0]
+            g = sf * state.ec[1] + (1 - sf) * state.sc[1]
+            b = sf * state.ec[2] + (1 - sf) * state.sc[2]
+            setBackgroundColor(r,g,b)
+            return Task.cont
+    taskMgr.removeTasksNamed('lerpBackgroundColor')
+    t = taskMgr.spawnMethodNamed(lerpColor, 'lerpBackgroundColor')
+    t.time = 0.0
+    t.duration = duration
+    t.sc = base.win.getGsg().getColorClearValue()
+    t.ec = VBase4(r,g,b,1)
+
+Q_EPSILON = 1e-10
+
+def qSlerp(startQuat, endQuat, t):
+    startQ = Quat(startQuat)
+    destQuat = Quat.identQuat()
+    # Calc dot product
+    cosOmega = (startQ.getI() * endQuat.getI() +
+                startQ.getJ() * endQuat.getJ() + 
+                startQ.getK() * endQuat.getK() +
+                startQ.getR() * endQuat.getR())
+    # If the above dot product is negative, it would be better to
+    # go between the negative of the initial and the final, so that
+    # we take the shorter path.  
+    if ( cosOmega < 0.0 ):
+        cosOmega *= -1
+        startQ.setI(-1 * startQ.getI())
+        startQ.setJ(-1 * startQ.getJ())
+        startQ.setK(-1 * startQ.getK())
+        startQ.setR(-1 * startQ.getR())
+    if ((1.0 + cosOmega) > Q_EPSILON):
+        # usual case
+        if ((1.0 - cosOmega) > Q_EPSILON):
+            # usual case
+            omega = math.acos(cosOmega)
+            sinOmega = math.sin(omega)
+            startScale = math.sin((1.0 - t) * omega)/sinOmega
+            endScale = math.sin(t * omega)/sinOmega
+        else:
+            # ends very close 
+            startScale = 1.0 - t
+            endScale = t
+        destQuat.setI(startScale * startQ.getI() +
+                      endScale * endQuat.getI())
+        destQuat.setJ(startScale * startQ.getJ() +
+                      endScale * endQuat.getJ())
+        destQuat.setK(startScale * startQ.getK() +
+                      endScale * endQuat.getK())
+        destQuat.setR(startScale * startQ.getR() +
+                      endScale * endQuat.getR())
+    else:
+        # ends nearly opposite
+        destQuat.setI(-startQ.getJ())
+        destQuat.setJ(startQ.getI())
+        destQuat.setK(-startQ.getR())
+        destQuat.setR(startQ.getK())
+        startScale = math.sin((0.5 - t) * math.pi)
+        endScale = math.sin(t * math.pi)
+        destQuat.setI(startScale * startQ.getI() +
+                      endScale * endQuat.getI())
+        destQuat.setJ(startScale * startQ.getJ() +
+                      endScale * endQuat.getJ())
+        destQuat.setK(startScale * startQ.getK() +
+                      endScale * endQuat.getK())
+    return destQuat

File diff suppressed because it is too large
+ 286 - 320
direct/src/tkpanels/MopathRecorder.py


Some files were not shown because too many files changed in this diff