Abstract
The FrameSJC Library is a substitute library for VPython frame objects that uses OpenGL pipeline
instead of VPython's internal graphics pipeline. Previously, students who implement their programs
in VPython were not able to run their code in the Cube because of compatibility issues. This library
resolves this issue by reproducing the frame objects' hierarchy using OpenGL's matrix
operations. Even though the backend implementation is completely different, VPython syntax is preserved
as much as possible to allow programmers to develop their program using VPython and switch over to the Cube
environment with minimal code conversion.
Progress
The prototype of the project was presented during the SAS on F12.
I was able to run Sarah Hovey's workoutguy.py in the Cube with my
port of the VPython library. Since then, lighting had been added to the library to make the objects look nicer.
The bug which caused the guy's legs and arms to widen up more and more over iterations of the animation was actually not found out to be a bug.
Because the original program was only designed for one iteration of the animation, it did not return the guy's arms and legs to the original position
at the end of the animation. Therefore, when the animation was repeated in a while-loop, the difference between the original position and the animation
adde up and the guy looked more and more out of position. This was fixed by forcing the guy to go back to the initial position before running the animation.
In addition, Tyler Ingram's Orndroids program was also ported to the SZG environment. Below are screenshots of his program running in Aszgard.
This was easier port than Hovey's program because porting had been already done once and Orndroids already had an infinite while-loop for its animations.
Implementation Details
There is a display() object called scene which contains all the objects in the scene. The objects within the scene are rendered by calling scene's
draw() method. This method is called inside the SZG onDraw() callback method.
Individual objects are either a frame object or a child of the frame object. Each object has at least color, position, and orientation. If the user does
not specify any one of these, a default value is taken for that element. Objects like a sphere, cylinder, cone, or arrow have additional members such as radius
and/or length.
Hierarchy of the different objects are specified by specifying which frame is their parent when creating the object. By doing so, I am able to construct
a scene graph internally. When a frame object is rendered, it does the following. In pseudo-code:
pushMatrix()
multiplyFrameMatrix()
drawItself()
drawChildren()
popMatrix()
This way, we are able to keep the parent's transformations applied after the child object is drawn and recursively render all its descendants.
Usage Instructions
The user's code need to be refactored into a thread object which has the following form.
from FrameSJC import *
import threading
class appThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
# user's initialization code
def run(self):
while 1:
# user's display loop
Then, we need the following from the szg code.
from szg import *
from FrameSJC import *
import appfilename
class nameApp(arPyMasterSlaveFramework)::
def onWindowStartGL( self, winInfo ):
frameSJCInit()
self.appthread = appfilename.appThread()
self.appthread.start()
# other initialization code
def onDraw( self, win, viewport ):
scene.draw()
# other rendering code
Finally, we are able to run this inside the Cube by running the szg code above. The library's rendering code and user's animation code
runs concurrently in separate threads with the library code in the main thread (to access OpenGL) and user's animation code in another thread,
applying transformations to objects as necessary.
*The above code only has changes that needs to be made to the existing szg framework. Please look at one of the example codes
from the szg demo programs for a complete source.
Source
Source files are located under
/repo/class198f11/chung38/FinalProject/ directory. It is currently called FrameSJC.py.
Examples of ported codes using my library is in workoutguy.py and szgworkoutguy.py for Sarah Hovey's program and in
orndroids.py and szgorndroids.py for Tyler Ingram's program.
Goals
All the previous goals have been accomplished. Next goal is to teach other students how to use the library to port their
programs into the Cube and try porting horsewalk.py.