Exemplo n.º 1
0
void qrot(Space *t, Quaternion q){
	Matrix m, inv;
	int i, j;
	qtom(m, q);
	for(i=0;i!=4;i++) for(j=0;j!=4;j++) inv[i][j]=m[j][i];
	ixform(t, m, inv);
}
void ixformPoint(vec3f &v, vec3f &r, float *m)
{
    vec3f x;
    x.x = v.x - m[12];
    x.y = v.y - m[13];
    x.z = v.z - m[14];
    ixform(x, r, m);
}
Exemplo n.º 3
0
//*****************************************************************************
void ixformPoint(float *v, float *r, GLfloat *m)
{
    float x[4];
    x[0] = v[0] - m[12];
    x[1] = v[1] - m[13];
    x[2] = v[2] - m[14];
    x[3] = 1.0f;
    ixform(x, r, m);
}
Exemplo n.º 4
0
void move(Space *t, double x, double y, double z){
	Matrix m, inv;
	ident(m);
	m[0][3]=x;
	m[1][3]=y;
	m[2][3]=z;
	ident(inv);
	inv[0][3]=-x;
	inv[1][3]=-y;
	inv[2][3]=-z;
	ixform(t, m, inv);
}
Exemplo n.º 5
0
void scale(Space *t, double x, double y, double z){
	Matrix m, inv;
	ident(m);
	m[0][0]=x;
	m[1][1]=y;
	m[2][2]=z;
	ident(inv);
	inv[0][0]=1/x;
	inv[1][1]=1/y;
	inv[2][2]=1/z;
	ixform(t, m, inv);
}
Exemplo n.º 6
0
void rot(Space *t, double theta, int axis){
	double s=sin(radians(theta)), c=cos(radians(theta));
	Matrix m, inv;
	int i=(axis+1)%3, j=(axis+2)%3;
	ident(m);
	m[i][i] = c;
	m[i][j] = -s;
	m[j][i] = s;
	m[j][j] = c;
	ident(inv);
	inv[i][i] = c;
	inv[i][j] = s;
	inv[j][i] = -s;
	inv[j][j] = c;
	ixform(t, m, inv);
}
Exemplo n.º 7
0
/*
 * multiply the top of the matrix stack by a view-pointing transformation
 * with the eyepoint at e, looking at point l, with u at the top of the screen.
 * The coordinate system is deemed to be right-handed.
 * The generated transformation transforms this view into a view from
 * the origin, looking in the positive y direction, with the z axis pointing up,
 * and x to the right.
 */
