Esempio n. 1
0
void Player::PickBlock() {
	Vector3D p = Eye();
	Vector3I b = p.Floor();
	Vector3D dir = ToWorldSmooth(this->dir);
	while ((Eye() - p).LengthSquared() < 5 * 5) {
		if (Block::Solid(Game::world->GetBlock(b))) {
			pickedBlock = b;
			picked = true;
			return;
		}
		double xPlaneDist = abs((p.x - (b.x + (dir.x > 0 ? 1 : 0))) / dir.x);
		double yPlaneDist = abs((p.y - (b.y + (dir.y > 0 ? 1 : 0))) / dir.y);
		double zPlaneDist = abs((p.z - (b.z + (dir.z > 0 ? 1 : 0))) / dir.z);
		if (xPlaneDist < yPlaneDist && xPlaneDist < zPlaneDist) {
			b.x += SIGN(dir.x);
			p += dir * xPlaneDist;
			side = -Vector3I::AxisX * SIGN(dir.x);
		}
		else if (yPlaneDist < zPlaneDist) {
			b.y += SIGN(dir.y);
			p += dir * yPlaneDist;
			side = -Vector3I::AxisY * SIGN(dir.y);
		}
		else {
			b.z += SIGN(dir.z);
			p += dir * zPlaneDist;
			side = -Vector3I::AxisZ * SIGN(dir.z);
		}
	}
	picked = false;
	return;
}
Esempio n. 2
0
void setup()
{
	size(200, 200);
	smooth();
	noStroke();

	e1 = Eye(50, 16, 80);
	e2 = Eye(64, 85, 40);
	e3 = Eye(90, 200, 120);
	e4 = Eye(150, 44, 40);
	e5 = Eye(175, 120, 80);
}
Esempio n. 3
0
void Camera :: move(double value)
{
	Point3 Eye(eye.x, eye.y+value, eye.z);
	Point3 Look = lookAt;
	Vector3 Up(0.0, 1.0, 0.0);
	set(Eye, Look, Up);
}
Esempio n. 4
0
    //
    // Constructor
    //
    CSample03::CSample03( 
                         HINSTANCE Instance, UINT Width, UINT Height, const WCHAR *Caption 
                         ):
        CDemo_GL( Instance, Width, Height, Caption )
    {
        Vec3<float> Eye( 0.0f, 0.0f, 5.0f );
        Vec3<float> At( 0.0f, 0.0f, 0.0f );
        Vec3<float> Up( 0.0f, 1.0f, 0.0f );

        m_View.LookAtRH( Eye, At, Up ); 

        //
        // OpenGL objects
        //

        CreateShaders();
        CreateVertexBuffers();
        CreateIndexBuffers();

        m_OcclusionQuery = new GL::CQuery();

        //
        // App
        //

        m_TrackBall = new UI::CTrackBall( Vec2<float>( m_Width / 2.0f, m_Height / 2.0f ), 250.0f, UI::CTrackBall::RT_TRACKBALL );
    }
Esempio n. 5
0
void TileQueue::cycleData( const uint32_t frameNumber, const Compound* compound)
{
    for( unsigned i = 0; i < NUM_EYES; ++i )
    {
        if( !compound->isInheritActive( Eye( 1<<i )))// eye pass not used
        {
            _queueMaster[i] = 0;
            continue;
        }

        // reuse unused queues
        LatencyQueue* queue    = _queues.empty() ? 0 : _queues.back();
        const uint32_t latency = getAutoObsolete();
        const uint32_t dataAge = queue ? queue->_frameNumber : 0;

        if( queue && dataAge < frameNumber-latency && frameNumber > latency )
            // not used anymore
            _queues.pop_back();
        else // still used - allocate new data
        {
            queue = new LatencyQueue;

            getLocalNode()->registerObject( &queue->_queue );
            queue->_queue.setAutoObsolete( 1 ); // current + in use by render nodes
        }

        queue->_queue.clear();
        queue->_frameNumber = frameNumber;

        _queues.push_front( queue );
        _queueMaster[i] = queue;
    }
}
Esempio n. 6
0
void Frame::addInputFrame(Frame* frame, const Compound* compound)
{
    for (unsigned i = 0; i < NUM_EYES; ++i)
    {
        // eye pass not used && no output frame for eye pass
        const Eye eye = Eye(1 << i);
        if (compound->isInheritActive(eye) && _frameData[i])
        {
            frame->_frameData[i] = _frameData[i];
            _inputFrames[i].push_back(frame);

            const Node* inputNode = frame->getNode();
            if (inputNode != getNode())
            {
                co::NodePtr inputNetNode = inputNode->getNode();
                _getInputNodes(i).push_back(inputNode->getID());
                _getInputNetNodes(i).push_back(inputNetNode->getNodeID());
            }
        }
        else
        {
            frame->_frameData[i] = 0;
        }
    }
}
Esempio n. 7
0
HRESULT D3DEngine::OnCreateDevice(ID3D10Device* d3d_device) {
	HRESULT hr;

	// Find the D3DX effect file
    WCHAR str[MAX_PATH];
	V_RETURN(DXUTFindDXSDKMediaFileCch(str, MAX_PATH, kFileTutFX));
    DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program.
    dwShaderFlags |= D3D10_SHADER_DEBUG;
    #endif
    V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, d3d_device, NULL,
                                              NULL, &effect_, NULL, NULL ) );

	// techniqueを入手
	technique_				= effect_->GetTechniqueByName( "Render" );
	diffuse_variable_		= effect_->GetVariableByName( "g_txDiffuse" )->AsShaderResource();
	world_variable_			= effect_->GetVariableByName( "World" )->AsMatrix();
	view_variable_			= effect_->GetVariableByName( "View" )->AsMatrix();
	projection_variable_	= effect_->GetVariableByName( "Projection" )->AsMatrix();

	// Define the input layout
    const D3D10_INPUT_ELEMENT_DESC layout[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    };
    UINT numElements = sizeof( layout ) / sizeof( layout[0] );

    // Create the input layout
    D3D10_PASS_DESC PassDesc;
    technique_->GetPassByIndex( 0 )->GetDesc( &PassDesc );
    V_RETURN( d3d_device->CreateInputLayout( layout, numElements, PassDesc.pIAInputSignature,
		PassDesc.IAInputSignatureSize, &vertex_layout_ ) );

    // Set the input layout
    d3d_device->IASetInputLayout( vertex_layout_ );

	// Load the mesh
	V_RETURN(mesh_.Create(d3d_device, kFileTinyMesh, true));

    // Initialize the world matrices
    D3DXMatrixIdentity( &world_ );

    // Initialize the view matrix
    D3DXVECTOR3 Eye( 0.0f, 3.0f, -500.0f );
    D3DXVECTOR3 At( 0.0f, 1.0f, 0.0f );
    D3DXVECTOR3 Up( 0.0f, 1.0f, 0.0f );
    D3DXMatrixLookAtLH( &view_, &Eye, &At, &Up );

    // Update Variables that never change
    view_variable_->SetMatrix( ( float* )&view_ );

	return S_OK;
}
Esempio n. 8
0
 Eye Eye::leftEye() const
 {
   Math::Point p;
   Math::Transformation trans(_position.toVector(), 0, -yAlpha(), -zAlpha());
   p.y() = -5;
   p = trans.apply(p);
   return (Eye(p, _direction));
 }
