Beispiel #1
0
	def transform(self):
			if self.angl == 1:
				view = viz.MainView
				mat = viz.Matrix()
				mat.postAxisAngle(0,1,0,self.theta)
				mat.postTrans(self.x,self.y+1.45,self.z+0.15)
				view.setMatrix(mat)
			intersect = viz.intersect([self.x, 4000, self.z], [self.x, 0, self.z])
			self.y = intersect.point[1]
			mat = viz.Matrix()
			mat.postAxisAngle(0,1,0,self.theta)
			mat.postScale(2,2,2)
			mat.postTrans(self.x, self.y, self.z)
			self.avatar.setMatrix(mat)
Beispiel #2
0
    def setTransformations(self):
        m = viz.Matrix()
        m.postTrans(self.baseX, self.baseY)
        self.base.setMatrix(m)

        m = viz.Matrix()
        m.postAxisAngle(0, 0, 1, self.ua)
        m.postTrans(0, 10)
        self.upperArm.setMatrix(m)

        m = viz.Matrix()
        m.postAxisAngle(0, 0, 1, self.la)
        m.postTrans(40, 0)
        self.lowerArm.setMatrix(m)
Beispiel #3
0
    def setTransformations(self):
        m = viz.Matrix()
        m.postTrans(100, 0)
        m.postAxisAngle(0, 0, 1, (self.day / 224.0) * 360)
        self.mercury.setMatrix(m)

        m = viz.Matrix()
        m.postTrans(400, 0)
        m.postAxisAngle(0, 0, 1, (self.day / 365.0) * 360)
        self.earth.setMatrix(m)

        m = viz.Matrix()
        m.postTrans(45, 0)
        m.postAxisAngle(0, 0, 1, (self.day / 30.0) * 360)
        self.moon.setMatrix(m)
Beispiel #4
0
	def setTransformations(self):
		
		baseM = viz.Matrix()
		baseM.postTrans(self.baseX, self.baseY)
		self.base.setMatrix(baseM)
		
		upperArmM = viz.Matrix()
		upperArmM.postAxisAngle(0, 0, 1, self.ua)
		upperArmM.postTrans(25, 5)
		self.upperArm.setMatrix(upperArmM)
		
		lowerArmM = viz.Matrix()
		lowerArmM.postAxisAngle(0, 0, 1, self.la)
		lowerArmM.postTrans(40, 2.5)
		self.lowerArm.setMatrix(lowerArmM)
Beispiel #5
0
    def getLastGazeMatrix(self, eye=viz.BOTH_EYE):
        """Returns the last received gaze matrix in HMD coordinate system"""
        m = viz.Matrix()
        s = self.getLastSample()
        if s:
            if eye == viz.LEFT_EYE:
                s = s.leftEye
            elif eye == viz.RIGHT_EYE:
                s = s.rightEye

            xoff = SCREEN_DISTANCE * math.tan(math.radians(
                FIELD_OF_VIEW / 2.0))
            yoff = SCREEN_DISTANCE * math.tan(math.radians(
                FIELD_OF_VIEW / 2.0))
            zoff = SCREEN_DISTANCE

            gx = ((s.por_x * 2.0 * xoff) / SCREEN_HRES - xoff)
            gy = -((s.por_y * 2.0 * yoff) / SCREEN_VRES - yoff)
            gz = zoff

            m.makeVecRotVec([0, 0, 1], viz.Vector(gx, gy, gz, normalize=True))

            #print 'Time: ' + str(s.timestamp)
            #print 'Time: ' + str(viz.getFrameElapsed())
        return m
    def onKeyDown(self, key):

        if key == viz.KEY_LEFT:
            #spin
            self.rotate -= 2
        elif key == viz.KEY_RIGHT:
            self.rotate += 2
        elif key == viz.KEY_UP:  #move forward
            self.xVal += 2 * (math.sin(math.radians(self.rotate)))
            self.zVal += 2 * (math.cos(math.radians(self.rotate)))
        elif key == viz.KEY_DOWN:  #move backward
            temp = 0
            if (self.rotate <= 180):
                temp = self.rotate + 180
            else:
                temp = self.rotate - 180

            self.xVal += 2 * (math.sin(math.radians(temp)))
            self.zVal += 2 * (math.cos(math.radians(temp)))
        elif key == "a":

            self.starttimer(1, .05, viz.PERPETUAL)

        self.height = self.findHeight(
            self.terrainData, self.zVal,
            self.xVal)  #weirdly have to switch x and z for it to work
        #sets the changed view
        view = viz.MainView
        m = viz.Matrix()
        m.postAxisAngle(0, 1, 0, self.rotate)
        m.postTrans(self.xVal, self.height + 5, self.zVal)
        view.setMatrix(m)
