#1
|
|||
|
|||
velocity conversion
I am moving an object using the vizact.move command which takes
meters/sec as an argument for speed. How would I convert the meters/sec velocity to a screenpixels/sec velocity? |
#2
|
|||
|
|||
If the object is added to the screen (viz.ORTHO), then the units will already by in pixels/sec. If the object is added to the world (viz.WORLD), then it gets more complicated. Is your object part of the screen or world?
|
#3
|
|||
|
|||
The object is in the world. I know it's more complicated - that's
why I know you have the answer. |
#4
|
|||
|
|||
I'm assuming that the viewpoint is fixed while the object is moving? Otherwise it will be REALLY complicated
|
#5
|
|||
|
|||
Yes, the viewpoint is stationary.
|
#6
|
|||
|
|||
Here is a script that creates an action that is similar to vizact.goto() except the speed is in pixels/sec. Run the script and press space bar to run the action.
Code:
import viz viz.go() class MovePixelSpeedAction(viz.ActionClass): def convertToPixels(self,pos): screen = self.window.worldToScreen(pos) screen[0] *= self.size[0] screen[1] *= self.size[1] screen[2] = 0.0 return screen def intersectLine(self,line1,line2): o1 = viz.Vector(line1.getBegin()) o2 = viz.Vector(line2.getBegin()) d1 = viz.Vector(line1.getDir(),normalize=True) d2 = viz.Vector(line2.getDir(),normalize=True) c = d1 ^ d2 clen = c.length() if clen == 0.0: return o1 #Compute determinant v = o2 - o1 d = (v[0] * (d2[1]*c[2] - d2[2]*c[1])) - (v[1] * (d2[0]*c[2]-d2[2]*c[0])) + (v[2] * (d2[0]*c[1]-d2[1]*c[0])) d1.setLength(d / (clen * clen)) return o1 + d1 def begin(self,object): self.window = viz.MainWindow self.size = self.window.getSize(viz.WINDOW_PIXELS) #Get begin/end positions beginVal = object.getPosition() endVal = vizact._paramlist_(self._actiondata_.pos,object) #Convert to pixel coordinates beginScreenVal = self.convertToPixels(beginVal) endScreenVal = self.convertToPixels(endVal) #Compute distance to travel dist = vizmat.Distance(beginScreenVal,endScreenVal) if dist == 0.0: self.end(object) return #Get velocity vel = vizact._paramval_(self._actiondata_.vel,object) #Calculate duration self.duration = dist / vel #Initialize variables self.elapsed = 0.0 self.endVal = endVal self.beginScreenVal = beginScreenVal self.endScreenVal = endScreenVal self.worldLine = viz.Line(begin=beginVal,end=endVal) def update(self,elapsed,object): self.elapsed += elapsed p = self.elapsed / self.duration if p >= 1.0: self._overtime_ = self.elapsed - self.duration object.translate(self.endVal) self.end(object) return #Interpolate screen pos from screen velocity screenPos = vizmat.Interpolate(self.beginScreenVal,self.endScreenVal,p) #Convert screen location to world vector line = self.window.screenToWorld( [screenPos[0]/self.size[0],screenPos[1]/self.size[1]] ) #Intersect vector with world vector of movement path pos = self.intersectLine(self.worldLine,line) object.translate(pos) def movePixelSpeed(pos,vel): bla = viz.ActionData() bla.pos = pos bla.vel = vel bla.actionclass = MovePixelSpeedAction return bla START_POS = (0,0,8) STOP_POS = (0,4,30) ball = viz.add('ball.wrl',pos=START_POS) def RunAction(): ball.translate(START_POS) ball.runAction(movePixelSpeed(STOP_POS,100)) vizact.onkeydown(' ',RunAction) |
#7
|
|||
|
|||
We are all humbled by your brilliance (I mean it!)
|
Thread Tools | |
Display Modes | Rate This Thread |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Face Conversion Integrity | nickyee | Vizard | 3 | 09-08-2004 08:38 PM |
angle conversion | DSparrow | Vizard | 3 | 04-21-2004 11:41 AM |