class Missile(object):
    def __init__(self, w=1.0, h=1.0):
        self.isActive = False
        self.x = 0.0
        self.y = 0.0
        self.z = 0.0
        self.dx = 0.0
        self.dy = 0.0
        self.dz = 0.0
        self.w = w
        self.h = h
        self.countDown = 0
        self.picture = Plane(w, h)

    #initialise the launch of the missile
    def fire(self, x, y, z, dx, dy, dz, cnt=10):
        self.isActive = True
        self.x = x
        self.y = y
        self.z = z
        self.dx = dx
        self.dy = dy
        self.dz = dz
        self.countDown = cnt
        self.picture.position(x, y, z)
        self.picture.rotateToY(atan(dx / dz))

    #move and draw
    def move(self, tex):
        if self.countDown > 0:
            self.picture.translate(self.dx, self.dy, self.dz)
            self.picture.rotateIncY(32)
            self.picture.draw(tex)
            self.countDown -= 1
Esempio n. 2
0
class Missile(object):
  def __init__(self, w=1.0, h=1.0):
    self.isActive = False
    self.x = 0.0
    self.y = 0.0
    self.z = 0.0
    self.dx = 0.0
    self.dy = 0.0
    self.dz = 0.0
    self.w = w
    self.h = h
    self.countDown = 0
    self.picture = Plane(w, h)

  #initialise the launch of the missile
  def fire(self, x, y, z, dx, dy, dz, cnt=10):
    self.isActive = True
    self.x = x
    self.y = y
    self.z = z
    self.dx = dx
    self.dy = dy
    self.dz = dz
    self.countDown = cnt
    self.picture.position(x, y, z)
    self.picture.rotateToY(atan(dx/dz))

  #move and draw
  def move(self, tex):
    if self.countDown > 0:
      self.picture.translate(self.dx, self.dy, self.dz)
      self.picture.rotateIncY(32)
      self.picture.draw(tex)
      self.countDown -= 1
 def __init__(self, w=1.0, h=1.0):
     self.isActive = False
     self.x = 0.0
     self.y = 0.0
     self.z = 0.0
     self.dx = 0.0
     self.dy = 0.0
     self.dz = 0.0
     self.w = w
     self.h = h
     self.countDown = 0
     self.picture = Plane(w, h)
Esempio n. 4
0
    def north_edge(self,
                   x,
                   y,
                   z,
                   width=10,
                   length=10,
                   height=10,
                   details=None,
                   name="wall",
                   mergeshape=None):
        """
    Creates a cell consisting of optional north, south, east and west walls and an optional ceiling.
    The north and south walls are parallel with the x axis, with north being more positive. The east and
    west walls are parallel with the z axis, with east being more positive.
    The cell is centred at (x,y,z). The cell is "width" along the z axis, (so north and south walls are that far apart,)
    "length" along the x axis, and "height" high. Each wall is a plane, but the ceiling is a cuboid, 1 unit high. There is no floor.

    The resulting object is added to the given mergeshape

    The objects are named with the given name argument as a prefix and a globally incrementing number as the suffix.
    """
        global wallnum
        n = z + width / 2
        s = z - width / 2
        e = x + length / 2
        w = x - length / 2

        model = Plane(w=length,
                      h=self.ceilingthickness,
                      name=name + str(wallnum))
        mergeshape.add(model, x, y + height + self.ceilingthickness / 2, n)

        wallnum += 1
Esempio n. 5
0
 def __init__(self, w=1.0, h=1.0):
   self.isActive = False
   self.x = 0.0
   self.y = 0.0
   self.z = 0.0
   self.dx = 0.0
   self.dy = 0.0
   self.dz = 0.0
   self.w = w
   self.h = h
   self.countDown = 0
   self.picture = Plane(w, h)
