# Z-axis codes!

By: H3LLB0Y on Apr 30th, 2012  |  syntax: Python  |  size: 2.64 KB  |  hits: 19  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. from direct.showbase.ShowBase import ShowBase
2. from pandac.PandaModules import *
3. from math import sin, cos, pi
4.
5. def move_forwards(rotation, multi):
6.         # Calculate Change
7.         x_movement=-sin(rotation*(pi/180))*multi
8.         z_movement=cos(rotation*(pi/180))*multi
9.
10.         return Vec3(x_movement,0,z_movement)
11.
12. # World Class
13. class World():
15.                 # generate n gon for platform
17.                 self.world=render.attachNewNode(n_gon)
18.
19.                 # this part sets up the texturing
20.                 self.proj = render.attachNewNode(LensNode('proj'))
21.                 self.lens = OrthographicLens()
22.                 self.lens.setFilmSize(250) # not sure exactly what this was :S
23.                 self.proj.node().setLens(self.lens)
24.                 self.proj.reparentTo(render)
25.                 # sets projection to be straight down from above the circle
26.                 self.proj.setPos(0,1,0)
27.                 self.proj.lookAt(0,0,0)
28.
31.                 self.ts = TextureStage('ts')
32.                 self.world.clearTexture()
33.                 # apply it!
34.                 self.world.projectTexture(self.ts, self.tex, self.proj)
35.
37.                 points={}
38.
39.                 # rotation between each warlock for even spacing
40.                 rotation=360.0/n
41.
42.                 for i in range(n):
43.                         # adjust rotation for this point
44.                         rot=rotation*(i+1)
45.
46.                         # set its position radius units from center
48.
49.                 nnode=GeomNode('n_gon')
50.                 for i in range(n):
51.                         triangle=self.create_triangle(points[i],points[(i+1)%n])
53.
54.                 return nnode
55.
56.         def create_triangle(self,point1,point2):
57.                 format=GeomVertexFormat.getV3n3cpt2()
58.                 vdata=GeomVertexData('triangle', format, Geom.UHStatic)
59.
60.                 vertex=GeomVertexWriter(vdata, 'vertex')
61.                 normal=GeomVertexWriter(vdata, 'normal')
62.                 color=GeomVertexWriter(vdata, 'color')
63.                 texcoord=GeomVertexWriter(vdata, 'texcoord')
64.
65.                 # first point
70.
71.                 # second point
76.
77.                 # center point (0,0,0)
82.
83.                 tri1=GeomTriangles(Geom.UHStatic)
84.
88.
89.                 tri1.closePrimitive()
90.
91.                 triangle=Geom(vdata)