Example #1
0
    def orbit(self, ref, axis, amt):
        """
        Orbit the camera around an axis passing through a reerence point ref -
        this one orbits relative to the camera axes
        Currently, this function has the undesirable side-effect of possibly
        breaking the "camera.yz is parallel to the world Y=0 plane" constraint,
        and should not be used unless you know what you're doing.
        """
        # Counter-rotate the camera.
        self.rotate(axis=axis, amt=amt)

        # Find the vector from the reference point to the camera
        vec = diff3D(ref, self.pos)
        # Rotate this vector around the axis
        if axis == X_AXIS:
            vec = rotate3D(vec, self.yz, amt)
        elif axis == Y_AXIS:
            vec = rotate3D(vec, self.up, amt)
        elif axis == Z_AXIS:
            vec = rotate3D(vec, self.vpn, -1 * amt)

        # Cacheable: Handled by setattr hook

        # Convert the vector into worldspace coordinates
        self.pos = add3D(ref, vec)
Example #2
0
    def rotate(self, axis, amt):
        """camera.rotate(axis, amt) -> void
           Rotates the camera relative to itself."""
        axisTuple = {X_AXIS: self.yz,
                     Y_AXIS: self.up,
                     Z_AXIS: self.vpn}[axis]

        amt *= self.rotateSpeed

        # Cacheable: Handled by setattr hook

        self.up = rotate3D(self.up, axisTuple, amt)
        self.vpn = rotate3D(self.vpn, axisTuple, amt)
Example #3
0
    def setLeafAngles(self,distribution="random"):
        """
        Adjusts zenith and vertex normal of all leaf plates to correspond to a known leaf angle distribution.
        Currently only uniform random distribution (spherical) is implemented.
        """
        
        # Translate so rotation axis runs through origin
        # Origin is leaf base
        leafVertices = self.getLeafVertices()
        if leafVertices is not None:
            x,y,z,nx,ny,nz = leafVertices
            xv = x[:,0] - x[:,1]
            x0 = repeat([x[:,0] + xv/2.0],4,axis=0).transpose()
            xt = x - x0
            yv = y[:,0] - y[:,1]
            y0 = repeat([y[:,0] + yv/2.0],4,axis=0).transpose()
            yt = y - y0
            zv = z[:,0] - z[:,1]
            z0 = repeat([z[:,0] + zv/2.0],4,axis=0).transpose()
            zt = z - z0

            # Reformat axis vectors about which to perform rotation
            # For leaves these are the equivalent of the plate base (side leaf base is on)
            xv = repeat([xv],4,axis=0).transpose()
            yv = repeat([yv],4,axis=0).transpose()
            zv = repeat([zv],4,axis=0).transpose()

            # Adjust zenith
            zenith = repeat([self.getLeafAngles()],4,axis=0).transpose()
            if (distribution == "random"):
                dims = zenith.shape
                newLeafAngle = repeat([random.uniform(low=0.0001, high=90.0-0.0001, size=dims[0])],4,axis=0).transpose()
                adjustment = newLeafAngle - zenith 
            else:
                print "%s not yet implemented" % distribution
                sys.exit()
            xr,yr,zr = utilities.rotate3D(xv, yv, zv, xt, yt, zt, adjustment)

            # Recalculate normals
            nx,ny,nz = utilities.calcFaceNormal(xr+x0,yr+y0,zr+z0)

            # Send the results
            self.putLeafVertices(xr+x0,yr+y0,zr+z0,nx,ny,nz)