Esempio n. 6
0
    def __init__(self, camera, matsh, points, thickness, colour=(255,255,255,255)):
        '''
        Constructor
        '''
        super(Line2d, self).__init__(camera)
        
        index = 0
        for i in xrange(0,len(points)-1):
            x1 = points[i][0]
            y1 = points[i][1]
            x2 = points[i+1][0]
            y2 = points[i+1][1]

            xdelta = (x2-x1)
            ydelta = (y2-y1)

            length = math.sqrt( (xdelta*xdelta) + (ydelta*ydelta) )
            xcenter=(x1+x2)*0.5
            ycenter=(y1+y2)*0.5
            
            if(xdelta != 0):
                angle = math.atan(ydelta / xdelta)
            else:
                angle = math.pi * 0.5
                
            if(ydelta < 0):
                angle += math.pi
                
            line = Plane(camera=camera,  w=length, h=thickness)
            line.set_draw_details(matsh, [], 0, 0)
#            line.set_material(colour)
#            line.rotateToZ(45)

            self.add(line, x=xcenter, y=ycenter, rz=math.degrees(angle))
            
        self.set_draw_details(matsh, [], 0, 0)
        self.set_material(colour)
#        self.rotateToZ(45)
Esempio n. 7
0
  def roof(self, x, y, z, width=10, length=10, height=10, details=None, name="wall", mergeshape=None, makeroof=True, makeceiling=True):
    """
    Creates a cell consisting of optional north, south, east and west walls and an optional ceiling.
    The north and south walls are parallel with the x axis, with north being more positive. The east and
    west walls are parallel with the z axis, with east being more positive.
    The cell is centred at (x,y,z). The cell is "width" along the z axis, (so north and south walls are that far apart,)
    "length" along the x axis, and "height" high. Each wall is a plane, but the ceiling is a cuboid, 1 unit high. There is no floor.

    The objects are named with the given name argument as a prefix and a globally incrementing number as the suffix.

    The resulting objects are added to the given mergeshape
    """
    global wallnum

    roof = SolidObject(name+str(wallnum), Size(length, 1, width), Position(x, y+height+self.ceilingthickness/2, z), 0)
    roofmodel = Plane(w=length, h=width, name=name+str(wallnum))
    mergeshape.add(roofmodel,x,y+height+self.ceilingthickness,z,rx=90.0,ry=0.0,rz=0.0)

    wallnum += 1
Esempio n. 8
0
    def east_wall(self,
                  x,
                  y,
                  z,
                  width=10,
                  length=10,
                  height=10,
                  details=None,
                  name="wall",
                  mergeshape=None):
        """
    Creates a cell consisting of optional north, south, east and west walls and an optional ceiling.
    The north and south walls are parallel with the x axis, with north being more positive. The east and
    west walls are parallel with the z axis, with east being more positive.
    The cell is centred at (x,y,z). The cell is "width" along the z axis, (so north and south walls are that far apart,)
    "length" along the x axis, and "height" high. Each wall is a plane, but the ceiling is a cuboid, 1 unit high. There is no floor.

    The resulting object is added to the given mergeshape

    The objects are named with the given name argument as a prefix and a globally incrementing number as the suffix.
    """
        global wallnum
        n = z + width / 2
        s = z - width / 2
        e = x + length / 2
        w = x - length / 2

        ewall = SolidObject(name + str(wallnum), Size(1, height, width),
                            Position(e, y + height / 2, z), 0)
        self.walls.append(ewall)
        model = Plane(w=ewall.d() * 2,
                      h=ewall.h() * 2,
                      name=name + str(wallnum))
        mergeshape.add(model,
                       ewall.x(),
                       ewall.y(),
                       ewall.z(),
                       rx=0.0,
                       ry=90.0,
                       rz=0.0)

        wallnum += 1
Esempio n. 9
0
File: Water.py Progetto: Arexxk/pi3d
num_n = len(waterbump)
shapeshine = Texture("textures/stars.jpg")