Beispiel #7
0
    def monsterMove(self):
        self.shortest = 9999
        self.decidedX = -1
        self.decidedZ = -1
        if (self.monX == self.x and self.monZ == self.z):
            self.EndGame = True
            t = viz.addText("Total Points: " + str(self.points),
                            viz.SCREEN,
                            pos=[0, 0, 0])
            p = viz.addText(str(self.points), viz.SCREEN, pos=[5, 0, 0])

        if (self.EndGame == False):

            if (self.x > self.monX
                    and self.maze[int(self.monX + 1)][int(self.monZ)] != 4):
                self.monX = self.monX + 1
            elif (self.x < self.monX
                  and self.maze[int(self.monX - 1)][int(self.monZ)] != 4):
                self.monX = self.monX - 1
            elif (self.z > self.monZ
                  and self.maze[int(self.monX)][int(self.monZ + 1)] != 4):
                self.monX = self.monX + 1
            elif (self.z < self.monZ
                  and self.maze[int(self.monX)][int(self.monZ - 1)] != 4):
                self.monZ = self.monZ - 1
            elif (self.monX == self.x and self.monZ == self.z):
                self.EndGame = True

            m = viz.Matrix()
            m.postTrans(int(self.monX), self.monY, int(self.monZ))

            self.monster.setMatrix(m)
Beispiel #8
0
	def rotateRight(self):
		self.angle -= 5
		self.changeInAngle -= 5
		m = viz.Matrix()
		m.postAxisAngle(0, 0, 1, self.changeInAngle)
		m.postTrans(self.x, self.y)
		self.vertices.setMatrix(m)
Beispiel #9
0
	def __init__(self):
		# base class constructor 
		viz.EventClass.__init__(self)
		self.model = viz.addChild('piazza.osgb')

		# set up keyboard and timer callback methods
		self.callback(viz.KEYDOWN_EVENT,self.onKeyDown)
		self.callback(viz.MOUSEDOWN_EVENT,self.onMouseDown)
		#booleans for video
		self.check1 = False
		#avatar's postion and rotation angle
		self.x = 0.5
		self.z = 0.5
		#counts for animaions
		self.count = 0.0
		self.count2 = 0.0
		self.theta = 0
		#inserting avater
		
		self.avatar = vizfx.addAvatar('mazinger/mazinger.cfg')
		self.avatar.state(0)
		#translating avatar to correct position
		mat = viz.Matrix()
		#mat.postAxisAngle(0,1,0,self.theta)
		mat.postTrans(0,7,0);
		self.avatar.setMatrix(mat)
		self.callback(viz.TIMER_EVENT,self.onTimer)
	
		#mazin.addAction(spin)
		#Music
		
		#add ground
		grass = viz.addTexture('images/tile_grass.jpg', wrap=viz.REPEAT)
