Exemplo n.º 1
0
CMatrix4::CMatrix4(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4)
#if 0
    : m{ v1.GetX(), v1.GetY(), v1.GetZ(), v1.GetW(),
         v2.GetX(), v2.GetY(), v2.GetZ(), v2.GetW(),
         v3.GetX(), v3.GetY(), v3.GetZ(), v3.GetW(),
         v4.GetX(), v4.GetY(), v4.GetZ(), v4.GetW() }
{
#else
{
    constexpr std::size_t bytes = sizeof(float) * 4;
    std::memcpy(static_cast<void*>(&m[0]), static_cast<const float*>(v1), bytes);
    std::memcpy(static_cast<void*>(&m[4]), static_cast<const float*>(v2), bytes);
    std::memcpy(static_cast<void*>(&m[8]), static_cast<const float*>(v3), bytes);
    std::memcpy(static_cast<void*>(&m[12]), static_cast<const float*>(v4), bytes);
#endif
}

CMatrix4::CMatrix4(const Array& m)
    : m(m)
{
}

void CMatrix4::SetRow(std::int32_t row, const Vector4& v)
{
    HASENPFOTE_ASSERT_MSG((row >= 0) && (row < order), "Row index out of bounds.");
    m[offset<order>(row, 0)] = v.GetX();
    m[offset<order>(row, 1)] = v.GetY();
    m[offset<order>(row, 2)] = v.GetZ();
    m[offset<order>(row, 3)] = v.GetW();
}
Exemplo n.º 2
0
 // /////////////////////////////////////////////////////////////////
 //
 // /////////////////////////////////////////////////////////////////
 void SliderControl::VSetColor(const Vector4 &colorRef)
 {
     ControlWidget::VSetColor(colorRef);
     Vector4 oldButtonColor = m_sliderButPtr->VGetColor();
     oldButtonColor.SetW(colorRef.GetW());
     m_sliderButPtr->VSetColor(oldButtonColor);
     m_lineColor.SetW(colorRef.GetW());
 }
Exemplo n.º 3
0
void CMatrix4::SetColumn(std::int32_t column, const Vector4& v)
{
    HASENPFOTE_ASSERT_MSG((column >= 0) && (column < order), "Column index out of bounds.");
    m[offset<order>(0, column)] = v.GetX();
    m[offset<order>(1, column)] = v.GetY();
    m[offset<order>(2, column)] = v.GetZ();
    m[offset<order>(3, column)] = v.GetW();
}
Exemplo n.º 4
0
void CgEffect::SetVector(const char* name, Vector4& v)
{
    cgSetParameter4f(this->retrieveParameter(name), v.GetX(), v.GetY(), v.GetZ(), v.GetW());
}
Exemplo n.º 5
0
void RenderFrameDX10(void)
{
	Vector4 vColorDarkBlue(0.0f, 0.0f, 0.5f, 1.0f);
	Vector4 vColorBlue(0.0f, 0.0f, 0.8f, 1.0f);
	Vector4 vPlane(0.0f, 0.0f, 1.0f, -g_mirror_z);

	D3D10_VIEWPORT mainVP, VP;

	// `取得呼叫GutCreateGraphicsDeviceDX10時所產生的D3D10物件`
	ID3D10RenderTargetView *pRenderTargetView = GutGetDX10RenderTargetView();
	ID3D10DepthStencilView *pDepthStencilView = GutGetDX10DepthStencilView();
	// front/back buffer
	IDXGISwapChain *pSwapChain = GutGetDX10SwapChain(); 

	// `在動態貼圖中畫出鏡射的茶壼`
	{
		UINT nViewports = 1;
		g_pDevice->RSGetViewports(&nViewports, &mainVP);

		// new rendertarget viewport size
		VP.TopLeftX = VP.TopLeftY = 0;
		VP.Width = VP.Height = 512;
		VP.MinDepth = 0.0f;
		VP.MaxDepth = 1.0f;

		ID3D10ShaderResourceView *null_views[4] = {NULL, NULL, NULL, NULL};
		g_pDevice->PSSetShaderResources(0, 4, null_views);
		// `使用代表動態貼圖的`RenderTarget
		g_pDevice->OMSetRenderTargets(1, &g_pRGBAView, g_pDepthStencilView);
		//
		g_pDevice->RSSetViewports(1, &VP);
		// `清除顏色`
		g_pDevice->ClearRenderTargetView(g_pRGBAView, (float *)&vColorDarkBlue);
		// `清除`Depth/Stencil buffer
		g_pDevice->ClearDepthStencilView(g_pDepthStencilView, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
		// `畫鏡射的茶壼`
		RenderModelDX10(true, &vPlane);
	}

	// `在主Framebuffer中畫出正常的茶壼`
	{
		// `使用主`framebuffer
		g_pDevice->OMSetRenderTargets(1, &pRenderTargetView, pDepthStencilView);
		//
		g_pDevice->RSSetViewports(1, &mainVP);
		// `清除顏色`
		g_pDevice->ClearRenderTargetView(pRenderTargetView, (float *)&vColorBlue);
		// `清除`Depth/Stencil buffer
		g_pDevice->ClearDepthStencilView(pDepthStencilView, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
		// `畫茶壼`
		RenderModelDX10(false, &vPlane);
	}

	// `在主framebuffer中畫出鏡面`
	{
		UINT stride = sizeof(Vertex_VT);
		UINT offset = 0;
		// `設定`vertex shader
		g_pDevice->VSSetShader(g_pVertexShader);
		// `設定`pixel shader
		g_pDevice->PSSetShader(g_pPixelShader);
		// `設定`Shader Constants
		g_pDevice->VSSetConstantBuffers(0, 1, &g_pVSConstBuffer);
		// `設定vertex資料格式`
		g_pDevice->IASetInputLayout(g_pVertexLayout);
		// `設定三角形頂點索引值資料排列是triangle strip`
		g_pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
		// Vertex Buffer
		g_pDevice->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset);
		// `計算`texture matrix
		Matrix4x4 uv_offset_matrix;
		uv_offset_matrix.Scale_Replace(0.5f, -0.5f, 1.0f);
		uv_offset_matrix[3].Set(0.5f, 0.5f, 0.0f, 1.0f);
		Matrix4x4 texture_matrix = g_mirror_view_matrix * g_proj_matrix * uv_offset_matrix;

		Vertex_VT *pVertices = NULL;
		g_pVertexBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, (void **) &pVertices);
		for ( int i=0; i<4; i++ )
		{
			Vector4 vPosition = g_Quad[i].m_Position;
			Vector4 vTexcoord = vPosition * texture_matrix;
			vTexcoord /= vTexcoord.GetW();

			pVertices[i].m_Position = vPosition;
			pVertices[i].m_Texcoord = vTexcoord;
		}
		g_pVertexBuffer->Unmap();

		// `計算矩陣`
		Matrix4x4 view_matrix = g_Control.GetViewMatrix();
		Matrix4x4 wvp_matrix = view_matrix * g_proj_matrix;
		// `更新shader參數`
		Matrix4x4 *pConstData;
		g_pVSConstBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, (void **) &pConstData );
		*pConstData = wvp_matrix;
		g_pVSConstBuffer->Unmap();
		// `套用第1張貼圖`
		g_pDevice->PSSetShaderResources(0, 1, &g_pTextureView);
		g_pDevice->PSSetSamplers(0, 1, &g_pSamplerState);
		// `畫出格子`
		g_pDevice->Draw(4, 0);
	}

	// `等待硬體掃結束, 然後才更新畫面.`
	pSwapChain->Present(1, 0);
}