コード例 #1
0
ファイル: Camera.cpp プロジェクト: seclorum/ziiWakeBreaker
void Camera::Update()
{
    Vector3 f = m_center - m_eye;
    //normalize it
    //int test = XTOF(f.z);
    int mag = sqrtx( (int32)(MULX(f.x,f.x) + (int32)MULX(f.y,f.y) + (int32)MULX(f.z,f.z)) );

    int n = DIVX(ITOX(1),mag);

    f.x = MULX(f.x,n);
    f.y = MULX(f.y,n);
    f.z = MULX(f.z,n);

    //update direction
    m_dir = f;


    Vector3 s = f ^ m_up,
            u = s ^ f;

    int matrix[16] = { s.x, u.x, -f.x, 0,
                       s.y, u.y, -f.y, 0,
                       s.z, u.z, -f.z, 0,
                       0,  0,   0,  ITOX(1)
                     };


    glMultMatrixx(matrix);

    glTranslatex(-m_eye.x,-m_eye.y,-m_eye.z);

}
コード例 #2
0
ファイル: scenegraph.cpp プロジェクト: nebogeo/jellyfish-old
void scenegraph::render_node_walk(scenenode *node, int depth)
{
#ifdef _EE
    ps2_renderer::get()->push_matrix();
    ps2_renderer::get()->mult_matrix(node->m_tx.arr());
#else
	glPushMatrix();
    glMultMatrixx((GLfixed*)&node->m_tx.m[0][0]);
//    glMultMatrixf(&node->m_tx.m[0][0]);
#endif

#ifndef _EE
//    glDisable(GL_LIGHTING);

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    // global render hints settings
    if (node->m_hints&HINT_UNLIT) glDisable(GL_LIGHTING);
    else glEnable(GL_LIGHTING);

    // not supported on gles
    //glLineWidth(node->m_line_width);
    //glPointSize(node->m_line_width); // ok to share this??
	if (node->m_hints&HINT_NOZWRITE) glDepthMask(false);
    else glDepthMask(true);
	if (node->m_hints&HINT_IGNORE_DEPTH) glDisable(GL_DEPTH_TEST);
    else glEnable(GL_DEPTH_TEST);

    glEnable(GL_NORMALIZE);

#endif
    if (node->m_texture!=0)
    {
        glEnable(GL_TEXTURE_2D);
        m_texture_manager.apply(node->m_texture);
    }
    else glDisable(GL_TEXTURE_2D);

    if (node->m_primitive!=NULL)
    {
        node->m_primitive->render(node->m_hints);
    }

    depth++;
    scenenode *n=static_cast<scenenode*>(node->m_children.m_head);
    while (n!=NULL)
    {
        render_node_walk(n,depth);
        n=static_cast<scenenode*>(n->m_next);
    }

#ifdef _EE
    ps2_renderer::get()->pop_matrix();
#else
	glPopMatrix();
#endif
}
コード例 #3
0
void jellyfish_primitive::render(u32 hints)
{
    execute();

    vec3 t=m_machine->peek(REG_TX_TRANSLATE);
    m_internal_tx.m[3][0]=t.x;
    m_internal_tx.m[3][1]=t.y;
    m_internal_tx.m[3][2]=t.z;

    t=m_machine->peek(REG_TX_ROTATEA);
    m_internal_tx.m[0][0]=t.x;
    m_internal_tx.m[0][1]=t.y;
    m_internal_tx.m[0][2]=t.z;

    t=m_machine->peek(REG_TX_ROTATEB);
    m_internal_tx.m[1][0]=t.x;
    m_internal_tx.m[1][1]=t.y;
    m_internal_tx.m[1][2]=t.z;

    t=m_machine->peek(REG_TX_ROTATEC);
    m_internal_tx.m[2][0]=t.x;
    m_internal_tx.m[2][1]=t.y;
    m_internal_tx.m[2][2]=t.z;

    // wheee!
    glMultMatrixx((GLfixed*)&m_internal_tx.m[0][0]);

    switch (m_machine->peekiy(REG_GRAPHICS))
    {
    case TRIANGLES: m_type=GL_TRIANGLES; break;
    case TRISTRIP: m_type=GL_TRIANGLE_STRIP; break;
    case POINTS: m_type=GL_POINTS; break;
    case LINES: m_type=GL_LINES; break;
    case LINESTRIP: m_type=GL_LINE_STRIP; break;
    default: m_type=GL_TRIANGLES;
    }

    u32 size=m_size;
    m_size=m_machine->peekix(REG_GRAPHICS);
    hints=m_machine->peekiz(REG_GRAPHICS);
    primitive::render(hints);
    m_size=size;
}
コード例 #4
0
ファイル: demo.c プロジェクト: TeamEOS/frameworks_native
/* Following gluLookAt implementation is adapted from the
 * Mesa 3D Graphics library. http://www.mesa3d.org
 */