Beispiel #10
0
 def onKeyDown(self, key):
     if (key == viz.KEY_LEFT):
         self.theta = self.theta - 5
     if (key == viz.KEY_RIGHT):
         self.theta = self.theta + 5
     if (key == viz.KEY_UP):
         ang = math.radians(self.theta)
         self.x = self.x + (math.sin(ang) / 3)
         self.z = self.z + (math.cos(ang) / 3)
     if (key == viz.KEY_DOWN):
         ang = math.radians(self.theta)
         self.x = (self.x - math.sin(ang) / 3)
         self.z = (self.z - math.cos(ang) / 3)
     if key == 'u':
         self.y += 5
     if key == 'd':
         self.y -= 5
         #self.y = self.elevation[self.x][self.z] + 1
     if (key == "1"):
         self.angl = 1
         view = viz.MainView
         mat = viz.Matrix()
         mat.postAxisAngle(0, 1, 0, self.theta)
         mat.postTrans(self.x, self.y + 1.45, self.z + 0.15)
         view.setMatrix(mat)
     self.transform()
Beispiel #11
0
 def setzScale(self, z):
     mat = viz.Matrix()
     mat.postScale(0.07, 0.08, 0.1)
     #mat.postScale(self.s,self.s,self.s)
     mat.postAxisAngle(0, 1, 0, 90)
     mat.postTrans(10.5, 0.2, 8.9)
     self.node.setMatrix(mat)
Beispiel #12
0
 def firstPerson(self):
     self.fp = True
     view = viz.MainView
     mat = viz.Matrix()
     mat.postAxisAngle(0, 1, 0, self.theta)
     mat.postTrans(self.x, 1.6, self.z)
     view.setMatrix(mat)
Beispiel #13
0
    def onKeyDown(self, key):

        m = viz.Matrix()

        #if the right key is pressed turn right
        if (key == viz.KEY_RIGHT):
            self.theta += 5
            m.postAxisAngle(0, 1, 0, self.theta)
            m.postTrans(self.x, 0.1, self.z)
            self.car.setMatrix(m)

        #if the left key if pressed turn left
        if (key == viz.KEY_LEFT):
            self.theta -= 5
            m.postAxisAngle(0, 1, 0, self.theta)
            m.postTrans(self.x, 0.1, self.z)
            self.car.setMatrix(m)

        #if the down key is pressed go "forwards" which is backwards for this model
        if (key == viz.KEY_DOWN):
            self.forwards = 1
#			x = math.sin(math.radians(self.theta))*.5
#			z = math.cos(math.radians(self.theta))*.5
#			self.x = self.x + x
#			self.z = self.z + z
#			m.postAxisAngle(0, 1, 0, self.theta)
#			m.postTrans(self.x, .1, self.z)
#			self.car.setMatrix(m)

#if the up key if pressed go "backwards" which is really forwards for this model
        if (key == viz.KEY_UP):
            self.forwards = -1
Beispiel #14
0
 def setTransMatrix(self):
     mat = viz.Matrix()
     mat.postScale(self.s, self.s, self.s)
     mat.postAxisAngle(1, 0, 0, self.xrot)
     mat.postAxisAngle(0, 1, 0, self.yrot)
     mat.postTrans(self.x, self.y, self.z)
     self.node.setMatrix(mat)
Beispiel #15
0
	def __init__(self, row, col):
		# Length of each block
		self.length = 20
		
		# Instance variables
		self.x = (row * self.length) - 100
		self.y = 100 - (col * self.length)
		self.row = col
		self.col = row
		
		viz.startLayer(viz.POLYGON)
		
		# Assign vertices a random color
		viz.vertexColor(random.uniform(.2, 1),random.uniform(.2, 1), random.uniform(.2, 1))
		
		# Define vertices
		viz.vertex(0, 0)
		viz.vertex(self.length, 0)
		viz.vertex(self.length, -self.length)
		viz.vertex(0, -self.length)
		
		# Capture layer and set its transformation matrix
		self.vertices = viz.endLayer()
		m = viz.Matrix()
		m.postTrans(self.x, self.y)
		self.vertices.setMatrix(m)
Beispiel #16
0
	def setXY(self,x,y):
		self.x = x
		self.y = y
		
		m = viz.Matrix()
		m.postTrans(self.x, self.y)
		self.vertices.setMatrix(m)