Esempio n. 9
0
void Camera :: setLookAt(Point3 lookAtIn)
{
	lookAtOld = lookAt;
	lookAt = lookAtIn;
	Point3 change(lookAt.x - lookAtOld.x, lookAt.y - lookAtOld.y, lookAt.z - lookAtOld.z);
	Point3 Eye(eye.x+change.x, eye.y+change.y, eye.z+change.z);
	Vector3 Up(0.0f, 1.0f, 0.0f);
	set(Eye, lookAt, Up);
}
Esempio n. 10
0
void TileQueue::setOutputQueue( TileQueue* queue, const Compound* compound )
{
    for( unsigned i = 0; i < NUM_EYES; ++i )
    {
        // eye pass not used && no output frame for eye pass
        if( compound->isInheritActive( Eye( 1<<i )))
            _outputQueue[i] =queue;
    }
}
Esempio n. 11
0
void Observer::_updateEyes()
{
    const Matrix4f& head = getHeadMatrix();
    for( size_t i = 0; i < NUM_EYES; ++i )
        _eyeWorld[ i ] = head * getEyePosition( Eye( 1 << i ));

    LBVERB << "Eye position: " << _eyeWorld[ fabric::EYE_CYCLOP_BIT ]
           << std::endl;
}
Esempio n. 12
0
/* Функция обработки сообщения окна.
 * АРГУМЕНТЫ:
 *   - дескриптор окна:
 *       HWND hWnd;
 *   - номер сообщения (см. WM_***):
 *       UINT Msg;
 *   - параметр сообшения ('word parameter'):
 *       WPARAM wParam;
 *   - параметр сообшения ('long parameter'):
 *       LPARAM lParam;
 * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ:
 *   (LRESULT) - в зависимости от сообщения.
 */
LRESULT CALLBACK MyWindowFunc( HWND hWnd, UINT Msg,
                               WPARAM wParam, LPARAM lParam )
{
  HDC hDC;
  static INT w, h;
  POINT pt;
  INT r, r1;
  switch (Msg)
  {
  case WM_CREATE:
    SetTimer(hWnd, 111, 50, NULL);
    return 0;
  case WM_SIZE:
    w = LOWORD(lParam);
    h = HIWORD(lParam);
    return 0;
  case WM_TIMER:
    hDC = GetDC(hWnd);
    if( w / 4 < h / 2)
      r = (w / 4) - (w / 30);
    else
      r = (h / 2) - (h / 15);
    Ellipse(hDC, w / 4 - r, h / 2 - r, w / 4 + r , h / 2 + r);
    Ellipse(hDC, 3 * w / 4 - r, h / 2 - r, 3 * w / 4 + r , h / 2 + r);
    GetCursorPos(&pt);
    ScreenToClient(hWnd, &pt);
    r1 = r / 6;
    SetDCBrushColor(hDC, RGB(0, 0, 0));
    SelectObject(hDC, GetStockObject(DC_BRUSH));
    Eye(hDC, pt.x, pt.y, r, r1, h / 2, w / 4);
    Eye(hDC, pt.x, pt.y, r, r1, h / 2, 3 * w / 4);
    ReleaseDC(hWnd, hDC);
    return 0;
  case WM_DESTROY:
    KillTimer(hWnd, 111);
    PostMessage(hWnd, WM_QUIT, 0, 0);
    return 0;
  }
  return DefWindowProc(hWnd, Msg, wParam, lParam);
} /* End of 'MyWindowFunc' function */
Esempio n. 13
0
void Camera :: set(float eyex, float eyey, float eyez,
		float lookx, float looky, float lookz,
		float upx, float upy, float upz)
{	// create a modelview matrix and send it to OpenGL
	Point3 Eye(eyex, eyey, eyez);
	Point3 look(lookx, looky, lookz);
	Vector3* up = new Vector3(upx, upy, upz);
	eye.set(Eye); 						// store the given eye position
	n->set(eye.x - look.x, eye.y - look.y, eye.z - look.z);	// make n
	u->set( up->cross(n) ); 				// make u = up X n
	n->normalize(); u->normalize(); 			// make them unit length
	v->set(n->cross(u));  					// make v =  n X u
	setModelViewMatrix(); 					// tell OpenGL
}
Esempio n. 14
0
void Camera :: swing(double value)
{
	orbitDegree += value;
	if( orbitDegree > 360.0 )
	{
		orbitDegree -= 360.0;
	}
	if( orbitDegree < 0.0 )
	{
		orbitDegree += 360.0;
	}
	Point3 Eye(cos(orbitDegree*DEG2RAD)*distance+lookAt.x, eye.y+lookAt.y, sin(orbitDegree*DEG2RAD)*distance+lookAt.z);
	Point3 Look = lookAt;
	Vector3 Up(0.0, 1.0, 0.0);
	set(Eye, Look, Up);
}
Esempio n. 15
0
	//-------------------------------------------------------------------------
	void HybridCamera::MoveEvent(int _x, int _y)
	{
		// Compute centered coordinate
		glm::ivec2 pos(_x,_y);

		// If is the fisrt move after click, update coordinate
		if( lastPos.x == -1 || lastPos.y == -1)
			lastPos = pos;

		if(action & PANE)
		{
			glm::vec3 dir   = center - Eye();
			glm::vec3 right = glm::normalize(glm::cross(dir,phiAxis));
			glm::vec3 up	 = glm::normalize(glm::cross(right,dir));
			
			
			float horizontallyOff = Distance * (pos.x-lastPos.x) / 500.f;
			float verticallyOff   = Distance * (pos.y-lastPos.y) / 1000.f;
			center				 += -horizontallyOff * right +verticallyOff * up;
		}
		else if(action & MOVE)
		{
			Phi   -= (pos.x-lastPos.x) / 100.f;
			Theta -= (pos.y-lastPos.y) / 200.f;

			Theta = glm::clamp(Theta,0.01f,3.14f);
//			Theta = std::max(Theta, 0.01f);
//			Theta = std::min(Theta, 3.14f);

			// Check bound and recenter value 
			// Add 2PI to have positive value (fmod need positive value)
			if(Phi<0)
				Phi += 2.f*M_PI;
			if(Theta<0)
				Theta += 2.f*M_PI;
			Phi   = fmod(Phi,float(2.f*M_PI));
			//Theta = fmod(Theta,glm::Constant::HALF_PI);
			Theta = fmod(Theta,float(M_PI));
		}

		// Update last coordinate
		lastPos = pos;
	}