static void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
	              GLfloat centerx, GLfloat centery, GLfloat centerz,
	              GLfloat upx, GLfloat upy, GLfloat upz)
{
    GLfloat m[16];
    GLfloat x[3], y[3], z[3];
    GLfloat mag;

    /* Make rotation matrix */

    /* Z vector */
    z[0] = eyex - centerx;
    z[1] = eyey - centery;
    z[2] = eyez - centerz;
    mag = (float)sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
    if (mag) {			/* mpichler, 19950515 */
        z[0] /= mag;
        z[1] /= mag;
        z[2] /= mag;
    }

    /* Y vector */
    y[0] = upx;
    y[1] = upy;
    y[2] = upz;

    /* X vector = Y cross Z */
    x[0] = y[1] * z[2] - y[2] * z[1];
    x[1] = -y[0] * z[2] + y[2] * z[0];
    x[2] = y[0] * z[1] - y[1] * z[0];

    /* Recompute Y = Z cross X */
    y[0] = z[1] * x[2] - z[2] * x[1];
    y[1] = -z[0] * x[2] + z[2] * x[0];
    y[2] = z[0] * x[1] - z[1] * x[0];

    /* mpichler, 19950515 */
    /* cross product gives area of parallelogram, which is < 1.0 for
     * non-perpendicular unit-length vectors; so normalize x, y here
     */

    mag = (float)sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
    if (mag) {
        x[0] /= mag;
        x[1] /= mag;
        x[2] /= mag;
    }

    mag = (float)sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
    if (mag) {
        y[0] /= mag;
        y[1] /= mag;
        y[2] /= mag;
    }

#define M(row,col)  m[(col)*4+(row)]
    M(0, 0) = x[0];
    M(0, 1) = x[1];
    M(0, 2) = x[2];
    M(0, 3) = 0.0;
    M(1, 0) = y[0];
    M(1, 1) = y[1];
    M(1, 2) = y[2];
    M(1, 3) = 0.0;
    M(2, 0) = z[0];
    M(2, 1) = z[1];
    M(2, 2) = z[2];
    M(2, 3) = 0.0;
    M(3, 0) = 0.0;
    M(3, 1) = 0.0;
    M(3, 2) = 0.0;
    M(3, 3) = 1.0;
#undef M
    {
        int a;
        GLfixed fixedM[16];
        for (a = 0; a < 16; ++a)
            fixedM[a] = (GLfixed)(m[a] * 65536);
        glMultMatrixx(fixedM);
    }

    /* Translate Eye to Origin */
    glTranslatex((GLfixed)(-eyex * 65536),
                 (GLfixed)(-eyey * 65536),
                 (GLfixed)(-eyez * 65536));
}
コード例 #5
0
void glMultMatrixxLogged(const GLfixed *m) {
	printf("glMultMatrixx(%p)\n", m);
	glMultMatrixx(m);
}
コード例 #6
0
ファイル: demo.c プロジェクト: alannet/example
static void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
	              GLfloat centerx, GLfloat centery, GLfloat centerz,
	              GLfloat upx, GLfloat upy, GLfloat upz)
{
    GLfloat m[16];
    GLfloat x[3], y[3], z[3];
    GLfloat mag;

    z[0] = eyex - centerx;
    z[1] = eyey - centery;
    z[2] = eyez - centerz;
    mag = (float)sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
    if (mag) {		
        z[0] /= mag;
        z[1] /= mag;
        z[2] /= mag;
    }


    y[0] = upx;
    y[1] = upy;
    y[2] = upz;


    x[0] = y[1] * z[2] - y[2] * z[1];
    x[1] = -y[0] * z[2] + y[2] * z[0];
    x[2] = y[0] * z[1] - y[1] * z[0];


    y[0] = z[1] * x[2] - z[2] * x[1];
    y[1] = -z[0] * x[2] + z[2] * x[0];
    y[2] = z[0] * x[1] - z[1] * x[0];



    mag = (float)sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
    if (mag) {
        x[0] /= mag;
        x[1] /= mag;
        x[2] /= mag;
    }

    mag = (float)sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
    if (mag) {
        y[0] /= mag;
        y[1] /= mag;
        y[2] /= mag;
    }

#define M(row,col)  m[col*4+row]
    M(0, 0) = x[0];
    M(0, 1) = x[1];
    M(0, 2) = x[2];
    M(0, 3) = 0.0;
    M(1, 0) = y[0];
    M(1, 1) = y[1];
    M(1, 2) = y[2];
    M(1, 3) = 0.0;
    M(2, 0) = z[0];
    M(2, 1) = z[1];
    M(2, 2) = z[2];
    M(2, 3) = 0.0;
    M(3, 0) = 0.0;
    M(3, 1) = 0.0;
    M(3, 2) = 0.0;
    M(3, 3) = 1.0;
#undef M
    {
        int a;
        GLfixed fixedM[16];
        for (a = 0; a < 16; ++a)
            fixedM[a] = (GLfixed)(m[a] * 65536);
        glMultMatrixx(fixedM);
    }


    glTranslatex((GLfixed)(-eyex * 65536),
                 (GLfixed)(-eyey * 65536),
                 (GLfixed)(-eyez * 65536));
}