Exemplo n.º 1
0
    /// <summary>
    /// Defines the view matrix with an eye position, a look at point and an up vector.
    /// This method is equivalent to the OpenGL function gluLookAt.
    /// If Up is a zero vector a default up vector is calculated with a default
    /// look-right vector (VZ) that lies in the x-z plane.
    /// </summary>
    /// <param name="Eye">Eye Vector to the position of the eye (view point)</param>
    /// <param name="At">At Vector to the target point</param>
    /// <param name="Up">Up Vector that points from the viewpoint upwards.</param>
    public void LookAt(SLVec3f Eye, SLVec3f At, SLVec3f Up)
    {
        SLVec3f VX, VY, VZ, VT, ZERO;

        //SLMat3<T> xz(0.0, 0.0, 1.0,         // matrix that transforms YZ into a
        //             0.0, 0.0, 0.0,         // vector that is perpendicular to YZ and
        //            -1.0, 0.0, 0.0);        // lies in the x-z plane

        VZ = Eye - At;
        VZ.Normalize();
        VX   = new SLVec3f();
        ZERO = new SLVec3f();

        if (Up == ZERO)
        {
            VX.x = VZ.z;
            VX.y = 0;
            VX.z = -1 * VZ.x;
        }
        else
        {
            VX = Up.Cross(VZ);
        }
        VY = SLVec3f.CrossProduct(VZ, VX);
        VX.Normalize();
        VY.Normalize();
        VZ.Normalize();
        VT = -Eye;

        Set(VX.x, VX.y, VX.z, SLVec3f.DotProduct(VX, VT),
            VY.x, VY.y, VY.z, SLVec3f.DotProduct(VY, VT),
            VZ.x, VZ.y, VZ.z, SLVec3f.DotProduct(VZ, VT),
            0.0f, 0.0f, 0.0f, 1.0f);
    }
Exemplo n.º 2
0
    /// <summary>
    /// if vertecies are in inverse order or not
    /// </summary>
    /// <param name="v0">vertex 1</param>
    /// <param name="v1">vertex 2</param>
    /// <param name="v2">vertex 3</param>
    /// <param name="cam">relative to the camera position</param>
    /// <returns></returns>
    private bool  backfaceCulling(SLVertex v0, SLVertex v1, SLVertex v2, SLVec3f cam)
    {
        SLVec3f face = SLVec3f.CrossProduct((v1.position - v0.position), (v2.position - v0.position));

        return(SLVec3f.DotProduct(face, cam) >= 0 || xWireframeActive);
    }