#Create shape
myshape = MergeShape()
num = (2, 2)
asphere = Sphere(sides=32)
for i in range(num[0]):
  for j in range(num[1]):
    myshape.add(asphere, -num[0]*0.9 + 1.8*i, -num[1]*0.9 +1.8*j, 0.0)

myshape.position(0.0, 0.0, 5)
myshape.set_draw_details(shader, [shapeimg, shapebump, shapeshine], 1.0, 0.1)
myshape.set_material((1.0, 0.5, 0.2, 0.5))

mywater = Plane(w=130.0, h=130.0)
mywater.set_draw_details(matsh, [waterbump[0], shapeshine], 12.0, 0.6)
mywater.set_material((0.0, 0.05, 0.1))
mywater.set_fog((0.4, 0.6, 0.8, 0.0),150)
mywater.rotateToX(90.001)
mywater.position(0.0, -2.0, 0.0)

arialFont = Ttffont("fonts/FreeMonoBoldOblique.ttf", "#dd00aa")   #load ttf font and set the font colour to 'raspberry'
mystring = String(font=arialFont, string="Now the Raspberry Pi really does rock")
mystring.translate(0.0, 0.0, 1)
mystring.set_shader(flatsh)

tick = 0
av_fps = 0
i_n=0
spf = 0.1 # seconds per frame, i.e. water image change
Esempio n. 10
0
mapdepth = 1000.0
mapheight = 100.0
mymap = ElevationMap("textures/maze1.jpg",
                     width=mapwidth,
                     depth=mapdepth,
                     height=mapheight,
                     divx=128,
                     divy=128,
                     name="sub")
mymap.set_draw_details(shader, [rockimg1, rockimg2, shineimg], 128.0, 0.05)

# Create fog for more realistic fade in distance. This can be turned on and off between drawing different object (i.e backgound not foggy)
mymap.set_fog((0.1, 0.1, 0.1, 1.0), 200.0)

#Create tree models
treeplane = Plane(w=4.0, h=5.0)

treemodel1 = MergeShape(name="baretree")
treemodel1.add(treeplane.buf[0], 0, 0, 0)
treemodel1.add(treeplane.buf[0], 0, 0, 0, 0, 90, 0)

#Scatter them on map using Merge shape's cluster function
mytrees1 = MergeShape(name="trees1")
mytrees1.cluster(treemodel1.buf[0], mymap, 0.0, 0.0, 900.0, 900.0, 10, "", 8.0,
                 3.0)
mytrees1.buf[0].set_draw_details(shader, [tree2img, rockimg2], 4.0, 0.0)
mytrees1.set_fog((0.1, 0.1, 0.1, 1.0), 200.0)

raspberry = MergeShape(name="rasp")
raspberry.cluster(treemodel1.buf[0], mymap, -250, +250, 470.0, 470.0, 5, "",
                  8.0, 1.0)
Esempio n. 11
0
# environment cube
ectex = Texture("textures/ecubes/skybox_stormydays.jpg")
myecube = EnvironmentCube(camera, light, 900.0, "CROSS")
myecube.set_draw_details(flatsh, [ectex])

#ball
maxdsz = 0.3
radius = 1.0
ball = Sphere(camera, light, radius, 12, 12, 0.0, "sphere", -4, 8, -7)
# Shape.set_draw_details is a wrapper for calling the method on each item in buf
# as is done explicitly here for no reason than to show that it can be done!
ball.buf[0].set_draw_details(shader, [ballimg], 0.0, 0.0)

#monster
monster = Plane(camera, light, 5.0, 5.0, "monster", 0, 0, 0, 0, 0, 0)
monster.buf[0].set_draw_details(flatsh, [monstimg])

# Create elevation map
mapwidth = 50.0
mapdepth = 50.0
maphalf = 22.0
mapheight = 40.0

