From 15a155032c024b48dd55ff3783323aaa0fe783a6 Mon Sep 17 00:00:00 2001 From: Mark Mine Date: Wed, 14 Mar 2001 04:24:20 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/directtools/DirectUtil.py | 23 ++++++ direct/src/extensions/NodePath-extensions.py | 87 ++++++++++++++++++++ direct/src/interval/PosHprInterval.py | 4 +- 3 files changed, 112 insertions(+), 2 deletions(-) diff --git a/direct/src/directtools/DirectUtil.py b/direct/src/directtools/DirectUtil.py index 670cf64869..85451d67b0 100644 --- a/direct/src/directtools/DirectUtil.py +++ b/direct/src/directtools/DirectUtil.py @@ -27,6 +27,7 @@ def lerpBackgroundColor(r,g,b,duration): Q_EPSILON = 1e-10 +# Quaternion interpolation def qSlerp(startQuat, endQuat, t): startQ = Quat(startQuat) destQuat = Quat.identQuat() @@ -79,3 +80,25 @@ def qSlerp(startQuat, endQuat, t): destQuat.setK(startScale * startQ.getK() + endScale * endQuat.getK()) return destQuat + +# File data util +def getFileData(filename, separator = ','): + """ + Open the specified file and strip out unwanted whitespace and + empty lines. Return file as list of lists, one file line per element, + list elements based upon separator + """ + f = open(filename.toOsSpecific(), 'r') + rawData = f.readlines() + f.close() + fileData = [] + for line in rawData: + # First strip whitespace from both ends of line + l = string.strip(line) + if l: + # If its a valid line, split on separator and + # strip leading/trailing whitespace from each element + data = map(string.strip, l.split(separator)) + fileData.append(data) + return fileData + diff --git a/direct/src/extensions/NodePath-extensions.py b/direct/src/extensions/NodePath-extensions.py index 1f3f16baef..e688f3ec3a 100644 --- a/direct/src/extensions/NodePath-extensions.py +++ b/direct/src/extensions/NodePath-extensions.py @@ -106,6 +106,93 @@ else: return [self] + def pprintPos(self, sd = 2): + """ Pretty print a node path's pos """ + from PandaObject import * + formatString = '%0.' + '%d' % sd + 'f' + pos = self.getPos() + print (self.getName() + '.setPos(' + + formatString % pos[0] + ', ' + + formatString % pos[1] + ', ' + + formatString % pos[2] + + ')\n') + + def pprintHpr(self, sd = 2): + """ Pretty print a node path's hpr """ + from PandaObject import * + formatString = '%0.' + '%d' % sd + 'f' + hpr = self.getHpr() + print (self.getName() + '.setHpr(' + + formatString % hpr[0] + ', ' + + formatString % hpr[1] + ', ' + + formatString % hpr[2] + + ')\n') + + def pprintScale(self, sd = 2): + """ Pretty print a node path's scale """ + from PandaObject import * + formatString = '%0.' + '%d' % sd + 'f' + scale = self.getScale() + print (self.getName() + '.setScale(' + + formatString % scale[0] + ', ' + + formatString % scale[1] + ', ' + + formatString % scale[2] + + ')\n') + + def pprintPosHpr(self, sd = 2): + """ Pretty print a node path's pos and, hpr """ + from PandaObject import * + formatString = '%0.' + '%d' % sd + 'f' + pos = self.getPos() + hpr = self.getHpr() + print (self.getName() + '.setPosHpr(' + + formatString % pos[0] + ', ' + + formatString % pos[1] + ', ' + + formatString % pos[2] + ', ' + + formatString % hpr[0] + ', ' + + formatString % hpr[1] + ', ' + + formatString % hpr[2] + + ')\n') + + def pprintPosHprScale(self, sd = 2): + """ Pretty print a node path's pos, hpr, and scale """ + from PandaObject import * + formatString = '%0.' + '%d' % sd + 'f' + pos = self.getPos() + hpr = self.getHpr() + scale = self.getScale() + print (self.getName() + '.setPosHprScale(' + + formatString % pos[0] + ', ' + + formatString % pos[1] + ', ' + + formatString % pos[2] + ', ' + + formatString % hpr[0] + ', ' + + formatString % hpr[1] + ', ' + + formatString % hpr[2] + ', ' + + formatString % scale[0] + ', ' + + formatString % scale[1] + ', ' + + formatString % scale[2] + + ')\n') + + def zeroPos(self): + """ Set node path's pos to 0,0,0 """ + self.setPos(0,0,0) + + def zeroHpr(self): + """ Set node path's hpr to 0,0,0 """ + self.setHpr(0,0,0) + + def unitScale(self): + """ SEt node path's scale to 1,1,1 """ + self.setScale(1,1,1) + + def zeroPosHpr(self): + """ Set node path's pos and hpr to 0,0,0 """ + self.setPosHpr(0,0,0,0,0,0) + + def reset(self): + """ Set node path's pos and hpr to 0,0,0 and scale to 1,1,1 """ + self.setPosHprScale(0,0,0,0,0,0,1,1,1) + # private methods def __getBlend(self, blendType): diff --git a/direct/src/interval/PosHprInterval.py b/direct/src/interval/PosHprInterval.py index 17627be88f..9b834ffe08 100644 --- a/direct/src/interval/PosHprInterval.py +++ b/direct/src/interval/PosHprInterval.py @@ -47,7 +47,7 @@ class PosInterval(Interval): self.posNum = self.posNum + 1 else: n = name - Interval.__init__(n, duration) + Interval.__init__(self, n, duration) def setT(self, t, entry=0): """ setT(t, entry) @@ -74,7 +74,7 @@ class HprInterval(Interval): self.hprNum = self.hprNum + 1 else: n = name - Interval.__init__(n, duration) + Interval.__init__(self, n, duration) def setT(self, t, entry=0): """ setT(t, entry)