Esempio n. 16
0
void readView()
{
    Scalar  x, y, z;                            // temp coordinates

    theInput >> x >> y >> z;                    // input eye location
    Point Eye(x, y, z);

    theInput >> x >> y >> z;                    // what we look at
    Point Center(x, y, z);

    theInput >> x >> y >> z;                    // input up-vector
    Vector Up(x, y, z);

    Scalar  fovy;
    theInput >> fovy;                           // vertical field of view
                                                // set up camera
    theCamera = new Camera(Eye, Center, Up, fovy,
                        thePixmap->nCols, thePixmap->nRows);
}
Esempio n. 17
0
void Frame::cycleData(const uint32_t frameNumber, const Compound* compound)
{
    _masterFrameData = 0;
    for (unsigned i = 0; i < NUM_EYES; ++i)
    {
        _inputFrames[i].clear();

        const Eye eye = Eye(1 << i);
        if (!compound->isInheritActive(eye)) // eye pass not used
        {
            _frameData[i] = 0;
            continue;
        }

        // reuse unused frame data
        FrameData* data = _datas.empty() ? 0 : _datas.back();
        const uint32_t latency = getAutoObsolete();
        const uint32_t dataAge = data ? data->getFrameNumber() : 0;

        if (data && dataAge < frameNumber - latency && frameNumber > latency)
            // not used anymore
            _datas.pop_back();
        else // still used - allocate new data
        {
            data = new FrameData;

            getLocalNode()->registerObject(data);
            data->setAutoObsolete(1); // current + in use by render nodes
        }

        data->setFrameNumber(frameNumber);

        _datas.push_front(data);
        _frameData[i] = data;
        _getInputNodes(i).clear();
        _getInputNetNodes(i).clear();
        if (!_masterFrameData)
            _masterFrameData = data;
    }
}
Esempio n. 18
0
//--------------------------------------------------------------------------------------
// Create any D3D10 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D10CreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBufferSurfaceDesc,
                                      void* pUserContext )
{
    HRESULT hr = S_OK;

    // Read the D3DX effect file
    DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program.
    dwShaderFlags |= D3D10_SHADER_DEBUG;
    #endif
    hr = D3DX10CreateEffectFromFile( L"Tutorial08.fx", NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL,
                                         NULL, &g_pEffect, NULL, NULL );
    if( FAILED( hr ) )
    {
        MessageBox( NULL,
                    L"The FX file cannot be located.  Please run this executable from the directory that contains the FX file.", L"Error", MB_OK );
        V_RETURN( hr );
    }

    g_pTechnique = g_pEffect->GetTechniqueByName( "Render" );
    g_pWorldVariable = g_pEffect->GetVariableByName( "World" )->AsMatrix();
    g_pViewVariable = g_pEffect->GetVariableByName( "View" )->AsMatrix();
    g_pProjectionVariable = g_pEffect->GetVariableByName( "Projection" )->AsMatrix();
    g_pMeshColorVariable = g_pEffect->GetVariableByName( "vMeshColor" )->AsVector();
    g_pDiffuseVariable = g_pEffect->GetVariableByName( "txDiffuse" )->AsShaderResource();

    // Define the input layout
    D3D10_INPUT_ELEMENT_DESC layout[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    };
    UINT numElements = sizeof( layout ) / sizeof( layout[0] );

    // Create the input layout
    D3D10_PASS_DESC PassDesc;
    g_pTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc );
    V_RETURN( pd3dDevice->CreateInputLayout( layout, numElements, PassDesc.pIAInputSignature,
                                             PassDesc.IAInputSignatureSize, &g_pVertexLayout ) );

    // Set the input layout
    pd3dDevice->IASetInputLayout( g_pVertexLayout );

    // Create vertex buffer
    SimpleVertex vertices[] =
    {
        { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },

        { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( -1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },

        { D3DXVECTOR3( -1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },

        { D3DXVECTOR3( 1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },

        { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },

        { D3DXVECTOR3( -1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },
    };

    D3D10_BUFFER_DESC bd;
    bd.Usage = D3D10_USAGE_DEFAULT;
    bd.ByteWidth = sizeof( SimpleVertex ) * 24;
    bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
    bd.CPUAccessFlags = 0;
    bd.MiscFlags = 0;
    D3D10_SUBRESOURCE_DATA InitData;
    InitData.pSysMem = vertices;
    V_RETURN( pd3dDevice->CreateBuffer( &bd, &InitData, &g_pVertexBuffer ) );

    // Set vertex buffer
    UINT stride = sizeof( SimpleVertex );
    UINT offset = 0;
    pd3dDevice->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &stride, &offset );

    // Create index buffer
    // Create vertex buffer
    DWORD indices[] =
    {
        3,1,0,
        2,1,3,

        6,4,5,
        7,4,6,

        11,9,8,
        10,9,11,

        14,12,13,
        15,12,14,

        19,17,16,
        18,17,19,

        22,20,21,
        23,20,22
    };

    bd.Usage = D3D10_USAGE_DEFAULT;
    bd.ByteWidth = sizeof( DWORD ) * 36;
    bd.BindFlags = D3D10_BIND_INDEX_BUFFER;
    bd.CPUAccessFlags = 0;
    bd.MiscFlags = 0;
    InitData.pSysMem = indices;
    V_RETURN( pd3dDevice->CreateBuffer( &bd, &InitData, &g_pIndexBuffer ) );

    // Set index buffer
    pd3dDevice->IASetIndexBuffer( g_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0 );

    // Set primitive topology
    pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

    // Load the Texture
    hr = D3DX10CreateShaderResourceViewFromFile( pd3dDevice, L"seafloor.dds", NULL, NULL, &g_pTextureRV, NULL );

    // Initialize the world matrices
    D3DXMatrixIdentity( &g_World );

    // Initialize the view matrix
    D3DXVECTOR3 Eye( 0.0f, 3.0f, -6.0f );
    D3DXVECTOR3 At( 0.0f, 1.0f, 0.0f );
    D3DXVECTOR3 Up( 0.0f, 1.0f, 0.0f );
    D3DXMatrixLookAtLH( &g_View, &Eye, &At, &Up );

    // Update Variables that never change
    g_pViewVariable->SetMatrix( ( float* )&g_View );
    g_pDiffuseVariable->SetResource( g_pTextureRV );

    return S_OK;
}
Esempio n. 19
0
//--------------------------------------------------------------------------------------
// Create Direct3D device and swap chain
//--------------------------------------------------------------------------------------
HRESULT InitDevice()
{
    HRESULT hr = S_OK;

    RECT rc;
    GetClientRect( g_hWnd, &rc );
    UINT width = rc.right - rc.left;
    UINT height = rc.bottom - rc.top;

    UINT createDeviceFlags = 0;
#ifdef _DEBUG
    createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;
#endif

    D3D10_DRIVER_TYPE driverTypes[] =
    {
        D3D10_DRIVER_TYPE_HARDWARE,
        D3D10_DRIVER_TYPE_REFERENCE,
    };
    UINT numDriverTypes = sizeof( driverTypes ) / sizeof( driverTypes[0] );

    DXGI_SWAP_CHAIN_DESC sd;
    ZeroMemory( &sd, sizeof( sd ) );
    sd.BufferCount = 1;
    sd.BufferDesc.Width = width;
    sd.BufferDesc.Height = height;
    sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    sd.BufferDesc.RefreshRate.Numerator = 60;
    sd.BufferDesc.RefreshRate.Denominator = 1;
    sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    sd.OutputWindow = g_hWnd;
    sd.SampleDesc.Count = 4;
    sd.SampleDesc.Quality = 0;
    sd.Windowed = TRUE;

    for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
    {
        g_driverType = driverTypes[driverTypeIndex];
        hr = D3D10CreateDeviceAndSwapChain1( NULL, g_driverType, NULL, createDeviceFlags,
            D3D10_FEATURE_LEVEL_10_1, D3D10_1_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice );
        if( SUCCEEDED( hr ) )
            break;
    }
    if( FAILED( hr ) )
        return hr;

    // Create a render target view
    ID3D10Texture2D* pBuffer;
    hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D10Texture2D ), ( LPVOID* )&pBuffer );
    if( FAILED( hr ) )
        return hr;

    hr = g_pd3dDevice->CreateRenderTargetView( pBuffer, NULL, &g_pRenderTargetView );
    pBuffer->Release();
    if( FAILED( hr ) )
        return hr;

    g_pd3dDevice->OMSetRenderTargets( 1, &g_pRenderTargetView, NULL );

    // Setup the viewport
    D3D10_VIEWPORT vp;
    vp.Width = width;
    vp.Height = height;
    vp.MinDepth = 0.0f;
    vp.MaxDepth = 1.0f;
    vp.TopLeftX = 0;
    vp.TopLeftY = 0;
    g_pd3dDevice->RSSetViewports( 1, &vp );

    // Create the effect
    DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program.
    dwShaderFlags |= D3D10_SHADER_DEBUG;
    #endif
    hr = D3DX10CreateEffectFromFile( "Tutorial07.fx", NULL, NULL, "fx_4_0", dwShaderFlags, 0, g_pd3dDevice, NULL,
                                         NULL, &g_pEffect, NULL, NULL );
    if( FAILED( hr ) )
    {
        MessageBox( NULL,
                    "The FX file cannot be located.  Please run this executable from the directory that contains the FX file.", "Error", MB_OK );
        return hr;
    }

    // Obtain the technique
    g_pTechnique = g_pEffect->GetTechniqueByName( "Render" );

    // Obtain the variables
    g_pWorldVariable = g_pEffect->GetVariableByName( "World" )->AsMatrix();
    g_pViewVariable = g_pEffect->GetVariableByName( "View" )->AsMatrix();
    g_pProjectionVariable = g_pEffect->GetVariableByName( "Projection" )->AsMatrix();
    g_pMeshColorVariable = g_pEffect->GetVariableByName( "vMeshColor" )->AsVector();
    g_pDiffuseVariable = g_pEffect->GetVariableByName( "txDiffuse" )->AsShaderResource();

    // Define the input layout
    D3D10_INPUT_ELEMENT_DESC layout[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    };
    UINT numElements = sizeof( layout ) / sizeof( layout[0] );

    // Create the input layout
    D3D10_PASS_DESC PassDesc;
    g_pTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc );
    hr = g_pd3dDevice->CreateInputLayout( layout, numElements, PassDesc.pIAInputSignature,
                                          PassDesc.IAInputSignatureSize, &g_pVertexLayout );
    if( FAILED( hr ) )
        return hr;

    // Set the input layout
    g_pd3dDevice->IASetInputLayout( g_pVertexLayout );

    // Create vertex buffer
    SimpleVertex vertices[] =
    {
        // top
        { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },

        { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( -1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },

        { D3DXVECTOR3( -1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },
        { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },

        { D3DXVECTOR3( 1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },

        { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },

        { D3DXVECTOR3( -1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
    };


    D3D10_BUFFER_DESC bd;
    bd.Usage = D3D10_USAGE_DEFAULT;
    bd.ByteWidth = sizeof( SimpleVertex ) * 24;
    bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
    bd.CPUAccessFlags = 0;
    bd.MiscFlags = 0;
    D3D10_SUBRESOURCE_DATA InitData;
    InitData.pSysMem = vertices;
    hr = g_pd3dDevice->CreateBuffer( &bd, &InitData, &g_pVertexBuffer );
    if( FAILED( hr ) )
        return hr;

    // Set vertex buffer
    UINT stride = sizeof( SimpleVertex );
    UINT offset = 0;
    g_pd3dDevice->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &stride, &offset );

    // Create index buffer
    // Create vertex buffer
    DWORD indices[] =
    {
        3,1,0,
        2,1,3,

        6,4,5,
        7,4,6,

        11,9,8,
        10,9,11,

        14,12,13,
        15,12,14,

        19,17,16,
        18,17,19,

        22,20,21,
        23,20,22
    };
    bd.Usage = D3D10_USAGE_DEFAULT;
    bd.ByteWidth = sizeof( DWORD ) * 36;
    bd.BindFlags = D3D10_BIND_INDEX_BUFFER;
    bd.CPUAccessFlags = 0;
    bd.MiscFlags = 0;
    InitData.pSysMem = indices;
    hr = g_pd3dDevice->CreateBuffer( &bd, &InitData, &g_pIndexBuffer );
    if( FAILED( hr ) )
        return hr;

    // Set index buffer
    g_pd3dDevice->IASetIndexBuffer( g_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0 );

    // Set primitive topology
    g_pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

    // Load the Texture
    //hr = D3DX10CreateShaderResourceViewFromFile( g_pd3dDevice, L"seafloor.dds", NULL, NULL, &g_pTextureRV, NULL );
    //if( FAILED( hr ) )
    //    return hr;


    // Initialize the world matrices
    D3DXMatrixIdentity( &g_World );

    // Initialize the view matrix
    D3DXVECTOR3 Eye( 0.0f, 1.5f, -2.5f );
    D3DXVECTOR3 At( 0.0f, 0.0f, 0.0f );
    D3DXVECTOR3 Up( 0.0f, 1.0f, 0.0f );
    D3DXMatrixLookAtLH( &g_View, &Eye, &At, &Up );

    // Initialize the projection matrix
    D3DXMatrixPerspectiveFovLH( &g_Projection, ( float )D3DX_PI * 0.25f, width / ( FLOAT )height, 0.1f, 100.0f );

    // Update Variables that never change
    g_pViewVariable->SetMatrix( ( float* )&g_View );
    g_pProjectionVariable->SetMatrix( ( float* )&g_Projection );

    HANDLE texHandle = NULL;
    DWORD	d3dFormat;
    ID3D10Texture2D *pTexture = NULL;

    HWND win = NULL;
    do
    {
        win = FindWindowEx(NULL, win, "Chrome_WidgetWin_0", NULL);
    } while (GetWindowTextLength(win) == 0);

    texHandle = DwmaxxGetWindowSharedHandle((HWND)win);

    if (texHandle == NULL)
    {
        MessageBox(NULL, "Unable to get window texture!!!!", "Error", MB_OK);
        return S_FALSE;
    }


    HRESULT hrs = g_pd3dDevice->OpenSharedResource(texHandle, __uuidof(ID3D10Texture2D), (void**)&pTexture);
    D3D10_TEXTURE2D_DESC desc;
    pTexture->GetDesc( &desc );
    D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc;
    D3D10_RESOURCE_DIMENSION type;
    srvDesc.Format = desc.Format;
    srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
    srvDesc.Texture2D.MipLevels = desc.MipLevels;
    srvDesc.Texture2D.MostDetailedMip = desc.MipLevels -1;
    ID3D10ShaderResourceView *pSRView = NULL;
    g_pd3dDevice->CreateShaderResourceView( pTexture, &srvDesc, &pSRView );
    g_pDiffuseVariable->SetResource( pSRView );


    return S_OK;
}
void CompoundUpdateInputVisitor::_updateFrames( Compound* compound )
{
    const Channel* channel = compound->getChannel();
    if( !compound->testInheritTask( fabric::TASK_ASSEMBLE ) || !channel )
        return;

    const Frames& inputFrames = compound->getInputFrames();
    if( inputFrames.empty( ))
    {
        compound->unsetInheritTask( fabric::TASK_ASSEMBLE );
        return;
    }

    for( FramesCIter i = inputFrames.begin(); i != inputFrames.end(); ++i )
    {
        //----- Find corresponding output frame
        Frame* frame = *i;
        const std::string& name = frame->getName();

        Compound::FrameMap::const_iterator j = _outputFrames.find( name );

        if( j == _outputFrames.end( ))
        {
            LBVERB << "Can't find matching output frame, ignoring input frame "
                   << name << std::endl;
            frame->unsetData();
            continue;
        }

        //----- Set frame parameters:
        // 1) Frame offset
        Frame* outputFrame = j->second;
        const Channel* iChannel = compound->getInheritChannel();
        Vector2i frameOffset = outputFrame->getMasterData()->getOffset() +
                               frame->getNativeOffset();

        if( outputFrame->getCompound()->getInheritChannel() != iChannel )
            frameOffset = frame->getNativeOffset();
        else if( channel != iChannel )
        {
            // compute delta offset between source and destination, since the
            // channel's native origin (as opposed to destination) is used.
            const Viewport& frameVP = frame->getViewport();
            const PixelViewport& inheritPVP=compound->getInheritPixelViewport();
            PixelViewport framePVP( inheritPVP );

            framePVP.apply( frameVP );
            frameOffset.x() -= framePVP.x;
            frameOffset.y() -= framePVP.y;

            const PixelViewport& iChannelPVP = iChannel->getPixelViewport();
            frameOffset.x() -= iChannelPVP.x;
            frameOffset.y() -= iChannelPVP.y;
        }
        frame->setOffset( frameOffset );

        // 2) zoom
        _updateZoom( compound, frame, outputFrame );

        // 3) TODO input frames are moved using the offset. The pvp signifies
        //    the pixels to be used from the frame data.
        //framePVP.x = static_cast< int32_t >( frameVP.x * inheritPVP.w );
        //framePVP.y = static_cast< int32_t >( frameVP.y * inheritPVP.h );
        //frame->setInheritPixelViewport( framePVP );
        //----- Link input frame to output frame (connects frame data)
        outputFrame->addInputFrame( frame, compound );

        for( unsigned k = 0; k < NUM_EYES; ++k )
        {
            const Eye eye = Eye( 1<<k );
            if( compound->isInheritActive( eye ) &&  // eye pass used
                outputFrame->hasData( eye ))         // output data for eye pass
            {
                frame->commit();
                LBLOG( LOG_ASSEMBLY )
                    << "Input frame  \"" << name << "\" on channel \""
                    << channel->getName() << "\" id " << frame->getID() << " v"
                    << frame->getVersion() << "\" tile pos "
                    << frame->getOffset() << ' ' << frame->getZoom()
                    << std::endl;
                break;
            }
        }
    }
}
Esempio n. 21
0
	//-------------------------------------------------------------------------	
	const glm::mat4& Camera::View() const 
	{
		viewMatrix = glm::lookAt(Eye(),Center(),Up());
		return viewMatrix;
	}
Esempio n. 22
0
BOOL gldInitialiseMesa_DX(
	DGL_ctx *lpCtx)
{
	GLD_driver_dx8	*gld = NULL;
	int				MaxTextureSize, TextureLevels;
	BOOL			bSoftwareTnL;

	if (lpCtx == NULL)
		return FALSE;

	gld = lpCtx->glPriv;
	if (gld == NULL)
		return FALSE;

	if (glb.bMultitexture) {
		lpCtx->glCtx->Const.MaxTextureUnits = gld->d3dCaps8.MaxSimultaneousTextures;
		// Only support MAX_TEXTURE_UNITS texture units.
		// ** If this is altered then the FVF formats must be reviewed **.
		if (lpCtx->glCtx->Const.MaxTextureUnits > GLD_MAX_TEXTURE_UNITS_DX8)
			lpCtx->glCtx->Const.MaxTextureUnits = GLD_MAX_TEXTURE_UNITS_DX8;
	} else {
		// Multitexture override
		lpCtx->glCtx->Const.MaxTextureUnits = 1;
	}

	// max texture size
	MaxTextureSize = min(gld->d3dCaps8.MaxTextureHeight, gld->d3dCaps8.MaxTextureWidth);
	if (MaxTextureSize == 0)
		MaxTextureSize = 256; // Sanity check

	//
	// HACK!!
	if (MaxTextureSize > 1024)
		MaxTextureSize = 1024; // HACK - CLAMP TO 1024
	// HACK!!
	//

	// Got to set MAX_TEXTURE_SIZE as max levels.
	// Who thought this stupid idea up? ;)
	TextureLevels = 0;
	// Calculate power-of-two.
	while (MaxTextureSize) {
		TextureLevels++;
		MaxTextureSize >>= 1;
	}
	lpCtx->glCtx->Const.MaxTextureLevels = (TextureLevels) ? TextureLevels : 8;
	lpCtx->glCtx->Const.MaxDrawBuffers = 1;

	IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_LIGHTING, FALSE);
	IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_CULLMODE, D3DCULL_NONE);
	IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_DITHERENABLE, TRUE);
	IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SHADEMODE, D3DSHADE_GOURAUD);

	IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_ZENABLE,
		(lpCtx->lpPF->dwDriverData!=D3DFMT_UNKNOWN) ? D3DZB_TRUE : D3DZB_FALSE);

	// Set the view matrix
	{
		D3DXMATRIX	vm;
#if 1
		D3DXMatrixIdentity(&vm);
#else
		D3DXVECTOR3 Eye(0.0f, 0.0f, 0.0f);
		D3DXVECTOR3 At(0.0f, 0.0f, -1.0f);
		D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f);
		D3DXMatrixLookAtRH(&vm, &Eye, &At, &Up);
		vm._31 = -vm._31;
		vm._32 = -vm._32;
		vm._33 = -vm._33;
		vm._34 = -vm._34;
