Final Project: The SZG-VPython Library

November 4, 2011Posted by Se-Joon Chung

 

Abstract

The SZG-VPython Library is a substitute library for VPython frame objects that uses OpenGL pipeline instead of VPython's internal graphics pipeline. Currently, students who implement their programs in VPython are not able to run their code in the Cube because of compatibility issues. This library seeks to resolve this issue by reproducing the frame objects' hierarchy using OpenGL's matrix operations. Even though the backend implementation will be 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.

Source

Source files are located under /repo/class198f11/chung38/FinalProject/ directory. It is currently called FrameSJC.py.

Current State

Currently, the ordering of the hierarchy of matrix transformations is implemented. Next step is to implement objects to be drawn onto the screen on top of the framework.

Goals

The short-term goal is to get some VPython projects into the Cube for next Friday's SAS. The long-term goal is to get other students' VPython projects into the Cube with minimal code conversion.

Wishes

My wish is to completely port all of VPython commands into OpenGL so that any VPython program would run in the Cube. However, I will need to prioritize which commands to port first as I will likely not have time to do all.

Final Project: The FrameSJC Library

November 14, 2011Posted by Se-Joon Chung

 

Abstract

The FrameSJC Library is a substitute library for VPython frame objects that uses OpenGL pipeline instead of VPython's internal graphics pipeline. Currently, students who implement their programs in VPython are not able to run their code in the Cube because of compatibility issues. This library seeks to resolve this issue by reproducing the frame objects' hierarchy using OpenGL's matrix operations. Even though the backend implementation will be 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. There was no lighting implemented at this time. There was a bug in the matrix calculation that was discovered while animating the work out guy repeatedly in the Cube. After a while, the joints do not come back to initial positions due to precision error in the matrix calculations. The picture of the bug happening is shown below.

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, or cone 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.

Source

Source files are located under /repo/class198f11/chung38/FinalProject/ directory. It is currently called FrameSJC.py.

Goals

Previous goal of getting a VPython project into the Cube for the SAS was accomplished. Next goal is to fix bugs in the matrix calculation, implement lighting and get more projects into the Cube.

Final Project: The FrameSJC Library

November 27, 2011Posted by Se-Joon Chung

 

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.