Hi @matrixloong ,
Please excuse the delayed answer.
The real-time scenario is one of those that might not go very smoothly in cinema (check the links in my previous message). It was already discussed in the thread: Is it possible to control Camera with keyboard WASD like a FPS game?
Ferdinand showed there one of the possible solutions to achieve live interactions on the scene using interaction dialog. You can use the simplified version of it below.
Cheers,
Ilia
Run this code from the script manager and select an object in the object manager.
import c4d, time, math
doc: c4d.documents.BaseDocument # The active document
class InteractionDialog(c4d.gui.GeDialog):
TIMER_DELAY = 40
def CreateLayout(self):
return True
def InitValues(self):
self._doc: c4d.BaseDocument = doc
self.SetTimer(InteractionDialog.TIMER_DELAY)
self._time = None
self._lastTime = None
self._angle = 0
return True
def Timer(self, msg):
# Initialize the time for the first frame a key is being pressed.
if self._lastTime is None:
self._lastTime = time.time()
return None
# The delta between now and the last evaluation
dt = time.time() - self._lastTime
self.DoSomething(dt)
self._lastTime = time.time()
def DoSomething(self, dt):
op: c4d.BaseObject = self._doc.GetActiveObject()
if not op:
return
PI2 = 2 * math.pi
angleIncrement = dt * PI2 / 2
self._angle += angleIncrement
if self._angle >= PI2:
self._angle -= PI2
ml: c4d.Matrix = op.GetMl()
bb: c4d.Vector = op.GetRad()
pos: c4d.Vector = ml.off
pos.x = bb.x * math.sin(self._angle)
ml.off = pos
op.SetMl(ml)
c4d.EventAdd()
if __name__ == '__main__':
global dialog
dialog = InteractionDialog(doc)
dialog.Open(c4d.DLG_TYPE_ASYNC)