from direct.showbase.ShowBase import ShowBase
from pandac.PandaModules import *
from math import sin, cos, pi
def move_forwards(rotation, multi):
# Calculate Change
x_movement=-sin(rotation*(pi/180))*multi
z_movement=cos(rotation*(pi/180))*multi
return Vec3(x_movement,0,z_movement)
# World Class
class World():
def __init__(self,showbase,num_sides,radius):
# generate n gon for platform
n_gon=self.create_world(num_sides,radius)
self.world=render.attachNewNode(n_gon)
# this part sets up the texturing
self.proj = render.attachNewNode(LensNode('proj'))
self.lens = OrthographicLens()
self.lens.setFilmSize(250) # not sure exactly what this was :S
self.proj.node().setLens(self.lens)
self.proj.reparentTo(render)
# sets projection to be straight down from above the circle
self.proj.setPos(0,1,0)
self.proj.lookAt(0,0,0)
# your texture
self.tex = loader.loadTexture('ground.png')
self.ts = TextureStage('ts')
self.world.clearTexture()
# apply it!
self.world.projectTexture(self.ts, self.tex, self.proj)
def create_world(self,n,radius):
points={}
# rotation between each warlock for even spacing
rotation=360.0/n
for i in range(n):
# adjust rotation for this point
rot=rotation*(i+1)
# set its position radius units from center
points[i]=move_forwards(rot,radius)
nnode=GeomNode('n_gon')
for i in range(n):
triangle=self.create_triangle(points[i],points[(i+1)%n])
nnode.addGeom(triangle)
return nnode
def create_triangle(self,point1,point2):
format=GeomVertexFormat.getV3n3cpt2()
vdata=GeomVertexData('triangle', format, Geom.UHStatic)
vertex=GeomVertexWriter(vdata, 'vertex')
normal=GeomVertexWriter(vdata, 'normal')
color=GeomVertexWriter(vdata, 'color')
texcoord=GeomVertexWriter(vdata, 'texcoord')
# first point
vertex.addData3f(point1.getX(), 0, point1.getZ())
normal.addData3f(0, -1, 0)
color.addData4f(1, 1, 1, 1)
texcoord.addData2f(1, 0)
# second point
vertex.addData3f(point2.getX(), 0, point2.getZ())
normal.addData3f(0, -1, 0)
color.addData4f(1, 1, 1, 1)
texcoord.addData2f(1, 1)
# center point (0,0,0)
vertex.addData3f(0, 0, 0)
normal.addData3f(0, 0, 1)
color.addData4f(1, 1, 1, 1)
texcoord.addData2f(0, 1)
tri1=GeomTriangles(Geom.UHStatic)
tri1.addVertex(0)
tri1.addVertex(1)
tri1.addVertex(2)
tri1.closePrimitive()
triangle=Geom(vdata)
triangle.addPrimitive(tri1)
return triangle
class Main(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.world=World(self,160,25)
game = Main()
game.run()