示例#1
0
void PezUpdate(float seconds)
{
    // Create the model-view matrix:
    Point3 eye = P3MakeFromElems(EyeVector[0] * EyeScale, EyeVector[1] * EyeScale, EyeVector[2] * EyeScale);
    Point3 target = P3MakeFromElems(TargetVector[0] * TargetScale, TargetVector[1] * TargetScale, TargetVector[2] * TargetScale);
    Vector3 up = V3MakeFromElems(0, 1, 0);
    Scene.ViewMatrix = M4MakeLookAt(eye, target, up);

    PezConfig cfg = PezGetConfig();
    const float h = 5.0f;
    const float w = h * cfg.Width / cfg.Height;
    const float hither = 5;
    const float yon = 200;
    Scene.Projection = M4MakeFrustum(-w, w, -h, h, hither, yon);
}
示例#2
0
void PezUpdate(unsigned int elapsedMicroseconds)
{
    const float RadiansPerMicrosecond = 0.0000005f;
    static float Theta = 0;
    Theta += elapsedMicroseconds * RadiansPerMicrosecond;
    
    Vector3 offset = V3MakeFromElems(0, 0, 0);
    Matrix4 model = M4MakeRotationZ(Theta);
    model = M4Mul(M4MakeTranslation(offset), model);
    model = M4Mul(model, M4MakeTranslation(V3Neg(offset)));

    Point3 eyePosition = P3MakeFromElems(0, 10, 0);
    Point3 targetPosition = P3MakeFromElems(0, 0, 0);
    Vector3 upVector = V3MakeFromElems(0, 0, 1);
    Matrix4 view = M4MakeLookAt(eyePosition, targetPosition, upVector);
    
    ModelviewMatrix = M4Mul(view, model);
}
示例#3
0
Mesh CreateMesh(const char* ctmFile, float totalScale, float lengthScale)
{
    Mesh mesh = {0};
    
    char qualifiedPath[256] = {0};
    strcpy(qualifiedPath, PezResourcePath());
    strcat(qualifiedPath, "/\0");
    strcat(qualifiedPath, ctmFile);
    
    // Open the CTM file:
    CTMcontext ctmContext = ctmNewContext(CTM_IMPORT);
    ctmLoad(ctmContext, qualifiedPath);
    PezCheckCondition(ctmGetError(ctmContext) == CTM_NONE, "OpenCTM issue with loading %s", qualifiedPath);
    CTMuint vertexCount = ctmGetInteger(ctmContext, CTM_VERTEX_COUNT);
    CTMuint faceCount = ctmGetInteger(ctmContext, CTM_TRIANGLE_COUNT);

    // Create the VBO for positions:
    const CTMfloat* positions = ctmGetFloatArray(ctmContext, CTM_VERTICES);
    if (positions) {
    
        // Find bounding box
        float m = 99999.0f;
        Point3 minCorner = P3MakeFromElems(m, m, m);
        Point3 maxCorner = P3MakeFromElems(-m, -m, -m);
        const CTMfloat* pSrc = positions;
        CTMuint remainingVerts = vertexCount;
        while (remainingVerts--)
        {
            float x = *pSrc++;
            float y = *pSrc++;
            float z = *pSrc++;
            Point3 p = P3MakeFromElems(x, y, z);
            minCorner = P3MinPerElem(p, minCorner);
            maxCorner = P3MaxPerElem(p, maxCorner);
        }
		
        // Scale such that the Z extent is 'scale'
        // The X and Y scales are computed according to the aspect ratio.
        // The model is centered at (+0.5, +0.5, +0.5).
        float xratio = (maxCorner.x - minCorner.x) / (maxCorner.z - minCorner.z);
        float yratio = (maxCorner.y - minCorner.y) / (maxCorner.z - minCorner.z);

        float sx = lengthScale * totalScale * xratio / (maxCorner.x - minCorner.x);
        float sy = totalScale * yratio / (maxCorner.y - minCorner.y);
        float sz = totalScale / (maxCorner.z - minCorner.z);
        pSrc = positions;
        remainingVerts = vertexCount;
        CTMfloat* pDest = (CTMfloat*) positions;
        while (remainingVerts--)
        {
            float x = *pSrc++;
            float y = *pSrc++;
            float z = *pSrc++;
            *pDest++ = (x - minCorner.x) * sx - totalScale * xratio / 2;
            *pDest++ = (y - minCorner.y) * sy - totalScale * yratio / 2;
            *pDest++ = (z - minCorner.z) * sz - totalScale / 2;
        }

        GLuint handle;
        GLsizeiptr size = vertexCount * sizeof(float) * 3;
        glGenBuffers(1, &handle);
        glBindBuffer(GL_ARRAY_BUFFER, handle);
        glBufferData(GL_ARRAY_BUFFER, size, positions, GL_STATIC_DRAW);
        mesh.Positions = handle;
    }
    
    // Create the VBO for normals:
    const CTMfloat* normals = ctmGetFloatArray(ctmContext, CTM_NORMALS);
    if (normals) {
        GLuint handle;
        GLsizeiptr size = vertexCount * sizeof(float) * 3;
        glGenBuffers(1, &handle);
        glBindBuffer(GL_ARRAY_BUFFER, handle);
        glBufferData(GL_ARRAY_BUFFER, size, normals, GL_STATIC_DRAW);
        mesh.Normals = handle;
    }
    
    // Create the VBO for indices:
    const CTMuint* indices = ctmGetIntegerArray(ctmContext, CTM_INDICES);
    if (indices) {
        
        GLsizeiptr bufferSize = faceCount * 3 * sizeof(GLuint);
        
        GLuint handle;
        glGenBuffers(1, &handle);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, handle);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, bufferSize, indices, GL_STATIC_DRAW);
        mesh.Faces = handle;
    }
    
    ctmFreeContext(ctmContext);

    mesh.FaceCount = faceCount;
    mesh.VertexCount = vertexCount;

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    return mesh;
}
示例#4
0
static float TessLevelOuter;
static float NormalModel = 2.0;
static float Tesselation = 0.0;
static float Wireframe = 0.0;
static float Tagg = 0.0;
static float ColNorm = 0.0;
static float DCol = 0.0;

// storage

std::vector<float> Verts;
std::vector<float> Faces;
int nv;

// Camera information
Point3 eyePosition = P3MakeFromElems(0, 0, -10);
Point3 targetPosition = P3MakeFromElems(0, 0, 1.0);
Vector3 upVector = V3MakeFromElems(0, 1, 0);
float camAngleX=0.0f, camAngleY=0.0f;   // camera angles

// Button information
float mouseSensitivy = 0.001f;
bool b_r = false;
int mouseButton = 0;
int mouseX = 0;
int mouseY = 0;

// selection
int selID = 0;