Ray Tracing and Rasturizer HELP needed ASAP

Printer-friendly version

Author: 

Taxonomy upgrade extras: 

is there anyone that is familiar with this because I am having difficulty with my rasturizer and ray tracer due tonight

Comments

Render Farm Fun

Piper's picture

R u in need of processing power, a new rendering platform, or something else?

-Piper


"She was like a butterfly, full of color and vibrancy when she chose to open her wings, yet hardly visible when she closed them."
— Geraldine Brooks


I'm not sure what I'm doing

import pygame
import math3d
import math
import objects3d

class RayTracer(object):
""" A Raytracer. Note: this is in a right-handed coordinate system. """

def __init__(self, renderSurf):
if not isinstance(renderSurf, pygame.Surface):
raise TypeError("You must pass a pygame Surface for renderSurf")
self.renderSurf = renderSurf # A pointer to the surface we'll render to.
self.pixelWidth = renderSurf.get_width() # Pygame width (in pixels)
self.pixelHeight = renderSurf.get_height() # Pygame height (in pixels)
# calculate the aspect ratio
self.aspectRatio = self.pixelWidth / self.pixelHeight # The aspect ratio of the render surface.
# Note: the virtual view screen should have a similar
# aspect ratio
# Set dummy values for those camera-related attributes that will be set by setCamera (camera-related)
# Unless otherwise specified, assume they are a scalar
self.cameraPos = None # The 3d position of the camera
self.cameraNear = None # The distance of the view screen in front of the camera
self.cameraFar = None # The maximum distance of objects from the viewer.
self.cameraHalfAngle = None # Half of the angle made by two vectors: v and w, where v goes from
# the camera to the top-middle of the view screen; w goes to the
# bottom-middle.
self.cameraX = None # The unit-length "right" direction (vector3) of the camera coordinate system
self.cameraY = None # The unit-length "up" direction (vector3) of the camera coordinate system
self.cameraZ = None # The unit-length "forward" direction (vector3) of the camera coordinate system
# Set dummy values for those view-screen-related attributes that will be set by setCamera (view-plane-related)

self.renderObjects = [] # objects3d.TriMesh objects

# FINISH ME: Construct the Clip=>Screen matrix here (self.clip2screen)

def setCamera(self, cameraPos, cameraInterest, cameraUp, near, far, \
viewAngle):
""" Sets the camera viewing the scene. """
self.cameraPos = cameraPos.copy()
self.cameraNear = near
self.cameraFar = far
self.cameraHalfAngle = viewAngle / 2.0 # In degrees

# Calculate self.cameraX, Y, Z (make sure they're unit length)
self.cameraZ = (cameraPos - cameraInterest).normalizeCopy()
self.cameraX = math3d.cross(cameraUp, self.cameraZ).normalizeCopy()
self.cameraY = math3d.cross(self.cameraZ, self.cameraX).normalizeCopy()

# Construct the World=>View matrix (self.world2view)
# Step1. Translate camera to origin
T = math3d.MatrixN(4, 4)
# ...FINISH ME: Set values of T
# Step2. Rotate camera axes to line up with world axes
R = math3d.MatrixN(4, 4)
# ...FINISH ME: Set values of R
# Step3. FINISH ME: self.world2view matrix is the concatenation of T & R

# FINISH ME: Construct the View=>Clip matrix (self.view2clip)

def addObject(self, o):
if not isinstance(o, objects3d.TriMesh):
raise TypeError("You can only pass a TriMesh object.")
self.renderObjects.append(o)

def render(self):
""" Rasterize the scene, and draw lines (polygons) to self.renderSurf """

# Go through each renderable object
for o in self.renderObjects:
# Go through each vertex and transform to screen space
screen_space_verts = []
for v in o.vlist:
# FINISH ME: Feed v through the "pipeline" to get vprime.
vprime = v.copy() # Temporary.

# Add vprime to screen_space_verts
# Note vprime.x and vprime.y are pygame coordinates
screen_space_verts.append(vprime)

# Go through each face and draw a pygame polygon
for f in o.flist:
# Draw a polygon to connect the vert's
a = (int(screen_space_verts[f[0]].x), int(screen_space_verts[f[0]].y))
b = (int(screen_space_verts[f[1]].x), int(screen_space_verts[f[1]].y))
c = (int(screen_space_verts[f[2]].x), int(screen_space_verts[f[2]].y))
pygame.draw.polygon(self.renderSurf, o.color, (a,b,c), 1)

hugs :)
Michelle SidheElf Amaianna

giggles

I've very seldom had a "good" teacher in the computing arts. Generally, you teach yourself and try to figure out what bull your prof wants you to spew on demand for his tests, ignoring it otherwise.

Abigail Drew.