Beispiel #17
0
    def linkPose(self, node3d):

        newTransMat = viz.Matrix()
        newTransMat.setQuat(self.getQuaternion())
        newTransMat.setPosition(self.body.getPosition())

        linkAction = vizact.onupdate(viz.PRIORITY_LINKS, node3d.setMatrix,
                                     newTransMat)
        return linkAction
Beispiel #18
0
	def setTransformations(self):
		sunM = viz.Matrix()
		sunM.postTrans(self.sunX, self.sunY)
		self.sun.setMatrix(sunM)
		
		earthM = viz.Matrix()
		earthM.postTrans(0, 400, 0)
		earthM.postAxisAngle(0, 0, 1, 1.0138*self.day)
		self.earth.setMatrix(earthM)
		
		mercuryM = viz.Matrix()
		mercuryM.postTrans(0, 100, 0)
		mercuryM.postAxisAngle(0, 0, 1, 1.607*self.day)
		self.mercury.setMatrix(mercuryM)
		
		moonM = viz.Matrix()
		moonM.postTrans(0, 45, 0)
		moonM.postAxisAngle(0, 0, 1, 12*self.day)
		self.moon.setMatrix(moonM)
    def setView(self):
        m = viz.Matrix()
        m.postAxisAngle(1, 0, 0, 10)
        m.postTrans(self.x, self.y + 3, self.z - 15)

        view = viz.MainView
        view.setMatrix(m)


#	def onMouse(self):
#		return
    def moveShip(self):
        view = viz.MainView
        mat = viz.Matrix()
        if self.model.id == self.tie.id:
            mat.postAxisAngle(0, 1, 0, 180)
        mat.postTrans(self.x, self.y, self.z)
        self.model.setMatrix(mat)

        self.setView()

        print("Centered at {}".format(self.model.getCenter()))
Beispiel #21
0
	def onKeyDown(self, key):
		if key == viz.KEY_UP:
			self.playerZ += 5
		elif key == viz.KEY_DOWN:
			self.playerZ -= 5
		
		if key == viz.KEY_LEFT:
			self.playerX -= 5
		elif key == viz.KEY_RIGHT:
			self.playerX += 5
			
		m = viz.Matrix()
		m.postTrans(self.playerX, self.playerY, self.playerZ)
		self.player.setMatrix(m)
		
		view = viz.MainView
		viewMat = viz.Matrix()
		viewMat.postAxisAngle(1, 0, 0, 90)
		viewMat.postTrans(self.playerX, self.playerY + 500, self.playerZ)
		
		view.setMatrix(viewMat)
Beispiel #22
0
    def transform(self):
        baseM = viz.Matrix()
        baseM.postTrans(self.x, self.y)
        self.group.setMatrix(baseM)

        mat = viz.Matrix()
        mat.postAxisAngle(0, 0, 1, self.a)
        mat.postAxisAngle(0, 1, 0, self.b)
        mat.postTrans(0, 4.5)
        self.lowerArmGroup.setMatrix(mat)

        mat = viz.Matrix()
        mat.postAxisAngle(0, 0, 1, self.c)
        mat.postAxisAngle(0, 1, 0, self.d)
        mat.postTrans(0, 20)
        self.upperArmGroup.setMatrix(mat)

        mat = viz.Matrix()
        mat.postTrans(0, 20)
        mat.postAxisAngle(0, 0, 1, self.e)
        self.shadeGroup.setMatrix(mat)
