Skip to content

Instantly share code, notes, and snippets.

@febret
Created December 29, 2014 02:25
Show Gist options
  • Save febret/58cb73b8b98a3f238a62 to your computer and use it in GitHub Desktop.
Save febret/58cb73b8b98a3f238a62 to your computer and use it in GitHub Desktop.
Actor Basic Example
# This example creates a spinning cube every time the user right-clicks on the window.
# A custom Actor keeps track of each cube spinning.
from math import *
from euclid import *
from omega import *
from omegaToolkit import *
from cyclops import *
# The actor list is needed to avoid garbage-collecting alive actors.
actors = []
class SpinningCube(Actor):
cube = None # The cube
def __init__(self, position):
super(SpinningCube, self).__init__("spinCube")
actors.append(self) # Add myself to the actor list
# Setup the cube
self.cube = BoxShape.create(0.5, 0.5, 0.5)
self.cube.setPosition(position)
self.cube.setEffect('colored -d #ff8080')
self.setUpdateEnabled(True) # Enable the update callback
def dispose(self):
# remove myself (and the cube) from the scene.
actors.remove(self)
self.cube.getParent().removeChildByRef(self.cube)
# Update animates the cube
def onUpdate(self, frame, time, dt):
self.cube.yaw(dt)
self.cube.pitch(sin(time) / 5.0)
scene = getSceneManager()
# Create light
light1 = Light.create()
light1.setColor(Color(0.8, 0.8, 0.8, 1))
light1.setPosition(Vector3(0, 4, -4))
light1.setEnabled(True)
def onEvent():
e = getEvent()
if(e.getServiceType() == ServiceType.Pointer):
if(e.isButtonDown(EventFlags.Button2)):
r = getRayFromEvent(e)
# Create a new spinning cube 5 meters away from the pointer
pos = r[1] + r[2] * 5
SpinningCube(pos)
setEventFunction(onEvent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment