コード例 #1
0
ファイル: rotatingTorii.py プロジェクト: milosarsik/CS3388
torusOuterRadius3 = 2.0
torus3 = parametricTorus(torusT3, torusInnerRadius3, torusOuterRadius3,
                         torusCol3, torusRef3, (0.0, 2.0 * pi),
                         (0.0, 2.0 * pi), (2.0 * pi / 256.0, 2.0 * pi / 64.0))

theta = pi / 64.0
R1 = transform().rotate(vector(1.0, 0.0, 0.0), theta)
R2 = transform().rotate(vector(0.0, 1.0, 0.0), theta)
R3 = transform().rotate(vector(1.0, 1.0, 0.0), theta)

#Produce movie
FRAMES = 64
d1 = datetime.now()  #Measure the time required to produce the movie
light = lightSource(L, C, I)  #Set light source position, color, and intensity
window = graphicsWindow(WIDTH, HEIGHT)  #Create frame
camera = cameraMatrix(window, P, E, G, NP, FP,
                      THETA)  # Set camera viewing system

for i in range(FRAMES):
    print("Producing frame: ", i)
    torus1.setT(R1 * torus1.getT())
    torus2.setT(R2 * torus2.getT())
    torus3.setT(R3 * torus3.getT())
    window.drawFaces(
        tessel([torus1, torus2, torus3], camera, light).getFaceList())
    window.saveImage("/Users/beau/Desktop/movie-1/image-" + str(i).zfill(3) +
                     ".png")
    window = graphicsWindow(WIDTH, HEIGHT)  #Create frame

os.system(
    "ffmpeg -y -loglevel 0 -framerate 24 -i /Users/beau/Desktop/movie-1/image-%3d.png -f mp4 -vcodec libx264 -pix_fmt yuv420p /Users/beau/Desktop/movie-1/test.mp4"
)
コード例 #2
0
coneCol = (0, 0, 255)
coneRef = (0.0, 0.0, 0.0)
coneHeight = 20.0
coneRadius = 10.0

#Cylinder attributes
cylinderT = matrix(np.identity(4))
cylinderT.set(0, 3, 40.0)
cylinderT.set(1, 3, 0.0)
cylinderCol = (255, 0, 255)
cylinderRef = (0.0, 0.0, 0.0)
cylinderHeight = 20.0
cylinderRadius = 10.0

window = graphicsWindow(WIDTH, HEIGHT)  #Open a graphics window
camera = cameraMatrix(P, E, G, NP, FP, WIDTH, HEIGHT,
                      THETA)  #Set camera viewing system

plane = parametricPlane(planeT, planeWidth, planeLength, planeCol, planeRef,
                        (0.0, 1.0), (0.0, 1.0), (1.0 / 10.0, 1.0 / 10.0))
circle = parametricCircle(circleT, circleRadius, circleCol, circleRef,
                          (0.0, 1.0), (0.0, 2.0 * pi), (1.0 / 10.0, pi / 18.0))
sphere = parametricSphere(sphereT, sphereRadius, sphereCol, sphereRef,
                          (0.0, 2.0 * pi), (0.0, pi), (pi / 18.0, pi / 18.0))
cone = parametricCone(coneT, coneHeight, coneRadius, coneCol, coneRef,
                      (0.0, 1.0), (0.0, 2.0 * pi), (1.0 / 10.0, pi / 18.0))
cylinder = parametricCylinder(cylinderT, cylinderHeight, cylinderRadius,
                              cylinderCol, cylinderRef, (0.0, 1.0),
                              (0.0, 2.0 * pi), (1.0 / 10.0, pi / 18.0))
torus = parametricTorus(torusT, torusInnerRadius, torusOuterRadius, torusCol,
                        torusRef, (0.0, 2.0 * pi), (0.0, 2.0 * pi),
                        (pi / 18.0, pi / 9.0))
コード例 #3
0
P.set(0, 0, Px)
P.set(1, 0, Py)
P.set(2, 0, Pz)

#Set up the viewing point vector
E.set(0, 0, Ex)
E.set(1, 0, Ey)
E.set(2, 0, Ez)

#Set up the gaze direction
G.set(0, 0, Gx)
G.set(1, 0, Gy)
G.set(2, 0, Gz)

#Set the camera
camera = cameraMatrix(P, E, G, NP, FP, WIDTH, HEIGHT, THETA)

#Set a world point (0,0,0,1)
worldPoint = matrix(np.zeros((4, 1)))
worldPoint.set(0, 0, 0.0)
worldPoint.set(1, 0, 0.0)
worldPoint.set(2, 0, 0.0)
worldPoint.set(3, 0, 1.0)

#Obtain coordinates of world point in viewing coordinates
viewPoint = camera.worldToViewingCoordinates(worldPoint)
print(viewPoint)

#Obtain coordinates of viewing point in image coordinates
imagePoint = camera.viewingToImageCoordinates(viewPoint)
print(imagePoint)
コード例 #4
0
WIDTH = 512
HEIGHT = 512
THETA = 45.0

P = vector(0.0,0.0,1.0) #Up vector
E = point(5.0,5.0,5.0) #Camera position
G = point(0.0,0.0,0.0) #Gaze point

L = point(5.0,0.0,3.0) #Set light position
C = (1.0,1.0,1.0) #Light color
I = (1.0,1.0,1.0) #Light intensity

light = lightSource(L,C,I)
window = graphicsWindow(WIDTH,HEIGHT)
camera = cameraMatrix(window,P,E,G,NP,FP,THETA)

#Creating a scene with three spheres
objectList = []
objectList.append(implicitSphere(color=(255,0,255),T=transform().translate(),reflectance=(0.2,0.4,0.4,10.0)))
objectList.append(implicitSphere(color=(0,255,0),T=transform().translate(Tx=-2.0,Tz=0.0),reflectance=(0.2,0.4,0.4,10.0)))
objectList.append(implicitSphere(color=(255,255,0),T=transform().translate(Tx=2.0,Tz=-0.0),reflectance=(0.2,0.4,0.4,10.0)))

for i in range(window.getWidth()):
    for j in range(window.getHeight()):
        direction = camera.getRay(window,i,j) #Compute ray direction
        iList = camera.minimumIntersection(direction,objectList) #Find minimum intersection time for ray
        #iList contains tuples (k,t0) where k is position of the object in the list
        #and t0 is the minimum intersection time, sorted in increasing values of t0
        if len(iList) > 0: #If we have an intersection, then set pixel (i,j) to color obtained with shader
            window.drawPoint((i,j),shader(iList[0],direction,camera,objectList,light).getShade())