Beispiel #23
0
    def onKeyDown(self, key):
        if key == 'a' or key == viz.KEY_LEFT:
            mat = viz.Matrix()
            self.theta -= 5
            mat.postAxisAngle(0, 1, 0, self.theta)
            mat.postTrans(self.x, .1, self.z)
            self.avatar.setMatrix(mat)
            if self.fp:
                self.firstPerson()

        if key == 'd' or key == viz.KEY_RIGHT:
            mat = viz.Matrix()
            self.theta += 5
            mat.postAxisAngle(0, 1, 0, self.theta)
            mat.postTrans(self.x, .1, self.z)
            self.avatar.setMatrix(mat)
            if self.fp:
                self.firstPerson()

        if key == 'w' or key == viz.KEY_UP:
            mat = viz.Matrix()
            rad = viz.radians(self.theta)
            self.z += .1 * math.cos(rad)
            self.x += .1 * math.sin(rad)
            mat.postAxisAngle(0, 1, 0, self.theta)
            mat.postTrans(self.x, .1, self.z)
            self.avatar.setMatrix(mat)
            if self.fp:
                self.firstPerson()

        if key == 's' or key == viz.KEY_DOWN:
            mat = viz.Matrix()
            rad = viz.radians(self.theta)
            self.z -= .1 * math.cos(rad)
            self.x -= .1 * math.sin(rad)
            mat.postAxisAngle(0, 1, 0, self.theta)
            mat.postTrans(self.x, .1, self.z)
            self.avatar.setMatrix(mat)
            if self.fp:
                self.firstPerson()

        if key == '1':
            self.fp = False
            view = viz.MainView
            mat = viz.Matrix()
            mat.postAxisAngle(1, 0, 0, 90)
            mat.postTrans(0, 20, 0)
            view.setMatrix(mat)

        if key == '2':
            self.fp = False
            view = viz.MainView
            mat = viz.Matrix()
            mat.postAxisAngle(0, 1, 0, -90)
            mat.postAxisAngle(0, 0, 1, 45)
            mat.postTrans(20, 20, 0)
            view.setMatrix(mat)

        if key == '3':
            self.firstPerson()
Beispiel #24
0
    def onKeyDown(self, key):
        if key == viz.KEY_UP:
            self.sunY += 5
        elif key == viz.KEY_DOWN:
            self.sunY -= 5
        elif key == viz.KEY_RIGHT:
            self.sunX += 5
        elif key == viz.KEY_LEFT:
            self.sunX -= 5

        m = viz.Matrix()
        m.postTrans(self.sunX, self.sunY)
        self.sun.setMatrix(m)
Beispiel #25
0
	def onTimer(self, num):
		if num == 1:
			self.spinAngle += 5
			
			theta = self.planeAngle - self.planeAngle if self.planeAngle > 0 else self.planeAngle + self.planeAngle
			
			m = viz.Matrix()
			m.postAxisAngle(0, 1, 0, theta)
			m.postTrans(0, self.planeY - self.planeY if self.planeY > 0 else self.planeY + self.planeY,
			self.planeZ - self.planeZ if self.planeZ > 0 else self.planeZ + self.planeZ)
			m.postAxisAngle(0, 0, 1, self.spinAngle)
			m.postTrans(0,self.planeY, self.planeZ) 
			self.plane.setMatrix(m)
Beispiel #26
0
    def transform(self):
        #transform broom
        m = viz.Matrix()
        #m.postScale(.005, .005, .005)
        m.postAxisAngle(1, 0, 0, 90)  #extra for cylinder
        m.postAxisAngle(1, 0, 0, self.alpha)
        m.postAxisAngle(0, 1, 0, self.theta)
        m.postTrans(self.x, self.y, self.z)
        #self.broom.getNode().setMatrix(m)
        self.broom.setMatrix(m)

        #transform view
        dx = 0.5 * (math.sin(math.radians(self.theta)))
        dz = 0.5 * (math.cos(math.radians(self.theta)))
        dy = 0.5 * (math.sin(math.radians(-self.alpha)))
        view = viz.MainView
        mat = viz.Matrix()
        mat.postTrans(0, 0.75, 0)
        mat.postAxisAngle(1, 0, 0, self.alpha)
        mat.postAxisAngle(0, 1, 0, self.theta)
        mat.postTrans(self.x - dx, self.y - dy, self.z - dz)
        view.setMatrix(mat)
