Ejemplo n.º 1
0
    def InitGraphics(self, handle):
        """Creates the Direct3D device which is used to render the scene.  Pops
        up a message box and returns False on failure (returns True on success).
        """
        params = Direct3D.PresentParameters()
        params.Windowed = True
        params.SwapEffect = Direct3D.SwapEffect.Discard
        params.EnableAutoDepthStencil = True
        params.AutoDepthStencilFormat = Direct3D.DepthFormat.D16

        self.Device = Direct3D.Device(
            0, Direct3D.DeviceType.Hardware, handle,
            Direct3D.CreateFlags.SoftwareVertexProcessing, params)

        self.Device.RenderState.ZBufferEnable = True
        self.Device.Transform.Projection = DirectX.Matrix.PerspectiveFovLH(
            System.Math.PI / 4.0, 1, 1, 100)
        self.Device.Transform.View = DirectX.Matrix.LookAtLH(
            DirectX.Vector3(0, 3, -5), DirectX.Vector3(0, 0, 0),
            DirectX.Vector3(0, 1, 0))
        self.Device.RenderState.Ambient = Drawing.Color.White

        # ensure we are not paused
        self.Paused = False

        return True
Ejemplo n.º 2
0
 def LookAt(self, position, up=DirectX.Vector3(0, 1, 0)):
     """Takes in a position to look at and an up vector to use to look at
     it with.  The up vector will normally be the positive Y axis, but in
     the case where the position is directly above or below the position
     of the camera, you will need to set which direction up is in this
     case."""
     zero = DirectX.Vector3(0, 0, 0)
     direction = Vectorize(position) - self.Position
     up = Vectorize(up)
     self.LookAtMatrix = DirectX.Matrix.LookAtLH(zero, direction, up)
     self.RotationMatrix = DirectX.Matrix.Identity
Ejemplo n.º 3
0
def Vectorize(v):
    "Converts v from a sequence into a Vector3."
    if operator.isSequenceType(v):
        v = DirectX.Vector3(System.Single(v[0]), System.Single(v[1]),
                            System.Single(v[2]))

    return v
Ejemplo n.º 4
0
 def __DelPosition(self):
     self.__Position = DirectX.Vector3(0, 0, 0)
     self.PositionMatrix = DirectX.Matrix.Identity
Ejemplo n.º 5
0
 def LookAt(self, pos, up=DirectX.Vector3(0, 1, 0)):
     pos, up = Vectorize(pos), Vectorize(up)
     self.RotationMatrix = DirectX.Matrix.LookAtLH(self.Position, pos, up) * \
                           DirectX.Matrix.Translation(-self.Position)
Ejemplo n.º 6
0
def Vectorize(v):
    if type(v) == list:
        v = DirectX.Vector3(v[0], v[1], v[2])
    return v
Ejemplo n.º 7
0
 def __UpdateMatrix(self):
     self.Matrix = DirectX.Matrix.LookAtLH(self.__Position,
                                           self.__LookAtVector,
                                           DirectX.Vector3(0, 1, 0))
Ejemplo n.º 8
0
 def __init__(self, name):
     self.Name = name
     self.__LookAtVector = DirectX.Vector3(0, 0, -1)
     self.__Position = DirectX.Vector3(0, 0, 0)
Ejemplo n.º 9
0
 def __DelPosition(self):
     self.__Position = DirectX.Vector3(0, 0, 0)
Ejemplo n.º 10
0
 def __init__(self):
     self.__Position = DirectX.Vector3(0, 0, 0)