Example #1
0
void Camera::setUniforms(const Program & program) const
{
    if (m_activeRenderTechnique == m_pathTracer)
    {
        const Program * p(m_pathTracer->program());
        if (p == nullptr)
            return;
        p->setUniform(VIEWPORT_UNIFORM, m_viewport);
        p->setUniform(VIEW_UNIFORM, m_view);
        p->setUniform(PROJECTION_UNIFORM, m_projection);
        p->setUniform(TRANSFORM_UNIFORM, m_transform);
        p->setUniform(TRANSFORMINVERSE_UNIFORM, m_transformInverse);
        p->setUniform(CAMERAPOSITION_UNIFORM, getEye());
        p->setUniform(ZNEAR_UNIFORM, m_zNear);
        p->setUniform(ZFAR_UNIFORM, m_zFar);
    }
    else
    {
        program.setUniform(VIEWPORT_UNIFORM, m_viewport);
        program.setUniform(VIEW_UNIFORM, m_view);
        program.setUniform(PROJECTION_UNIFORM, m_projection);
        program.setUniform(TRANSFORM_UNIFORM, m_transform);
        program.setUniform(TRANSFORMINVERSE_UNIFORM, m_transformInverse);
        program.setUniform(CAMERAPOSITION_UNIFORM, getEye());
        program.setUniform(ZNEAR_UNIFORM, m_zNear);
        program.setUniform(ZFAR_UNIFORM, m_zFar);
    }
}
Example #2
0
void Channel::frameViewFinish( const eq::uint128_t& frameID )
{
    if( stopRendering( ))
        return;

    applyBuffer();

    const FrameData& frameData = _getFrameData();
    Accum& accum = _accum[ lunchbox::getIndexOfLastBit( getEye()) ];

    if( accum.buffer )
    {
        const eq::PixelViewport& pvp = getPixelViewport();
        const bool isResized = accum.buffer->resize( pvp );

        if( isResized )
        {
            const View* view = static_cast< const View* >( getView( ));
            accum.buffer->clear();
            accum.step = view->getIdleSteps();
            accum.stepsDone = 0;
        }
        else if( frameData.isIdle( ))
        {
            setupAssemblyState();

            if( !_isDone() && accum.transfer )
                accum.buffer->accum();
            accum.buffer->display();

            resetAssemblyState();
        }
    }

    applyViewport();
    _drawOverlay();
    _drawHelp();

    if( frameData.useStatistics())
        drawStatistics();

    int32_t steps = 0;
    if( frameData.isIdle( ))
    {
        for( size_t i = 0; i < eq::NUM_EYES; ++i )
            steps = LB_MAX( steps, _accum[i].step );
    }
    else
    {
        const View* view = static_cast< const View* >( getView( ));
        steps = view ? view->getIdleSteps() : 0;
    }

    // if _jitterStep == 0 and no user redraw event happened, the app will exit
    // FSAA idle mode and block on the next redraw event.
    eq::Config* config = getConfig();
    config->sendEvent( IDLE_AA_LEFT ) << steps;

    eq::Channel::frameViewFinish( frameID );
}
Example #3
0
// Calculates local north vector for this Camera
Vector3D Camera::getUp(){
	
	// If there are no over-own-center rotations
	if(xoangle == 0.0 && yoangle == 0.0)
		return getSingleUp();
	
	// Get new space coordinates refference
	Vector3D eye = getEye();
			// Not using getFocus ... we need original focus, not rotated one
	Vector3D dirAxis = eye.sub(focus).normalize(); // z' (eye - focus, not focus - eye)
	                                               // couse the z+ direction
	Vector3D up = getSingleUp(); // y'
	Vector3D right = dirAxis.crossProduct(up).normalize(); // x'
	
	// Rotate standar position focus
	Vector3D pivotalAxis(0.0, 1.0, 0.0);
	pivotalAxis = pivotalAxis.rotate(xoangle, 1, 0, 0);
	pivotalAxis = pivotalAxis.rotate(yoangle, 0, 1, 0);
	
	// Translate new standar position focus to the new space coordinates refference
	Vector3D nuPivotalAxis = right.byScalarProduct(pivotalAxis.getCoord(0));
	nuPivotalAxis = nuPivotalAxis.add(up.byScalarProduct(pivotalAxis.getCoord(1)));
	nuPivotalAxis = nuPivotalAxis.add(dirAxis.byScalarProduct(pivotalAxis.getCoord(2)));
	return nuPivotalAxis;
	
}
Example #4
0
void Channel::frameClear( const eq::uint128_t& /*frameID*/ )
{
    if( stopRendering( ))
        return;

    _initJitter();
    resetRegions();

    const FrameData& frameData = _getFrameData();
    const int32_t eyeIndex = lunchbox::getIndexOfLastBit( getEye() );
    if( _isDone() && !_accum[ eyeIndex ].transfer )
        return;

    applyBuffer();
    applyViewport();

    const eq::View* view = getView();
    if( view && frameData.getCurrentViewID() == view->getID( ))
        glClearColor( 1.f, 1.f, 1.f, 0.f );
#ifndef NDEBUG
    else if( getenv( "EQ_TAINT_CHANNELS" ))
    {
        const eq::Vector3ub color = getUniqueColor();
        glClearColor( color.r()/255.f, color.g()/255.f, color.b()/255.f, 0.f );
    }
#endif // NDEBUG
    else
        glClearColor( 0.f, 0.f, 0.f, 0.0f );

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}
Example #5
0
glm::vec3 Camera::getCenter() const
{
    glm::vec3 lookat = glm::row(m_view, 2).xyz();
    glm::vec3 eye = getEye();

    return eye - lookat;

}
Example #6
0
void Z3DCameraParameter::flipViewDirection()
{
  glm::vec3 referenceCenter = getCenter();
  glm::vec3 eyePosition = getEye();

  glm::vec3 viewVector = eyePosition - referenceCenter;
  setEye(referenceCenter - viewVector);
}
Example #7
0
void Channel::frameAssemble( const eq::uint128_t& frameID )
{
    if( stopRendering( ))
        return;

    if( _isDone( ))
        return;

    Accum& accum = _accum[ lunchbox::getIndexOfLastBit( getEye()) ];

    if( getPixelViewport() != _currentPVP )
    {
        accum.transfer = true;

        if( accum.buffer && !accum.buffer->usesFBO( ))
        {
            LBWARN << "Current viewport different from view viewport, "
                   << "idle anti-aliasing not implemented." << std::endl;
            accum.step = 0;
        }

        eq::Channel::frameAssemble( frameID );
        return;
    }
    // else
    
    accum.transfer = true;
    const eq::Frames& frames = getInputFrames();

    for( eq::Frames::const_iterator i = frames.begin(); i != frames.end(); ++i )
    {
        eq::Frame* frame = *i;
        const eq::SubPixel& curSubPixel = frame->getSubPixel();

        if( curSubPixel != eq::SubPixel::ALL )
            accum.transfer = false;

        accum.stepsDone = LB_MAX( accum.stepsDone, 
                                  frame->getSubPixel().size*frame->getPeriod( ));
    }

    applyBuffer();
    applyViewport();
    setupAssemblyState();

    try
    {
        eq::Compositor::assembleFrames( getInputFrames(), this, accum.buffer );
    }
    catch( const co::Exception& e )
    {
        LBWARN << e.what() << std::endl;
    }

    resetAssemblyState();
}
Example #8
0
bool Channel::_isDone() const
{
    const FrameData& frameData = _getFrameData();
    if( !frameData.isIdle( ))
        return false;

    const eq::SubPixel& subpixel = getSubPixel();
    const Accum& accum = _accum[ lunchbox::getIndexOfLastBit( getEye()) ];
    return int32_t( subpixel.index ) >= accum.step;
}
Example #9
0
void Channel::frameAssemble( const eq::uint128_t& frameID,
                             const eq::Frames& frames )
{
    if( stopRendering( ))
        return;

    if( _isDone( ))
        return;

    Accum& accum = _accum[ lunchbox::getIndexOfLastBit( getEye()) ];

    if( getPixelViewport() != _currentPVP )
    {
        accum.transfer = true;

        if( accum.buffer && !accum.buffer->usesFBO( ))
        {
            LBWARN << "Current viewport different from view viewport, "
                   << "idle anti-aliasing not implemented." << std::endl;
            accum.step = 0;
        }

        eq::Channel::frameAssemble( frameID, frames );
        return;
    }
    // else

    accum.transfer = true;
    for( eq::Frame* frame : frames )
    {
        const eq::SubPixel& subPixel =
            frame->getFrameData()->getContext().subPixel;

        if( subPixel != eq::SubPixel::ALL )
            accum.transfer = false;

        accum.stepsDone = LB_MAX( accum.stepsDone, subPixel.size *
                                  frame->getFrameData()->getContext().period );
    }

    applyBuffer();
    applyViewport();
    setupAssemblyState();

    try
    {
        eq::Compositor::assembleFrames( frames, this, accum.buffer.get( ));
    }
    catch( const co::Exception& e )
    {
        LBWARN << e.what() << std::endl;
    }

    resetAssemblyState();
}
Example #10
0
void Camera::rotateAroundAtPoint(int axis, double angle, double focusDist) {
	Matrix4 matRot;
    if ( axis == 0 ) matRot = Matrix4::xrotation(angle);
    if ( axis == 1 ) matRot = Matrix4::yrotation(angle);
    if ( axis == 2 ) matRot = Matrix4::zrotation(angle);

    const Point3 ptFocus = getEye() + getLook() * focusDist;
	
    const Matrix4 matRotCameraInv = getRotationFromXYZ();
    const Matrix4 matAll = matRotCameraInv * matRot * matRotCameraInv.transpose();

    const double dScl = focusDist * tan( getZoom() / 2.0 );
    const double dXOff = 1.0 / arScale * ptCOP[0] * dScl - skew * ptCOP[1];
    const double dYOff = ptCOP[1] * dScl;

    // Undo center of projection pan to find true at point
    const Vector3 vecUndoCOPPan = dXOff * getRight() +
                                  dYOff * getUp();

	// Should keep unit and ortho, but reset just to make sure
	const Vector3 vecFrom = matAll * (getEye() - ptFocus);
	const Vector3 vecUp = unit( matAll * getUp() );
	const Vector3 vecRight = unit( matAll * getRight() );

    // Undo center of projection pan to find true at point

    const Vector3 vecRedoCOPPan = dXOff * vecRight +
                                  dYOff * vecUp;

    // Find from point if we rotated around the correct at point, then fixed the pan
    const Point3 ptFrom = (ptFocus + vecUndoCOPPan) + vecFrom - vecRedoCOPPan;

    // Correct the at point for the COP pan, then add in the new COP pan
    const Point3 ptAt = (ptFocus + vecUndoCOPPan) - vecRedoCOPPan;

    setFrom( ptFrom );
    setAt( ptAt );
    setUp( vecUp );
}
Example #11
0
eq::Vector2f Channel::getJitter() const
{
    const FrameData& frameData = _getFrameData();
    const Accum& accum = _accum[ lunchbox::getIndexOfLastBit( getEye()) ];

    if( !frameData.isIdle() || accum.step <= 0 )
        return eq::Channel::getJitter();

    const View* view = static_cast< const View* >( getView( ));
    if( !view || view->getIdleSteps() != 256 )
        return eq::Vector2f::ZERO;

    const eq::Vector2i jitterStep = _getJitterStep();
    if( jitterStep == eq::Vector2i::ZERO )
        return eq::Vector2f::ZERO;

    const eq::PixelViewport& pvp = getPixelViewport();
    const float pvp_w = float( pvp.w );
    const float pvp_h = float( pvp.h );
    const float frustum_w = float(( getFrustum().get_width( )));
    const float frustum_h = float(( getFrustum().get_height( )));

    const float pixel_w = frustum_w / pvp_w;
    const float pixel_h = frustum_h / pvp_h;

    const float sampleSize = 16.f; // sqrt( 256 )
    const float subpixel_w = pixel_w / sampleSize;
    const float subpixel_h = pixel_h / sampleSize;

    // Sample value randomly computed within the subpixel
    lunchbox::RNG rng;
    const eq::Pixel& pixel = getPixel();

    const float i = ( rng.get< float >() * subpixel_w +
                      float( jitterStep.x( )) * subpixel_w ) / float( pixel.w );
    const float j = ( rng.get< float >() * subpixel_h +
                      float( jitterStep.y( )) * subpixel_h ) / float( pixel.h );

    return eq::Vector2f( i, j );
}
Example #12
0
eq::Vector2i Channel::_getJitterStep() const
{
    const eq::SubPixel& subPixel = getSubPixel();
    const uint32_t channelID = subPixel.index;
    const View* view = static_cast< const View* >( getView( ));
    if( !view )
        return eq::Vector2i::ZERO;

    const uint32_t totalSteps = uint32_t( view->getIdleSteps( ));
    if( totalSteps != 256 )
        return eq::Vector2i::ZERO;

    const Accum& accum = _accum[ lunchbox::getIndexOfLastBit( getEye()) ];
    const uint32_t subset = totalSteps / getSubPixel().size;
    const uint32_t index = ( accum.step * _primes[ channelID % 100 ] )%subset +
                           ( channelID * subset );
    const uint32_t sampleSize = 16;
    const int dx = index % sampleSize;
    const int dy = index / sampleSize;

    return eq::Vector2i( dx, dy );
}
Example #13
0
void Hero::drawPose( MQO_MODEL pose )
{
	Vector dirV = Vector( direct.z, 0, -direct.x );
	Vector eye = getEye();
	double z = 2.5;
	double y = -2.5;
	Vector core;

	core.x = eye.x + direct.x * z + dirV.x * 0;
	core.y = eye.y + y;
	core.z = eye.z + direct.z * z + dirV.z * 0;

	glPushMatrix();
		glTranslatef( core.x, core.y, core.z );
		glRotatef( rot.y, 0, 1, 0 );
		glRotatef( rot.x + 20, 1, 0, 0 );
		glRotatef( rot.z, 0, 0 ,1 );
		if ( state != H_DAMAGE ) mqoCallModel( pose );
		else					 mqoAlphaCall( pose, 0.7 );
		//mqoCallModel( animeModelMap["atack_right"][0] );
	glPopMatrix();
}
Example #14
0
void Channel::_initJitter()
{
    if( !_initAccum( ))
        return;

    const FrameData& frameData = _getFrameData();
    if( frameData.isIdle( ))
        return;

    const View* view = static_cast< const View* >( getView( ));
    if( !view )
        return;

    const int32_t idleSteps = view->getIdleSteps();
    if( idleSteps == 0 )
        return;

    // ready for the next FSAA
    Accum& accum = _accum[ lunchbox::getIndexOfLastBit( getEye()) ];
    if( accum.buffer )
        accum.buffer->clear();
    accum.step = idleSteps;
}
Example #15
0
void Hero::drawJustAtackBar()
{

	glDisable( GL_DEPTH_TEST );

	Vector eye = getEye();
	Vector dir = direct;

	Vector dirV = Vector( dir.z ,0, -dir.x);
	int chargeMax = H_FRAME_SPAN_STEP;
	int chargeCnt;
	if ( (step == 0 || step == H_MAX_STEP) || state != H_NONE ) chargeCnt = 0;
	else			 chargeCnt = stateManager;
	int cUp, cLo;
	if ( step <= 1 )
	{
		cUp = H_JUST_ATACK_1_UPPER;
		cLo = H_JUST_ATACK_1_LOWER;
	}
	else 
	{
		cUp = H_JUST_ATACK_2_UPPER;
		cLo = H_JUST_ATACK_2_LOWER;
	}
	if ( chargeCnt > chargeMax ) chargeCnt = chargeMax;
	double ratio = (double)chargeCnt/chargeMax;
	double width = 0.1;
	double height = 1.6;
	Vector bCore;
	Vector oCore;
	double z = 5;
	double y = -1;
	double x = 3.2;
	double oy = height * ratio;
	Vector cCore;
	double cRatioU = (double)cUp/chargeMax;
	double cRatioL = (double)cLo/chargeMax;
	double cy = cRatioU*height - cRatioL*height;


	bCore.x = eye.x + dir.x * z + -1*(x) * dirV.x ;
	bCore.y = eye.y + y;
	bCore.z = eye.z + dir.z * z + -1*(x) * dirV.z;

	oCore.x = bCore.x ;
	oCore.y = bCore.y - height/2 + oy/2;
	oCore.z = bCore.z;

	cCore.x = bCore.x;
	cCore.y = bCore.y - height/2 + cRatioL*height + cy/2.0;
	cCore.z = bCore.z;
	
	GLfloat dif[] = { 0.2, 0.2, 0.2, 1 };
	GLfloat gray[] = { 0.2, 0.2, 0.2, 1 };

	glMaterialfv(GL_FRONT, GL_DIFFUSE, dif );
	glMaterialfv( GL_FRONT, GL_SPECULAR, gray );
	glMaterialfv( GL_FRONT, GL_EMISSION, gray );
	glPushMatrix();
	glTranslatef( bCore.x, bCore.y, bCore.z );
	glRotatef( rot.x, 1, 0, 0 );
	glRotatef( rot.y, 0, 1, 0 );
	glRotatef( rot.z, 0, 0 ,1 );
	Scene::drawBox( width/2, height/2, width/4 );
	glPopMatrix();

	GLfloat yellow[] = { 0.7, 0.7, 0, 1 };
	//glMaterialfv(GL_FRONT, GL_SPECULAR, yellow );
	//glMaterialfv( GL_FRONT, GL_EMISSION, spec );
	glMaterialfv(GL_FRONT, GL_EMISSION, yellow);
	glPushMatrix();
	glTranslatef( cCore.x , cCore.y, cCore.z);
	glRotatef( rot.x, 1, 0, 0 );
	glRotatef( rot.y, 0, 1, 0 );
	glRotatef( rot.z, 0, 0 ,1 );
	Scene::drawBox( width/2, cy/2, width/4 );
	glPopMatrix();


	GLfloat orange[] = { 0.5, 0.2, 0, 1 };
	GLfloat purple[] = { 1, 0, 1, 1 };
	//glMaterialfv(GL_FRONT, GL_DIFFUSE, orange);
	glMaterialfv(GL_FRONT, GL_EMISSION, purple );
	glPushMatrix();
	glTranslatef( oCore.x, oCore.y, oCore.z );
	glRotatef( rot.x, 1, 0, 0 );
	glRotatef( rot.y, 0, 1, 0 );
	glRotatef( rot.z, 0, 0 ,1 );
	Scene::drawBox( width/2, oy/2, width/4 );
	glPopMatrix();

	glEnable( GL_DEPTH_TEST );
}
Example #16
0
bool Channel::_initAccum()
{
    View* view = static_cast< View* >( getNativeView( ));
    if( !view ) // Only alloc accum for dest
        return true;

    const eq::Eye eye = getEye();
    Accum& accum = _accum[ lunchbox::getIndexOfLastBit( eye ) ];

    if( accum.buffer ) // already done
        return true;

    if( accum.step == -1 ) // accum init failed last time
        return false;

    // Check unsupported cases
    if( !eq::util::Accum::usesFBO( glewGetContext( )))
    {
        for( size_t i = 0; i < eq::NUM_EYES; ++i )
        {
            if( _accum[ i ].buffer )
            {
                LBWARN << "glAccum-based accumulation does not support "
                       << "stereo, disabling idle anti-aliasing."
                       << std::endl;
                for( size_t j = 0; j < eq::NUM_EYES; ++j )
                {
                    delete _accum[ j ].buffer;
                    _accum[ j ].buffer = 0;
                    _accum[ j ].step = -1;
                }

                view->setIdleSteps( 0 );
                return false;
            }
        }
    }

    // set up accumulation buffer
    accum.buffer = new eq::util::Accum( glewGetContext( ));
    const eq::PixelViewport& pvp = getPixelViewport();
    LBASSERT( pvp.isValid( ));

    if( !accum.buffer->init( pvp, getWindow()->getColorFormat( )) ||
        accum.buffer->getMaxSteps() < 256 )
    {
        LBWARN <<"Accumulation buffer initialization failed, "
               << "idle AA not available." << std::endl;
        delete accum.buffer;
        accum.buffer = 0;
        accum.step = -1;
        return false;
    }

    // else
    LBVERB << "Initialized "
           << (accum.buffer->usesFBO() ? "FBO accum" : "glAccum")
           << " buffer for " << getName() << " " << getEye()
           << std::endl;

    view->setIdleSteps( accum.buffer ? 256 : 0 );
    return true;
}
void SceneTerrain::Idle(float fElapsedTime)
{
	SINGLETON_GET( Camera, cam )
	SINGLETON_GET( Kinect, kin )
	SINGLETON_GET( VarManager, var )

	if( var.getb("dynamic_sun") )
		m_vSunAngle.y += fElapsedTime * 0.01f;

	m_vSunVector = vec4(	-cosf(m_vSunAngle.x) * sinf(m_vSunAngle.y),
							-cosf(m_vSunAngle.y),
							-sinf(m_vSunAngle.x) * sinf(m_vSunAngle.y),
							0.0f );
	
	// Get texture space positions.
	vec3 tEye     = m_pTerrain->getPosition( (float)(cam.getEye().x / m_pTerrain->getHMWidth()),
											 (float)(cam.getEye().z / m_pTerrain->getHMHeight()) );
	vec3 tPointer = m_pTerrain->getPosition( (float)(Mark.m_pointer.m_vPosition.x / m_pTerrain->getHMWidth()),
											 (float)(Mark.m_pointer.m_vPosition.z / m_pTerrain->getHMHeight()) );

	// Set eye and pointer values above terrain. 
	Mark.m_pointer.m_vPosition.y = tPointer.y + 1.0f;
	if( cam.getEye().y < tEye.y + 1.0f )
		cam.vEye.y = tEye.y + 1.0f;

		if(var.getb("using_kinect"))
	{
		// Kinect Camera Movement
		kin.Update();

		if(kin.getRightFoot().y <= (kin.getLeftFoot().y-0.2))
Example #18
0
void Channel::frameDraw( const eq::uint128_t& frameID )
{
    if( stopRendering( ))
        return;

    _initJitter();
    if( _isDone( ))
        return;

    Window* window = static_cast< Window* >( getWindow( ));
    VertexBufferState& state = window->getState();
    const Model* oldModel = _model;
    const Model* model = _getModel();

    if( oldModel != model )
        state.setFrustumCulling( false ); // create all display lists/VBOs

    if( model )
        _updateNearFar( model->getBoundingSphere( ));

    eq::Channel::frameDraw( frameID ); // Setup OpenGL state

    glLightfv( GL_LIGHT0, GL_POSITION, lightPosition );
    glLightfv( GL_LIGHT0, GL_AMBIENT,  lightAmbient  );
    glLightfv( GL_LIGHT0, GL_DIFFUSE,  lightDiffuse  );
    glLightfv( GL_LIGHT0, GL_SPECULAR, lightSpecular );

    glMaterialfv( GL_FRONT, GL_AMBIENT,   materialAmbient );
    glMaterialfv( GL_FRONT, GL_DIFFUSE,   materialDiffuse );
    glMaterialfv( GL_FRONT, GL_SPECULAR,  materialSpecular );
    glMateriali(  GL_FRONT, GL_SHININESS, materialShininess );

    const FrameData& frameData = _getFrameData();
    glPolygonMode( GL_FRONT_AND_BACK,
                   frameData.useWireframe() ? GL_LINE : GL_FILL );

    const eq::Vector3f& position = frameData.getCameraPosition();

    glMultMatrixf( frameData.getCameraRotation().array );
    glTranslatef( position.x(), position.y(), position.z() );
    glMultMatrixf( frameData.getModelRotation().array );

    if( frameData.getColorMode() == COLOR_DEMO )
    {
        const eq::Vector3ub color = getUniqueColor();
        glColor3ub( color.r(), color.g(), color.b() );
    }
    else
        glColor3f( .75f, .75f, .75f );

    if( model )
        _drawModel( model );
    else
    {
        glNormal3f( 0.f, -1.f, 0.f );
        glBegin( GL_TRIANGLE_STRIP );
            glVertex3f(  .25f, 0.f,  .25f );
            glVertex3f( -.25f, 0.f,  .25f );
            glVertex3f(  .25f, 0.f, -.25f );
            glVertex3f( -.25f, 0.f, -.25f );
        glEnd();
    }

    state.setFrustumCulling( true );
    Accum& accum = _accum[ lunchbox::getIndexOfLastBit( getEye()) ];
    accum.stepsDone = LB_MAX( accum.stepsDone,
                              getSubPixel().size * getPeriod( ));
    accum.transfer = true;
}