Beispiel #27
0
	def transform(self):
		m = viz.Matrix()
		m.postTrans(self.x, self.y)
		self.baseGroup.setMatrix(m)
		
		#lower arm
		m = viz.Matrix()
		m.postAxisAngle(0,0,1, self.a)
		m.postAxisAngle(0,1,0, self.b)
		m.postTrans(0, 5, 0)
		self.lowerArmGroup.setMatrix(m)
		
		#upper arm
		m = viz.Matrix()
		m.postAxisAngle(0,0,1, self.c)
		m.postTrans(0, 40, 0)
		self.upperArmGroup.setMatrix(m)
		
		m = viz.Matrix()
		m.postAxisAngle(0,0,1, self.d)
		m.postAxisAngle(0,1,0, self.e)
		m.postTrans(0, 40, 0)
		self.shadeGroup.setMatrix(m)
Beispiel #28
0
    def onCollideBegin(self, e):
        self.catches += 1
        viz.playSound('ball_sound.wav')

        #Displays on the screen the score that the player scores by catching the snitch
        m = viz.Matrix()
        m.postTrans(-100, -100, 0)
        self.text.setMatrix(m)
        self.text = viz.addText('Score: ' + str(self.catches),
                                viz.SCREEN,
                                pos=[0.01, 0.92, 0])
        self.text.setBackdrop(viz.BACKDROP_RIGHT_BOTTOM)
        self.text.color(0.95, 0.95, 0.95)
        self.text.disable(viz.LIGHTING)
Beispiel #29
0
    def setCameraTransforms(self):
        self.camAngle = self.camera.getAxisAngle()
        self.camera.setAxisAngle(self.camAngle)
        self.camera.setPosition(self.camX, self.camY, self.camZ)

        mat = viz.Matrix()
        mat.postAxisAngle(self.camAngle)
        self.camVector = mat.preMultVec(0, 0, 1)

        mat = viz.Matrix()
        mat.postAxisAngle(0, 1, 0, -105)
        mat.postAxisAngle(self.camAngle)
        mat.postTrans(self.camX + self.camVector[0],
                      self.camY + self.camVector[1],
                      self.camZ + self.camVector[2])
        self.gun.setMatrix(mat)

        mat = viz.Matrix()
        mat.postScale(0.1, 0.1, 0.1)
        mat.postAxisAngle(self.camAngle)
        mat.postTrans(self.camX + self.camVector[0] * 2,
                      self.camY + self.camVector[1] * 2,
                      self.camZ + self.camVector[2] * 2)
        self.reload.setMatrix(mat)
Beispiel #30
0
    def __init__(self):
        viz.EventClass.__init__(self)

        self.callback(viz.KEYDOWN_EVENT, self.onKeyDown)

        # generate random terrain using diamond-square algorithm
        self.terrainData = diamondSquare(7)

        # add some craters to the terrain
        self.makeCrater(self.terrainData,
                        len(self.terrainData) / 4,
                        len(self.terrainData) / 4, 10)
        self.makeCrater(self.terrainData, 6 * len(self.terrainData) / 8,
                        len(self.terrainData) / 2, 22)

        # create a triangular mesh (a Vizard layer of triangles) out of the data
        terrainLayer = self.generateLayer(self.terrainData)
        terrainLayer.enable(viz.LIGHTING)
        # viewer is located at (self.x,self.y,self.z)
        self.x = 0
        self.y = self.terrainData[0][0] + 1
        self.z = 0
        # viewer is rotated by self.rotate, an angle measured off the +x axis,
        # so initially the viewer is looking down the +z axis
        self.rotate = 90
        # initialize this starting view
        self.setView()

        viz.MainView.getHeadLight().disable()

        self.myLight = viz.addLight()
        self.myLight.enable()
        self.myLight.color(1, 1, 1)
        m = viz.Matrix()
        m.postAxisAngle(1, 0, 0, 45)
        self.myLight.setMatrix(m)
        #print self.normal([1,1830,1],[2,1820,2], [2,1835,1])

        for row in self.terrainData:
            for col in row:
                print(col),
            print()