
Any help would be gratefully recieved ...
from Plasma import *
from PlasmaTypes import *
from PlasmaNetConstants import *
from xPsnlVaultSDL import *
import math
import time
class ScnObjManipulator:
def __init__(self,object,agename):
try:
self.scnobj = PtFindSceneobject(object, agename)
except:
self.scnobj = None
self.initialMtx = self.getMatrix()
# resets the object to the initial position and scale
def reset(self):
self.setMatrix(self.initialMtx)
def getMatrix(self):
return self.scnobj.getLocalToWorld()
def setMatrix(self,l2w):
# this is a weird way of calculating an inverse matrix, the getInverse() function
# actually stores the inverse matrix into the matrix that is used as an argument.
w2l = ptMatrix44()
l2w.getInverse(w2l)
self.scnobj.setTransform(l2w,w2l)
# Scales an object - relative to current scale
def scale(self,scale):
l2w = self.getMatrix()
self.setScale(scale,l2w)
# Scales an object - relative to initial scale
def setScale(self,scale,initialmtx=None):
if initialmtx is None:
initialmtx = self.initialMtx
scalemtx = ptMatrix44()
scalemtx.makeScaleMat(scale)
initialmtx *= scalemtx
self.setMatrix(initialmtx)
# Moves an object - relative to current position
def move(self,vector):
l2w = self.getMatrix()
self.setMove(vector,l2w)
# Moves an object - relative to initial position
def setMove(self,vector,initialmtx=None):
if initialmtx is None:
initialmtx = self.initialMtx
trltmtx = ptMatrix44()
trltmtx.makeTranslateMat(vector)
initialmtx *= trltmtx
self.setMatrix(initialmtx)
# Rotates an object - relative to current rotation
def rotate(self,anglevector,radians):
l2w = self.getMatrix()
self.setRotation(anglevector,radians,l2w)
# Rotates an object - relative to initial rotation
def setRotation(self,anglevector,radians,initialmtx=None):
if initialmtx is None:
initialmtx = self.initialMtx
fullrotmtx = ptMatrix44()
# now, apply relative transformations for the anglevector
anglevector.normalize() # normalize before using it for scale
# for the X part
xfactor = anglevector.getX()
rotmat = ptMatrix44()
rotmat.makeRotateMat(0,radians*xfactor)
fullrotmtx *= rotmat
# for the Y part
yfactor = anglevector.getY()
rotmat = ptMatrix44()
rotmat.makeRotateMat(2,radians*yfactor)
fullrotmtx *= rotmat
# for the Z part
zfactor = anglevector.getZ()
rotmat = ptMatrix44()
rotmat.makeRotateMat(1,radians*zfactor)
fullrotmtx *= rotmat
initialmtx *= fullrotmtx
self.setMatrix(initialmtx)
class FuncChk01(ptResponder,):
__module__ = __name__
def __init__(self):
ptResponder.__init__(self)
self.RotTestObj = none
def OnServerInitComplete(self):
# Obtain the piston objects
self.RotTestObj = ScnObjManipulator("Rotate1",self.AgeName)
# Register a timer callback for moving the piston objects
PtAtTimeCallback(self.key, self.MovePistonInterval, self.MovePistonTimerId)
def OnTimer(self, id):
# Check for the piston timer
if (id == self.MovePistonTimerId):
# Calculate the height offset of the pistons, based on the time
currentTime = time.clock()
# Warp the pistons to the new height
# Rotational object
rotOffset = (math.sin(2.0*currentTime) *0.05) + 1.0
angle = ptVector3(0.0,0.0,1.0)
self.RotTestObj.rotate(angle,rotOffset);
# Register for another piston update
PtAtTimeCallback(self.key, self.MovePistonInterval, self.MovePistonTimerId)
# x.x,y.y,Z.Z
angle = ptVector3(0.0,0.0,1.0)
myobject.rotate(angle,math.pi/2)
Users browsing this forum: No registered users and 4 guests