mymap = ElevationMap("textures/pong.jpg",
                     camera=camera,
                     light=light,
                     width=mapwidth,
                     depth=mapdepth,
                     height=mapheight,
                     divx=32,
Esempio n. 12
0
shapeshine = Texture("textures/stars.jpg")

#Create shape
myshape = MergeShape()
num = (2, 2)
asphere = Sphere(sides=32)
for i in range(num[0]):
    for j in range(num[1]):
        myshape.add(asphere, -num[0] * 0.9 + 1.8 * i, -num[1] * 0.9 + 1.8 * j,
                    0.0)

myshape.position(0.0, 0.0, 5)
myshape.set_draw_details(shader, [shapeimg, shapebump, shapeshine], 1.0, 0.1)
myshape.set_material((1.0, 0.5, 0.2, 0.5))

mywater = Plane(w=130.0, h=130.0)
mywater.set_draw_details(matsh, [waterbump[0], shapeshine], 12.0, 0.6)
mywater.set_material((0.0, 0.05, 0.1))
mywater.set_fog((0.4, 0.6, 0.8, 0.0), 150)
mywater.rotateToX(90.001)
mywater.position(0.0, -2.0, 0.0)

arialFont = Ttffont(
    "fonts/FreeMonoBoldOblique.ttf",
    "#dd00aa")  #load ttf font and set the font colour to 'raspberry'
mystring = String(font=arialFont,
                  string="Now the Raspberry Pi really does rock")
mystring.translate(0.0, 0.0, 1)
mystring.set_shader(flatsh)

tick = 0
Esempio n. 13
0
File: Pong.py Progetto: JamesR1/pi3d
# Load textures
texs = Textures()
# Setting 2nd param to True renders 'True' Blending
# (this can be changed later to 'False' with 'rockimg2.blend = False')
groundimg = texs.loadTexture("textures/stripwood.jpg")
monstimg = texs.loadTexture("textures/pong3.png")
ballimg = texs.loadTexture("textures/cloud6.png", True)
# environment cube
ectex = texs.loadTexture("textures/ecubes/skybox_stormydays.jpg")
myecube = EnvironmentCube(900.0,"CROSS")
#ball
maxdsz = 0.3
radius = 1.0
ball = Sphere(radius,12,12,0.0,"sphere",-4,8,-7)
#monster
monster = Plane(5.0, 5.0, "monster", 0,0,0, 0,0,0)

# Create elevation map
mapwidth=50.0
mapdepth=50.0
maphalf=22.0
mapheight=40.0
#set smooth to give proper normals the bouncing won't work properly without and it doesn't look as good
mymap = ElevationMap("textures/pong.jpg",mapwidth,mapdepth,mapheight,32,32,4,"sub",0,0,0, smooth=True)

# lighting. The default light is a point light but I have made the position method capable of creating
# a directional light and this is what I do inside the loop. If you want a torch you don't need to move it about
light = Light(0, 2, 2, 1, "", 1,2,3, 0.1,0.1,0.2) #yellowish 'torch' or 'sun' with low level blueish ambient
light.position(1,2,3,0) # set to directional light by setting position with 0 fourth parameter
light.on()
Esempio n. 14
0
#Create inbuilt shapes
mysphere = Sphere(1,24,24,0.0,"sphere",-4,2,-7)
mytcone = TCone(0.8,0.6,1,24,"TCone", -2,2,-7)
myhelix = Helix(0.4,0.1,12,24,1.5,3.0,"helix", 0,2,-7)
mytube = Tube(0.4,0.1,1.5,24,"tube",2,2,-7, 30,0,0)
myextrude = Extrude( ((-0.5, 0.5), (0.5,0.7), (0.9,0.2), (0.2,0.05), (1.0,0.0), (0.5,-0.7), (-0.5, -0.5)), 0.5,"Extrude",4,2,-7)

mycone = Cone(1,2,24,"Cone",-4,-1,-7)
mycylinder = Cylinder(.7,1.5,24,"Cyli",-2,-1,-7)
myhemisphere = Sphere(1,24,24,0.5,"hsphere",0,-1,-7)
mytorus = Torus(1,0.3,12,24,"Torus", 2,-1,-7)
#NB Lathe needs to start at the top otherwise normals are calculated in reverse, also inside surfaces need to be defined otherwise normals are wrong
mylathe = Lathe( ((0,1),(0.6,1.2),(0.8,1.4),(1.09,1.7), (1.1,1.7),(0.9, 1.4),(0.7,1.2),(0.08,1),(0.08,0.21),(0.1,0.2),(1,0.05),(1,0),(0,0)), 24,"Cup",4,-1,-7, 0,0,0, 0.8,0.8,0.8)

myPlane = Plane(4,4,"plane",0,0,0)
myPlane.translate(0,0,-10)

arialFont = Font("AR_CENA","#dd00aa")   #load AR_CENA font and set the font colour to 'raspberry'
destineFont = Font("AR_Destine", "#0055ff")


# Fetch key presses
mykeys = Keyboard()

#create a light
mylight = Light(0, 2,2,2, "", 1,0,0, 0.1,0.1,0.1, 0)
mylight.on()

# Display scene
while 1:
Esempio n. 15
0
File: Pong.py Progetto: Arexxk/pi3d
# environment cube
ectex = Texture("textures/ecubes/skybox_stormydays.jpg")
myecube = EnvironmentCube(camera, light, 900.0,"CROSS")
myecube.set_draw_details(flatsh, [ectex])

#ball
maxdsz = 0.3
radius = 1.0
ball = Sphere(camera, light, radius,12,12,0.0,"sphere",-4,8,-7)
# Shape.set_draw_details is a wrapper for calling the method on each item in buf
# as is done explicitly here for no reason than to show that it can be done!
ball.buf[0].set_draw_details(shader,[ballimg], 0.0, 0.0)

#monster
monster = Plane(camera, light, 5.0, 5.0, "monster", 0,0,0, 0,0,0)
monster.buf[0].set_draw_details(flatsh, [monstimg])

# Create elevation map
mapwidth=50.0
mapdepth=50.0
maphalf=22.0
mapheight=40.0

mymap = ElevationMap("textures/pong.jpg", camera=camera, light=light,
                     width=mapwidth, depth=mapdepth, height=mapheight,
                     divx=32, divy=32, ntiles=4, name="sub")
mymap.buf[0].set_draw_details(shader, [groundimg, groundimg, ballimg], 1.0, 0.0)

#avatar camera
avhgt = 2.0
Esempio n. 16
0
# Load textures
texs=Textures()
# Setting 2nd param to True renders 'True' Blending
# (this can be changed later to 'False' with 'cloudimg.blend = False')
cloudimg = texs.loadTexture("textures/earth_clouds.png",True)
earthimg = texs.loadTexture("textures/world_map.jpg")
moonimg = texs.loadTexture("textures/moon.jpg")
starsimg = texs.loadTexture("textures/stars2.jpg")
watimg = texs.loadTexture("textures/water.jpg")

mysphere = Sphere(2,24,24,0.0,"earth",0,0,-5.8)
mysphere2 = Sphere(2.05,24,24,0.0,"clouds",0,0,-5.8)
mymoon = Sphere(0.4,16,16,0.0,"moon",0,0,0)
mymoon2 = Sphere(0.1,16,16,0.0,"moon2",0,0,0)
myplane = Plane(50,50, "stars", 0,0,-10)

# Fetch key presses
mykeys = Keyboard()

rot=0.0
rot1=90.0
rot2=0.0
m1Rad = 4 # radius of moon orbit
m2Rad = 0.55 # radius moon's moon orbit


#create a light
mylight = Light(0,5,5,5,"sun",10,0,6, .1,.1,.2, 0)
mylight.on()