pygame.init()
screen = pygame.display.set_mode((300, 200))  # Look at test #3
done = False

# Create a camera (use one of the camera test values)
camPos = math3d.VectorN(-15, 19, -30)
camCOI = math3d.VectorN(2, 5, 3)
camUp = math3d.VectorN(0, 1, 0)
camFOV = 60
camNear = 1.5
cam = math3d.Camera(camPos, camCOI, camUp, camFOV, camNear, screen)
objects = []  # See Phase III tester and the numbers on page 4 of the lab pdf
y = 0

objects.append(
    math3d.Sphere(math3d.VectorN(2, 5, 3), 7, math3d.VectorN(1, 0, 0)))
objects.append(
    math3d.Plane(math3d.VectorN(0, 1, 0), 5, math3d.VectorN(0, 1, 0)))
objects.append(
    math3d.Plane(math3d.VectorN(0.1, 1, 0), 4, math3d.VectorN(0, 0, 1)))

# Game Loop
while not done:
    # Update
    # Render one line of pixels in the screen (if we haven't rendered all of them
    #  yet).  Do it this way so we give the user a chance to press escape
    # while we're rendering.
    if y < screen.get_height():
        # Render one line
        for x in range(screen.get_width()):
            pos3d = cam.getPixelPos(x, y)  # The ray's origin
Пример #2
0
                                          s.mAABB.mMaxPoint[0] - s.mAABB.mMinPoint[0], s.mAABB.mMaxPoint[1] - s.mAABB.mMinPoint[1]), 2)


# Pygame setup
pygame.display.init()
pygame.font.init()
screen = pygame.display.set_mode((800, 600))
font = pygame.font.SysFont("Courier New", 15)
done = False

# "Scene" setup -- feel free to modify this and / or comment out sections as you test.
allShapes = []
mainRay = math3d.Ray(math3d.VectorN(400, 300, 0), math3d.VectorN(1, 0, 0))
allShapes.append(mainRay)
allShapes.append(
    math3d.Sphere(math3d.VectorN(200, 200, 0), 50, math3d.VectorN(1, 1, 0)))
allShapes.append(
    math3d.Plane(math3d.VectorN(0, 1, 0), 10, math3d.VectorN(0, 1, 0)))
allShapes.append(
    math3d.Plane(math3d.VectorN(20, 1, 0), 60, math3d.VectorN(0, 1, 1)))
allShapes.append(
    math3d.Plane(math3d.VectorN(-2, -7, 0), -600, math3d.VectorN(1, 0.5, 0)))
#allShapes.append(math3d.AABB(math3d.VectorN(500,450,0), math3d.VectorN(660,420,0), math3d.VectorN(0,0,1)))
#allShapes.append(math3d.Polymesh("monkey.obj", math3d.VectorN(500,100,0), 2.0, math3d.VectorN(1.0,0.3,0.8)))
#allShapes.append(math3d.Polymesh("sword.obj", math3d.VectorN(150,350,0), 10.0, math3d.VectorN(0.5,0.5,1.0)))

# Main Loop
while not done:
    ##############################
    # UPDATES                    #
    ##############################
# Pygame setup
pygame.init()
screen = pygame.display.set_mode((300, 200))
done = False

camPos = math3d.VectorN(-15, 19, -30)
camCOI = math3d.VectorN(2, 5, 3)
camUp = math3d.VectorN(0, 1, 0)
camFOV = 60.0
camNear = 1.5
cam = objects3d.Camera(camPos, camCOI, camUp, camFOV, camNear, screen)
Ambient_Light=math3d.VectorN(1,1,1)

#Shapes
allShapes = []
allShapes.append(math3d.Sphere(math3d.VectorN(2, 5, 3), 7, math3d.Material((1,0,0),(1,1,1),10,(.3,0,0))))
allShapes.append(math3d.Plane(math3d.VectorN(0,1,0), 5, math3d.Material((0,1,0),(1,0,0),2.0,(0,0.5,0))))
allShapes.append(math3d.Plane(math3d.VectorN(0.1,1,0), 4, math3d.Material((0,0,1),(1,0,1),6.0,(0,0,0.1))))

#LightSources
LightSources=[]
LightSources.append(math3d.LightSource((0,50,0),(1,1,1),(1,1,1)))
LightSources.append(math3d.LightSource((50,50,-50),(0.4,0,0),(0,0.6,0)))
y = 0

# Drawing code
for y in range(0, screen.get_height()):


# Game Loop
while not done:
screen = pygame.display.set_mode((300, 200),Flags,32)        # Look at test #3
done = False

# Create a camera (use one of the camera test values)
camPos = math3d.VectorN(-15, 19, -30)
camCOI= math3d.VectorN(2, 5, 3)
camUp = math3d.VectorN(0,1,0)
camFOV = 60
camNear = 1.5
cam = math3d.Camera(camPos,camCOI, camUp, camFOV, camNear, screen)
Ambient_Light=math3d.VectorN(1,1,1)
objects = []      # See Phase III tester and the numbers on page 4 of the lab pdf
y = 0

#Shapes
objects.append(math3d.Sphere(math3d.VectorN(2, 5, 3), 7, math3d.Material(math3d.VectorN(1,0,0),math3d.VectorN(1,1,1),10,math3d.VectorN(.3,0,0))))
objects.append(math3d.Plane(math3d.VectorN(0,1,0), 5, math3d.Material(math3d.VectorN(0,1,0),math3d.VectorN(1,0,0),2.0,math3d.VectorN(0,0.5,0))))
objects.append(math3d.Plane(math3d.VectorN(0.1,1,0).normalized(), 4, math3d.Material(math3d.VectorN(0,0,1),math3d.VectorN(1,0,1),6.0,math3d.VectorN(0,0,0.1))))
objects.append(math3d.AABB(math3d.VectorN(2,9,-6),math3d.VectorN(8,15,0),math3d.Material(math3d.VectorN(1,1,0),math3d.VectorN(0.5,1,0.5),6.0,math3d.VectorN(0.5,0.3,0.1))))
#objects.append(math3d.Polymesh("sword.obj",math3d.VectorN(-10,8,3),1.0,math3d.Material(math3d.VectorN(0.7,0,1),math3d.VectorN(1,1,1),50.0,math3d.VectorN(0.2,0,0.4))))

#LightSources
LightSources=[]
LightSources.append(math3d.LightSource(math3d.VectorN(0,50,0),math3d.VectorN(1,1,1),math3d.VectorN(1,1,1)))
LightSources.append(math3d.LightSource(math3d.VectorN(50,50,-50),math3d.VectorN(0.4,0,0),math3d.VectorN(0,0.6,0)))

# Game Loop
while not done:
    # Update
    # Render one line of pixels in the screen (if we haven't rendered all of them
    #  yet).  Do it this way so we give the user a chance to press escape