#endif
		IDirect3DDevice8_SetTransform(gld->pDev, D3DTS_VIEW, &vm);
	}

	if (gld->bHasHWTnL) {
		if (glb.dwTnL == GLDS_TNL_DEFAULT)
			bSoftwareTnL = FALSE; // HW TnL
		else {
			bSoftwareTnL = ((glb.dwTnL == GLDS_TNL_MESA) || (glb.dwTnL == GLDS_TNL_D3DSW)) ? TRUE : FALSE;
		}
	} else {
		// No HW TnL, so no choice possible
		bSoftwareTnL = TRUE;
	}
	IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, bSoftwareTnL);

// Dump this in a Release build as well, now.
//#ifdef _DEBUG
	ddlogPrintf(DDLOG_INFO, "HW TnL: %s",
		gld->bHasHWTnL ? (bSoftwareTnL ? "Disabled" : "Enabled") : "Unavailable");
//#endif

	gldEnableExtensions_DX8(lpCtx->glCtx);
	gldInstallPipeline_DX8(lpCtx->glCtx);
	gldSetupDriverPointers_DX8(lpCtx->glCtx);

	// Signal a complete state update
	lpCtx->glCtx->Driver.UpdateState(lpCtx->glCtx, _NEW_ALL);

	// Start a scene
	IDirect3DDevice8_BeginScene(gld->pDev);
	lpCtx->bSceneStarted = TRUE;

	return TRUE;
}
Esempio n. 23
0
int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if(!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if(!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    GLFWmousebuttonfun pFun = mouseCallback;


    // init GLEW
    glewExperimental = GL_TRUE;
    GLenum err = glewInit();
    if(GLEW_OK != err)
        return -1;

    GLuint m_shaderProgramId;
    {   // shaders
        GLuint m_vertexShaderId = loadShader("C:\\Projects\\DI\\testGL\\VertexShader.glsl", GL_VERTEX_SHADER);
        GLuint m_fragmentShaderId = loadShader("C:\\Projects\\DI\\testGL\\FragmentShader.glsl", GL_FRAGMENT_SHADER);

        m_shaderProgramId = glCreateProgram();
        glAttachShader(m_shaderProgramId, m_vertexShaderId);
        glAttachShader(m_shaderProgramId, m_fragmentShaderId);
        glLinkProgram(m_shaderProgramId);
    }

    CModel model;
    kt::readObj(&model, "C:\\Projects\\Resources\\Models\\obj\\african_head.obj");
    GLuint vertexbuffer = model.vbId();

    //glEnable(GL_DEPTH_TEST);
    //glClearDepth(1.0f);
    //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // ????

    // Camera and matrices
    float radius = 1.0f;
    static float orbitX = 0;
    static float orbitY = 0;

    // GLFWAPI void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos);
    // glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun cbfun);
    // glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun cbfun);
    // GLFWAPI void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos);

    /* Loop until the user closes the window */
    while(!glfwWindowShouldClose(window))
    {
        GLFWmousebuttonfun ptr = glfwSetMouseButtonCallback(window, pFun);
        /* Render here */
        {
            glEnable(GL_DEPTH_TEST);
            glClearDepth(1.0f);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            if(pRotation)
            {
                D1 x, y;
                glfwGetCursorPos(window, &x, &y);
                orbitX += (pRotation->x - x) / 100;
                orbitY += (pRotation->y - y) / 100;
                pRotation->x = x;
                pRotation->y = y;
            }
            // orbit += 0.0001f;

            // Инициализация орбитальных данных координат камеры
            // glm::vec3 Eye(sin(orbitX)*radius, 1.0f, -0.5f + cos(orbitX)*radius*1.5f);
            glm::vec3 Eye(-radius*sin(orbitY)*cos(orbitX), radius*cos(orbitY), radius*sin(orbitY)*sin(orbitX));
            glm::mat4 mWorld;
            glm::mat4 mView;
            glm::mat4 mProjection;
            mWorld = glm::mat4(1.0f, 0, 0, 0, 0, 1.0f, 0, 0, 0, 0, 1.0f, 0, 0, 0, 0, 1.0f);
            mView = glm::lookAt(Eye, glm::vec3(0, 0, 0), glm::vec3(0.0f, 1.0f, 0.0f));
            mProjection = glm::perspectiveFov(90.0f, 533.0f, 400.0f, 0.001f, 1000.0f);



            // Clear the screen
            glClear(GL_COLOR_BUFFER_BIT);

            // Use our shader
            glUseProgram(m_shaderProgramId);

            //Установка констант шейдера матриц
            int iWorld = glGetUniformLocation(m_shaderProgramId, "mWorld");
            int iView = glGetUniformLocation(m_shaderProgramId, "mView");
            int iProjection = glGetUniformLocation(m_shaderProgramId, "mProjection");

            glUniformMatrix4fv(iWorld, 1, GL_FALSE, glm::value_ptr(mWorld));
            glUniformMatrix4fv(iView, 1, GL_FALSE, glm::value_ptr(mView));
            glUniformMatrix4fv(iProjection, 1, GL_FALSE, glm::value_ptr(mProjection));

            // 1rst attribute buffer : vertices
            glEnableVertexAttribArray(0);
            glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
            glVertexAttribPointer(
                0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
                3,                  // size
                GL_FLOAT,           // type
                GL_FALSE,           // normalized?
                0,                  // stride
                (void*)0            // array buffer offset
            );

            // Draw the triangle !
            glDrawArrays(GL_TRIANGLES, 0, model.nTrng()*3); // 3 indices starting at 0 -> 1 triangle

            glDisableVertexAttribArray(0);
        }
        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}
Esempio n. 24
0
#define PI 3.14159265359
void drawScene(void);

 //pixels;	
GLuint imageTexture = 0;
int renderWidth = 512;
int renderHeight = 512;

unsigned char *pixels = new unsigned char[renderWidth*renderHeight*3];


glm::vec3 shootRay();

float FieldOfView = PI/6; //Degrees

Eye camera = Eye(glm::vec3(0,0,7.6), FieldOfView);

float pixelPlane = 4.0;

void init(void)
{
	float seconds = glutGet(GLUT_ELAPSED_TIME);

	 Objects obj;

	 float raysPerPixel = 9.0f;
	 int rays = int(raysPerPixel);

	float X =2;
	float Y =2;
	float Z =0;
Esempio n. 25
0
    //
    // Constructor
    //
    CDemo_GL::CDemo_GL( 
                       HINSTANCE Instance, UINT Width, UINT Height, const WCHAR *Caption 
                       ):
        IDemo( Instance, Width, Height, Caption )
    {
        Vec3<float> Eye( 0.0f, 50.0f, 120.0f );
        Vec3<float> At( 0.0f, 0.0f, 0.0f );
        Vec3<float> Up( 0.0f, 1.0f, 0.0f );

        m_View.LookAtRH( Eye, At, Up ); 
        m_Proj.PerspectiveRH( 60.0f, (float)m_Width / (float)m_Height, 1.0f, 1000.0f );
        m_Ortho.Ortho2DRH( 0.0f, m_Width, 0.0f, m_Height );

        try
        {
            CreateRender();
        }
        catch (const Sys::CException& Ex)
        {
            DestroyRender();
            
            throw Ex;
        }

        //
        // Render
        //

        try
        {
            CreateRender();
        }
        catch (const Sys::CException& Ex)
        {
            DestroyRender();
            
            throw Ex;
        }

        //
        // Driver description
        //

        GL::CDriver::GetDesc( &m_DriverDesc );

        //
        // Font
        //

        GLU::CFont::TDesc Desc;

        Desc.Height = 14;
        Desc.Width = 0;
        Desc.Weight = FW_NORMAL;
        Desc.Italic = false;
        Desc.Underline = false;
        Desc.CharSet = DEFAULT_CHARSET;
        Desc.OutputPrecision = OUT_DEFAULT_PRECIS;
        Desc.Quality = ANTIALIASED_QUALITY;//DEFAULT_QUALITY;
        Desc.PitchAndFamily = FF_DONTCARE | DEFAULT_PITCH;
        wcscpy( Desc.FaceName, L"Microsoft Sans Serif" );

        m_Font = new GLU::CBitmapFont( Desc );

        m_Stack = new GLU::CMatrixStack();
    }
Esempio n. 26
0
//--------------------------------------------------------------------------------------
// Create any D3D10 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D10CreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBufferSurfaceDesc,
                                      void* pUserContext )
{
    HRESULT hr;

    V_RETURN( g_DialogResourceManager.OnD3D10CreateDevice( pd3dDevice ) );
    V_RETURN( g_D3DSettingsDlg.OnD3D10CreateDevice( pd3dDevice ) );
    V_RETURN( D3DX10CreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET,
                                OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
                                L"Arial", &g_pFont ) );
    V_RETURN( D3DX10CreateSprite( pd3dDevice, 512, &g_pSprite ) );
    g_pTxtHelper = new CDXUTTextHelper( NULL, NULL, g_pFont, g_pSprite, 15 );


    DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program.
    dwShaderFlags |= D3D10_SHADER_DEBUG;
    #endif

    // Read the D3DX effect file
    WCHAR str[MAX_PATH];
    V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"Tutorial13.fx" ) );
    V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL,
                                          NULL, &g_pEffect, NULL, NULL ) );

    // Obtain the technique
    g_pTechnique = g_pEffect->GetTechniqueByName( "Render" );

    // Obtain the variables
    g_ptxDiffuseVariable = g_pEffect->GetVariableByName( "g_txDiffuse" )->AsShaderResource();
    g_pWorldVariable = g_pEffect->GetVariableByName( "World" )->AsMatrix();
    g_pViewVariable = g_pEffect->GetVariableByName( "View" )->AsMatrix();
    g_pProjectionVariable = g_pEffect->GetVariableByName( "Projection" )->AsMatrix();
    g_pExplodeVariable = g_pEffect->GetVariableByName( "Explode" )->AsScalar();

    // Set Waviness
    g_pExplodeVariable->SetFloat( g_fExplode );

    // Define the input layout
    const D3D10_INPUT_ELEMENT_DESC layout[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    };
    UINT numElements = sizeof( layout ) / sizeof( layout[0] );

    // Create the input layout
    D3D10_PASS_DESC PassDesc;
    g_pTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc );
    V_RETURN( pd3dDevice->CreateInputLayout( layout, numElements, PassDesc.pIAInputSignature,
                                             PassDesc.IAInputSignatureSize, &g_pVertexLayout ) );

    // Set the input layout
    pd3dDevice->IASetInputLayout( g_pVertexLayout );

    // Load the mesh
    V_RETURN( g_Mesh.Create( pd3dDevice, L"Tiny\\tiny.sdkmesh", true ) );

    // Initialize the world matrices
    D3DXMatrixIdentity( &g_World );

    // Initialize the camera
    D3DXVECTOR3 Eye( 0.0f, 0.0f, -800.0f );
    D3DXVECTOR3 At( 0.0f, 0.0f, 0.0f );
    g_Camera.SetViewParams( &Eye, &At );

    return S_OK;
}