void look(Space *t, Point3 e, Point3 l, Point3 u){
	Matrix m, inv;
	Point3 r;
	l=unit3(sub3(l, e));
	u=unit3(vrem3(sub3(u, e), l));
	r=cross3(l, u);
	/* make the matrix to transform from (rlu) space to (xyz) space */
	ident(m);
	m[0][0]=r.x; m[0][1]=r.y; m[0][2]=r.z;
	m[1][0]=l.x; m[1][1]=l.y; m[1][2]=l.z;
	m[2][0]=u.x; m[2][1]=u.y; m[2][2]=u.z;
	ident(inv);
	inv[0][0]=r.x; inv[0][1]=l.x; inv[0][2]=u.x;
	inv[1][0]=r.y; inv[1][1]=l.y; inv[1][2]=u.y;
	inv[2][0]=r.z; inv[2][1]=l.z; inv[2][2]=u.z;
	ixform(t, m, inv);
	move(t, -e.x, -e.y, -e.z);
}
Exemplo n.º 8
0
// Helper function to loop through different modes
//*****************************************************************************
void ResetSim(int iOption)
{
    if((iOption < 1) || (iOption > 4))return;
    switch (iOption)
    {
        case 1:
            psystem->reset(ParticleSystem::CONFIG_GRID);
            break;
        case 2:
            psystem->reset(ParticleSystem::CONFIG_RANDOM);
            break;
        case 3:
            addSphere();
            break;
        case 4:
            {
                // shoot ball from camera
                float pr = psystem->getParticleRadius();
                float vel[4], velw[4], pos[4], posw[4];
                vel[0] = 0.0f;
                vel[1] = 0.0f;
                vel[2] = fShootVelocity;
                vel[3] = 0.0f;
                ixform(vel, velw, modelView);

                pos[0] = 0.0f;
                pos[1] = 0.0f;
                pos[2] = -2.5f;
                pos[3] = 1.0;
                ixformPoint(pos, posw, modelView);
                posw[3] = 0.0f;

                psystem->addSphere(0, posw, velw, ballr, pr * 2.0f);
            }
            break;
    }
}
Exemplo n.º 9
0
// GLUT mouse motion callback
//*****************************************************************************
void MotionGL(int x, int y)
{
    float dx, dy;
    dx = (float)(x - ox);
    dy = (float)(y - oy);

    if (displaySliders) 
    {
        if (params->Motion(x, y)) 
        {
            ox = x; 
            oy = y;
            return;
        }
    }

    switch(mode) 
    {
    case M_VIEW:
        if (buttonState == 3) 
        {
            // left+middle = zoom
            camera_trans[2] += (dy / 100.0f) * 0.5f * fabs(camera_trans[2]);
        } 
        else if (buttonState & 2) 
        {
            // middle = translate
            camera_trans[0] += dx / 100.0f;
            camera_trans[1] -= dy / 100.0f;
        }
        else if (buttonState & 1) 
        {
            // left = rotate
            camera_rot[0] += dy / 5.0f;
            camera_rot[1] += dx / 5.0f;
        }
        break;

    case M_MOVE:
        {
            float translateSpeed = 0.003f;
            float3 p = psystem->getColliderPos();
            if (buttonState == 1) 
            {
                float v[3], r[3];
                v[0] = dx * translateSpeed;
                v[1] = -dy * translateSpeed;
                v[2] = 0.0f;
                ixform(v, r, modelView);
                p.x += r[0];
                p.y += r[1];
                p.z += r[2];
            } 
            else if (buttonState == 2) 
            {
                float v[3], r[3];
                v[0] = 0.0f;
                v[1] = 0.0f;
                v[2] = dy * translateSpeed;
                ixform(v, r, modelView);
                p.x += r[0];
                p.y += r[1];
                p.z += r[2];
            }
            psystem->setColliderPos(p);
        }
        break;
    }

    ox = x; 
    oy = y;

    // update view transform based upon mouse inputs
    ResetViewTransform();
}
Exemplo n.º 10
0
// commented out to remove unused parameter warnings in Linux
void key(unsigned char key, int /*x*/, int /*y*/)
{
#ifndef BT_NO_PROFILE
	if (key >= 0x31 && key < 0x37)
	{
		int child = key-0x31;
		renderer->m_profileIterator->Enter_Child(child);
	}
	if (key==0x30)
	{
		renderer->m_profileIterator->Enter_Parent();
	}
#endif //BT_NO_PROFILE

    switch (key) 
    {
    case ' ':
        bPause = !bPause;
        break;
    case 13:
        psystem->update(timestep); 
        renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles());
        break;
    case '\033':
    case 'q':
        exit(0);
        break;
    case 'v':
        mode = M_VIEW;
        break;
    case 'm':
        mode = M_MOVE;
        break;
    case 'p':
        displayMode = (ParticleRenderer::DisplayMode)
                      ((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES);
        break;
    case 'd':
        psystem->dumpGrid();
        break;
    case 'u':
        psystem->dumpParticles(0, 1);
        break;

    case 'r':
        displayEnabled = !displayEnabled;
        break;

    case 'g':
        psystem->reset(ParticleSystem::CONFIG_GRID);
        break;
    case 'a':
        psystem->reset(ParticleSystem::CONFIG_RANDOM);
        break;
    case 'e':
        {
            // inject a sphere of particles
            float pr = psystem->getParticleRadius();
            float tr = pr+(pr*2.0f)*ballr;
            float pos[4], vel[4];
            pos[0] = -1.0 + tr + frand()*(2.0f - tr*2.0f);
            pos[1] = 1.0f - tr;
            pos[2] = -1.0 + tr + frand()*(2.0f - tr*2.0f);
            pos[3] = 0.0f;
            vel[0] = vel[1] = vel[2] = vel[3] = 0.0f;
            psystem->addSphere(0, pos, vel, ballr, pr*2.0f);
        }
        break;
    case 'b':
        {
            // shoot ball from camera
            float pr = psystem->getParticleRadius();
            float vel[4], velw[4], pos[4], posw[4];
            vel[0] = 0.0f;
            vel[1] = 0.0f;
            vel[2] = -0.05f;
            vel[3] = 0.0f;
            ixform(vel, velw, modelView);

            pos[0] = 0.0f;
            pos[1] = 0.0f;
            pos[2] = -2.5f;
            pos[3] = 1.0;
            ixformPoint(pos, posw, modelView);
            posw[3] = 0.0f;

            psystem->addSphere(0, posw, velw, ballr, pr*2.0f);
        }
        break;

    case 'w':
        wireframe = !wireframe;
        break;

    case 'h':
        displaySliders = !displaySliders;
        break;
	case 's':
		psystem->setSimulationMode((ParticleSystem::SimulationMode) ((psystem->getSimulationMode() + 1) % ParticleSystem::SIMULATION_NUM_MODES));
		CProfileManager::CleanupMemory();
        break;
    }

    glutPostRedisplay();
}
Exemplo n.º 11
0
void motion(int x, int y)
{
    float dx, dy;
    dx = x - ox;
    dy = y - oy;

    if (displaySliders) {
        if (params->Motion(x, y)) {
            ox = x; oy = y;
            glutPostRedisplay();
            return;
        }
    }

    switch(mode) 
    {
    case M_VIEW:
        if (buttonState == 3) {
            // left+middle = zoom
            camera_trans[2] += (dy / 100.0) * 0.5 * fabs(camera_trans[2]);
        } 
        else if (buttonState & 2) {
            // middle = translate
            camera_trans[0] += dx / 100.0;
            camera_trans[1] -= dy / 100.0;
        }
        else if (buttonState & 1) {
            // left = rotate
            camera_rot[0] += dy / 5.0;
            camera_rot[1] += dx / 5.0;
        }
        break;

    case M_MOVE:
        {
            float translateSpeed = 0.003f;
            float4 p = psystem->getColliderPos();
            if (buttonState==1) {
                float v[3], r[3];
                v[0] = dx*translateSpeed;
                v[1] = -dy*translateSpeed;
                v[2] = 0.0f;
                ixform(v, r, modelView);
                p.x += r[0];
                p.y += r[1];
                p.z += r[2];
            } else if (buttonState==2) {
                float v[3], r[3];
                v[0] = 0.0f;
                v[1] = 0.0f;
                v[2] = dy*translateSpeed;
                ixform(v, r, modelView);
                p.x += r[0];
                p.y += r[1];
                p.z += r[2];
            }
            psystem->setColliderPos(p);
        }
        break;
    }

    ox = x; oy = y;
    glutPostRedisplay();
}
void motion(int x, int y)
{
    float dx, dy;
    dx = x - ox;
    dy = y - oy;

    if (displaySliders) {
        if (params->Motion(x, y)) {
            ox = x; oy = y;
            glutPostRedisplay();
            return;
        }
    }

    switch(mode) 
    {
    case M_VIEW:
        {
            if (buttonState == 1) {
                // left = rotate
                cameraRot[0] += dy * rotateSpeed;
                cameraRot[1] += dx * rotateSpeed;
            }
            if (buttonState == 2) {
                // middle = translate
                vec3f v = vec3f(dx*translateSpeed, -dy*translateSpeed, 0.0f);
                vec3f r;
                ixform(v, r, modelView);
                cameraPos += r;
            }
            if (buttonState == 3) {
                // left+middle = zoom
                vec3f v = vec3f(0.0, 0.0, dy*translateSpeed);
                vec3f r;
                ixform(v, r, modelView);
                cameraPos += r;
            } 
        }
        break;

    case M_MOVE_CURSOR:
        {
            if (buttonState==1) {
                vec3f v = vec3f(dx*cursorSpeed, -dy*cursorSpeed, 0.0f);
                vec3f r;
                ixform(v, r, modelView);
                //cursorPos += r;
            } else if (buttonState==2) {
                vec3f v = vec3f(0.0f, 0.0f, dy*cursorSpeed);
                vec3f r;
                ixform(v, r, modelView);
                //cursorPos += r;
            }
        }
        break;

	case M_MOVE_LIGHT:
        if (buttonState==1) {
            vec3f v = vec3f(dx*cursorSpeed, -dy*cursorSpeed, 0.0f);
            vec3f r;
            ixform(v, r, modelView);
            lightPos += r;
        } else if (buttonState==2) {
            vec3f v = vec3f(0.0f, 0.0f, dy*cursorSpeed);
            vec3f r;
            ixform(v, r, modelView);
            lightPos += r;
        }
		break;

    }

    ox = x; oy = y;
    glutPostRedisplay();
}
Exemplo n.º 13
0
void xform(Space *t, Matrix m){
	Matrix inv;
	if(invertmat(m, inv)==0) return;
	ixform(t, m, inv);
}
Exemplo n.º 14
0
// commented out to remove unused parameter warnings in Linux
void key(unsigned char key, int /*x*/, int /*y*/)
{
    switch (key) 
    {
    case ' ':
        bPause = !bPause;
        break;
    case 13:
        psystem->update(timestep); 
        renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles());
        break;
    case '\033':
    case 'q':
        exit(0);
        break;
    case 'v':
        mode = M_VIEW;
        break;
    case 'm':
        mode = M_MOVE;
        break;
    case 'p':
        displayMode = (ParticleRenderer::DisplayMode)
                      ((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES);
        break;
    case 'd':
        psystem->dumpGrid();
        break;
    case 'u':
        psystem->dumpParticles(0, 1);
        break;

    case 'r':
        displayEnabled = !displayEnabled;
        break;

    case '1':
        psystem->reset(ParticleSystem::CONFIG_GRID);
        break;
    case '2':
        psystem->reset(ParticleSystem::CONFIG_RANDOM);
        break;
    case '3':
        {
            // inject a sphere of particles
            float pr = psystem->getParticleRadius();
            float tr = pr+(pr*2.0f)*ballr;
            float pos[4], vel[4];
            pos[0] = -1.0 + tr + frand()*(2.0f - tr*2.0f);
            pos[1] = 1.0f - tr;
            pos[2] = -1.0 + tr + frand()*(2.0f - tr*2.0f);
            pos[3] = 0.0f;
            vel[0] = vel[1] = vel[2] = vel[3] = 0.0f;
            psystem->addSphere(0, pos, vel, ballr, pr*2.0f);
        }
        break;
    case '4':
        {
            // shoot ball from camera
            float pr = psystem->getParticleRadius();
            float vel[4], velw[4], pos[4], posw[4];
            vel[0] = 0.0f;
            vel[1] = 0.0f;
            vel[2] = -0.05f;
            vel[3] = 0.0f;
            ixform(vel, velw, modelView);

            pos[0] = 0.0f;
            pos[1] = 0.0f;
            pos[2] = -2.5f;
            pos[3] = 1.0;
            ixformPoint(pos, posw, modelView);
            posw[3] = 0.0f;

            psystem->addSphere(0, posw, velw, ballr, pr*2.0f);
        }
        break;

    case 'w':
        wireframe = !wireframe;
        break;

    case 'h':
        displaySliders = !displaySliders;
        break;
    }

    glutPostRedisplay();
}
Exemplo n.º 15
0
// commented out to remove unused parameter warnings in Linux
void key(unsigned char key, int /*x*/, int /*y*/)
{
    switch (key)
    {
        case ' ':
            bPause = !bPause;
            break;

        case 13:
            psystem->update(timestep);

            if (renderer)
            {
                renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles());
            }

            break;

        case '\033':
        case 'q':
            #if defined(__APPLE__) || defined(MACOSX)
                exit(EXIT_SUCCESS);
            #else
                glutDestroyWindow(glutGetWindow());
                return;
            #endif
        case 'v':
            mode = M_VIEW;
            break;

        case 'm':
            mode = M_MOVE;
            break;

        case 'p':
            displayMode = (ParticleRenderer::DisplayMode)
                          ((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES);
            break;

        case 'd':
            psystem->dumpGrid();
            break;

        case 'u':
            psystem->dumpParticles(0, numParticles-1);
            break;

        case 'r':
            displayEnabled = !displayEnabled;
            break;

        case '1':
            psystem->reset(ParticleSystem::CONFIG_GRID);
            break;

        case '2':
            psystem->reset(ParticleSystem::CONFIG_RANDOM);
            break;

        case '3':
            addSphere();
            break;

        case '4':
            {
                // shoot ball from camera
                float pr = psystem->getParticleRadius();
                float vel[4], velw[4], pos[4], posw[4];
                vel[0] = 0.0f;
                vel[1] = 0.0f;
                vel[2] = -0.05f;
                vel[3] = 0.0f;
                ixform(vel, velw, modelView);

                pos[0] = 0.0f;
                pos[1] = 0.0f;
                pos[2] = -2.5f;
                pos[3] = 1.0;
                ixformPoint(pos, posw, modelView);
                posw[3] = 0.0f;

                psystem->addSphere(0, posw, velw, ballr, pr*2.0f);
            }
            break;

        case 'w':
            wireframe = !wireframe;
            break;

        case 'h':
            displaySliders = !displaySliders;
            break;
    }

    demoMode = false;
    idleCounter = 0;
    glutPostRedisplay();
}
Exemplo n.º 16
0
// commented out to remove unused parameter warnings in Linux
void key(unsigned char key, int /*x*/, int /*y*/)
{
    switch (key)
    {
        case ' ':
            bPause = !bPause;
            break;

        case 13:
            psystem->update(timestep);

            if (renderer)
            {
                renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles());
            }

            break;

        case '\033':
        case 'q':
            // cudaDeviceReset causes the driver to clean up all state. While
            // not mandatory in normal operation, it is good practice.  It is also
            // needed to ensure correct operation when the application is being
            // profiled. Calling cudaDeviceReset causes all profile data to be
            // flushed before the application exits
            cudaDeviceReset();
            exit(EXIT_SUCCESS);
            break;

        case 'v':
            mode = M_VIEW;
            break;

        case 'm':
            mode = M_MOVE;
            break;

        case 'p':
            displayMode = (ParticleRenderer::DisplayMode)
                          ((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES);
            break;

        case 'd':
            psystem->dumpGrid();
            break;

        case 'u':
            psystem->dumpParticles(0, numParticles-1);
            break;

        case 'r':
            displayEnabled = !displayEnabled;
            break;

        case '1':
            psystem->reset(ParticleSystem::CONFIG_GRID);
            break;

        case '2':
            psystem->reset(ParticleSystem::CONFIG_RANDOM);
            break;

        case '3':
            addSphere();
            break;

        case '4':
            {
                // shoot ball from camera
                float pr = psystem->getParticleRadius();
                float vel[4], velw[4], pos[4], posw[4];
                vel[0] = 0.0f;
                vel[1] = 0.0f;
                vel[2] = -0.05f;
                vel[3] = 0.0f;
                ixform(vel, velw, modelView);

                pos[0] = 0.0f;
                pos[1] = 0.0f;
                pos[2] = -2.5f;
                pos[3] = 1.0;
                ixformPoint(pos, posw, modelView);
                posw[3] = 0.0f;

                psystem->addSphere(0, posw, velw, ballr, pr*2.0f);
            }
            break;

        case 'w':
            wireframe = !wireframe;
            break;

        case 'h':
            displaySliders = !displaySliders;
            break;
    }

    demoMode = false;
    idleCounter = 0;
    glutPostRedisplay();
}