void RenderPipe_zpass_opengl::setLight( CVector lightPos, CVector lightLookAt)
{
	m_lightPos = lightPos;
	m_lightLookAt = lightLookAt;

	m_light_vmat = ViewMatrix(m_lightPos,m_lightLookAt,m_lightUp,0.0f);
}
Exemple #2
0
void Camera::ViewMatrix(Matrix &m)
{

	if (dirty_)
		ViewMatrix();

	m.set(matrix_);
}
Exemple #3
0
void RSSpotLight::SetupPlanes()
{
	m_Matrix=ViewMatrix(m_Position,m_Direction,m_Up);
	ComputeFrustrum(m_Planes+0, -1,  0, 1);
	ComputeFrustrum(m_Planes+1,  1,  0, 1);
	ComputeFrustrum(m_Planes+2,  0,  1, 1);
	ComputeFrustrum(m_Planes+3,  0, -1, 1);

}
Exemple #4
0
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE,
                     LPTSTR,
                     int nCmdShow)
{
{ // code block
	Helper::Window mainWindow(	hInstance, nCmdShow, &WndProc,
								L"Skinning", L"skinning", 4 );

	D3DPRESENT_PARAMETERS params;
		ZeroMemory( &params, sizeof( params ) );

		params.Windowed = TRUE;
		params.SwapEffect = D3DSWAPEFFECT_DISCARD;
		params.BackBufferFormat = D3DFMT_UNKNOWN;
		params.EnableAutoDepthStencil = TRUE;
		params.AutoDepthStencilFormat = D3DFMT_D16;
		params.MultiSampleType = D3DMULTISAMPLE_NONE;

	D3D::GraphicDevice graphicDevice( mainWindow.GetHWND(), params );
	graphicDevice.SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );
	graphicDevice.SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

	Helper::SpectatorCoords spectatorCoords( 40.0f, D3DX_PI / 2, -D3DX_PI / 2 );
	Cylinder cylinder(nPointsPerCircle, nPointsPerGeneratrix, Height, Radius, graphicDevice, Freq, MaxAngle);
	cylinder.SetPositionMatrix( RotateZMatrix(D3DX_PI/2)*TranslationMatrix(0, -Height/2*0, 0) );
	cylinder.SetViewMatrix( ViewMatrix( spectatorCoords.GetCartesianCoords(),
										D3DXVECTOR3(0.0f, 0.0f, 0.0f),
										D3DXVECTOR3(0.0f, 1.0f, 0.0f)) );
	cylinder.SetProjectiveMatrix( ProjectiveMatrix( FrontClippingPlane, BackClippingPlane ) );



	SetWindowLong(mainWindow.GetHWND(), 0, reinterpret_cast<LONG>(&spectatorCoords));
	SetWindowLong(mainWindow.GetHWND(), sizeof(LONG), reinterpret_cast<LONG>(&cylinder));

	MSG msg;

	ZeroMemory(&msg, sizeof(msg));
    while( msg.message != WM_QUIT )
    {
        if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
        {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        else
		{
			Render(graphicDevice, spectatorCoords, cylinder);
		}
    }
} // code block

	_CrtDumpMemoryLeaks();

	return 0;
}
Exemple #5
0
// When there is no rotation, direction is assumed to be (0 0 -1)
void Camera::Direction(Vector3 &dir)
{  
	if (dirty_)
	{
		Matrix m;
		ViewMatrix(m);
		dir(-m[0][2], -m[1][2], -m[2][2]);
	}
	else
	{
		dir(-matrix_[0][2], -matrix_[1][2], -matrix_[2][2]);
	}
}
Exemple #6
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_KEYDOWN:
		{
			Helper::SpectatorCoords* pSpectatorCoords = NULL;
			Cylinder* cylinder = NULL;
			pSpectatorCoords = reinterpret_cast<Helper::SpectatorCoords*>(
												GetWindowLong(hWnd, 0));
			cylinder = reinterpret_cast<Cylinder*>( GetWindowLong(hWnd,sizeof(LONG)) );
			switch(wParam)
			{
			case VK_UP:
				pSpectatorCoords->DecTheta();
				break;
			case VK_DOWN:
				pSpectatorCoords->IncTheta();
				break;
			case VK_RIGHT:
				pSpectatorCoords->IncPhi();
				break;
			case VK_LEFT:
				pSpectatorCoords->DecPhi();
				break;
			case VK_NEXT:
			case 'S':
				pSpectatorCoords->IncR();
				break;
			case VK_PRIOR:
			case 'W':
				pSpectatorCoords->DecR();
				break;
			default:
				return DefWindowProc(hWnd, message, wParam, lParam);
			}
			cylinder->SetViewMatrix( ViewMatrix( pSpectatorCoords->GetCartesianCoords(),
												 D3DXVECTOR3(0.0f, 0.0f, 0.0f),
												 D3DXVECTOR3(0.0f, 1.0f, 0.0f)) );

			break;
		}
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}

	return 0;
}
Exemple #7
0
void Renderer::renderColor(Mesh *mesh) {
    Eigen::Matrix4f MVP = ProjectionMatrix * ViewMatrix * mesh->ModelMatrix;

    glUseProgram(program["color"]);
    glUniformMatrix4fv(ViewMatrixID, 1, GL_FALSE, &ViewMatrix(0, 0));
    glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP(0, 0));
    glUniformMatrix4fv(ModelMatrixID, 1, GL_FALSE, &mesh->ModelMatrix(0, 0));
    Vector3f lightPosition(0,-4,1);
//    lightPosition = ViewMatrix.topRightCorner(3,1);
//    printf("%.4f %.4f %.4f\n", lightPosition(0), lightPosition(1), lightPosition(2));
    glUniform3fv(LightPositionID, 1, &lightPosition(0));

    mesh->Render();
}
bool RenderPipe_zpass_opengl::init( Device_opengl *device )
{

	m_vertexProgramID = loadVertexShaderOpenGL_GLSL(".//Src//Shader//ZPass.glvs");
	if ( m_vertexProgramID==NULL )
		return false;

	m_fragmentProgramID = loadFragmentShaderOpenGL_GLSL(".//Src//Shader//ZPass.glfs");
	if ( m_fragmentProgramID==NULL )
		return false;

	m_pipeProgramID = glCreateProgram();

	glAttachShader(m_pipeProgramID, m_vertexProgramID);
	glAttachShader(m_pipeProgramID, m_fragmentProgramID);
	glLinkProgram(m_pipeProgramID);

	MatrixOrthoForLH(&m_light_pmat, m_orthW, m_orthH,m_lightNearZ,m_lightFarZ);
	m_light_vmat = ViewMatrix(m_lightPos,m_lightLookAt,m_lightUp,0.0f);

	return true;
}
// 描画用パーツデータの作成、1パーツ分
bool FSsAnimeDecoder::CreateRenderPart(FSsRenderPart& OutRenderPart, FSsPartState* State)
{
	// 各種非表示チェック
	if(!State){ return false; }
	if(State->Hide){ return false; }
	if(State->NoCells){ return false; }
	if(0.0f == State->Alpha){ return false; }
	if(NULL == State->CellValue.Cell){ return false; }
	if(NULL == State->CellValue.Texture){ return false; }

	// RenderTargetに対する描画基準位置
	float OffX = (float)(CurAnimeCanvasSize.X /2) + (CurAnimePivot.X * CurAnimeCanvasSize.X);
	float OffY = (float)(CurAnimeCanvasSize.Y /2) - (CurAnimePivot.Y * CurAnimeCanvasSize.Y);

	// 頂点座標
	FMatrix ViewMatrix(
		FVector(State->Matrix[ 0], State->Matrix[ 1], State->Matrix[ 2]),
		FVector(State->Matrix[ 4], State->Matrix[ 5], State->Matrix[ 6]),
		FVector(State->Matrix[ 8], State->Matrix[ 9], State->Matrix[10]),
		FVector(State->Matrix[12], State->Matrix[13], State->Matrix[14])
		);
	FVector2D Vertices2D[4];
	for(int i = 0; i < 4; ++i)
	{
		FVector4 V = ViewMatrix.TransformPosition(FVector(
			State->Vertices[i*3 + 0],
			State->Vertices[i*3 + 1],
			State->Vertices[i*3 + 2]
			));
		Vertices2D[i] = FVector2D(V.X + OffX, -V.Y + OffY);
	}

	// 上下反転,左右反転
	if(State->HFlip)
	{
		FVector2D tmp;
		tmp = Vertices2D[0];
		Vertices2D[0] = Vertices2D[1];
		Vertices2D[1] = tmp;
		tmp = Vertices2D[2];
		Vertices2D[2] = Vertices2D[3];
		Vertices2D[3] = tmp;
	}
	if(State->VFlip)
	{
		FVector2D tmp;
		tmp = Vertices2D[0];
		Vertices2D[0] = Vertices2D[2];
		Vertices2D[2] = tmp;
		tmp = Vertices2D[1];
		Vertices2D[1] = Vertices2D[3];
		Vertices2D[3] = tmp;
	}

	// UV
	FVector2D UVs[4];
	for(int i = 0; i < 4; ++i)
	{
		UVs[i] = FVector2D(State->CellValue.Uvs[i].X + State->Uvs[i*2 + 0] + State->UvTranslate.X, State->CellValue.Uvs[i].Y + State->Uvs[i*2 + 1] + State->UvTranslate.Y);
	}
	if(1.f != State->UvScale.X)
	{
		float Center;
		Center = (UVs[1].X - UVs[0].X) / 2.f + UVs[0].X;
		UVs[0].X = Center - ((Center - UVs[0].X) * State->UvScale.X);
		UVs[1].X = Center - ((Center - UVs[1].X) * State->UvScale.X);
		Center = (UVs[3].X - UVs[2].X) / 2.f + UVs[2].X;
		UVs[2].X = Center - ((Center - UVs[2].X) * State->UvScale.X);
		UVs[3].X = Center - ((Center - UVs[3].X) * State->UvScale.X);
	}
	if(0.f != State->UvRotation)
	{
		FVector2D UVCenter((UVs[1].X - UVs[0].X) / 2.f + UVs[0].X, (UVs[2].Y - UVs[0].Y) / 2.f + UVs[0].Y);
		float S = FMath::Sin(FMath::DegreesToRadians(State->UvRotation));
		float C = FMath::Cos(FMath::DegreesToRadians(State->UvRotation));
		for(int i = 0; i < 4; ++i)
		{
			UVs[i] -= UVCenter;
			UVs[i] = FVector2D(
				UVs[i].X * C - UVs[i].Y * S,
				UVs[i].X * S + UVs[i].Y * C
				);
			UVs[i] += UVCenter;
		}
	}
	if(1.f != State->UvScale.Y)
	{
		float Center;
		Center = (UVs[2].Y - UVs[0].Y) / 2.f + UVs[0].Y;
		UVs[0].Y = Center - ((Center - UVs[0].Y) * State->UvScale.Y);
		UVs[2].Y = Center - ((Center - UVs[2].Y) * State->UvScale.Y);
		Center = (UVs[3].Y - UVs[1].Y) / 2.f + UVs[1].Y;
		UVs[1].Y = Center - ((Center - UVs[1].Y) * State->UvScale.Y);
		UVs[3].Y = Center - ((Center - UVs[3].Y) * State->UvScale.Y);
	}

	// イメージ反転
	if(State->ImageFlipH)
	{
		FVector2D tmp;
		tmp = UVs[0];
		UVs[0] = UVs[1];
		UVs[1] = tmp;
		tmp = UVs[2];
		UVs[2] = UVs[3];
		UVs[3] = tmp;
	}
	if(State->ImageFlipV)
	{
		FVector2D tmp;
		tmp = UVs[0];
		UVs[0] = UVs[2];
		UVs[2] = tmp;
		tmp = UVs[1];
		UVs[1] = UVs[3];
		UVs[3] = tmp;
	}

	// 頂点カラー
	FColor VertexColors[4];
	float ColorBlendRate[4];
	if(State->IsColorBlend)
	{
		if(State->ColorValue.Target == SsColorBlendTarget::Whole)
		{
			const FSsColorBlendValue& cbv = State->ColorValue.Color;
			VertexColors[0].R = cbv.Rgba.R;
			VertexColors[0].G = cbv.Rgba.G;
			VertexColors[0].B = cbv.Rgba.B;
			VertexColors[0].A = (uint8)(cbv.Rgba.A * State->Alpha);
			ColorBlendRate[0] = cbv.Rate;

			for(int32 i = 1; i < 4; ++i)
			{
				VertexColors[i] = VertexColors[0];
				ColorBlendRate[i] = cbv.Rate;
			}
		}
		else
		{
			for(int32 i = 0; i < 4; ++i)
			{
				const FSsColorBlendValue& cbv = State->ColorValue.Colors[i];
				VertexColors[i].R = cbv.Rgba.R;
				VertexColors[i].G = cbv.Rgba.G;
				VertexColors[i].B = cbv.Rgba.B;
				VertexColors[i].A = (uint8)(cbv.Rgba.A * State->Alpha);
				ColorBlendRate[i] = cbv.Rate;
			}
		}
	}
	else
	{
		const FSsColorBlendValue& cbv = State->ColorValue.Color;
		for(int32 i = 0; i < 4; ++i)
		{
			VertexColors[i] = FColor(255, 255, 255, (uint8)(255 * State->Alpha));
			ColorBlendRate[i] = 1.f;
		}
	}

	OutRenderPart.PartIndex = State->Index;
	OutRenderPart.Texture = State->CellValue.Texture;
	OutRenderPart.ColorBlendType = State->ColorValue.BlendType;
	OutRenderPart.AlphaBlendType = State->AlphaBlendType;
	for(int32 i = 0; i < 4; ++i)
	{
		OutRenderPart.Vertices[i].Position = FVector2D(Vertices2D[i].X/CurAnimeCanvasSize.X, Vertices2D[i].Y/CurAnimeCanvasSize.Y);
		OutRenderPart.Vertices[i].TexCoord = UVs[i];
		OutRenderPart.Vertices[i].Color = VertexColors[i];
		OutRenderPart.Vertices[i].ColorBlendRate = ColorBlendRate[i];
	}
	return true;
}
Exemple #10
0
float4x4 Frustum::ViewProjMatrix() const
{
	return ProjectionMatrix() * ViewMatrix();
}
/*  Method
    *@brief: This method recalculate View Matrix
    *@param: None
    *@retval: None
    */
void GCamera::CalculateView()
{
    m_ViewMatrix = ViewMatrix(m_xAxis, m_yAxis, m_zAxis, m_Position);
}
Exemple #12
0
void GlobalMatrices::UpdateShader()
{
	ModelMatrix()->UpdateShader("modelMat");
	ViewMatrix()->UpdateShader("viewMat");
	ProjectionMatrix()->UpdateShader("projMat");
}
Exemple #13
0
bool ZCamera::CheckCollisionWall(float &fRealDist, rvector& pos, rvector& dir)
{
	RBSPPICKINFO bpi;
	float fNearZ = DEFAULT_NEAR_Z;
	rvector pos2 = pos;							// camera pos
	rvector tarpos = pos2 + (dir * fNearZ);		// near pos

	rvector up2, right2;
	up2 = rvector(0.0f, 0.0f, 1.0f);
	right2 = Normalized(CrossProduct(dir, up2));

	up2 = Normalized(CrossProduct(right2, dir));
	right2 = Normalized(CrossProduct(dir, up2));

	float fov = GetFOV();
	float e = 1 / (tanf(fov / 2));
	float fAspect = (float)RGetScreenWidth() / (float)RGetScreenHeight();
	float fPV = (fAspect * fNearZ / e);
	float fPH = (fNearZ / e);

	bool bCollisionWall = false;

	pos2 = pos;
	rvector tar = tarpos + (up2 * fPV);
	rvector dir2;
	dir2 = tar - pos2;
	Normalize(dir2);
	// NOTE: This was using dir as at??? Figure out why
	auto matView = ViewMatrix(pos2, Normalized(dir - pos2), up2);

	if (ZGetGame()->GetWorld()->GetBsp()->Pick(pos2, dir2, &bpi))
	{
		if (Magnitude(tar - bpi.PickPos) < Magnitude(tar - pos2))
		{
			rvector v1, v2, v3;

			v1 = bpi.PickPos;
			v3 = tar;

			if (ZGetGame()->GetWorld()->GetBsp()->Pick(tarpos, up2, &bpi))
			{
				v2 = bpi.PickPos;

				float fD = Magnitude(tarpos - v2);
				if (fD < fPH)
				{
					rvector vv1 = v1 - v2, vv2 = v2 - v3;
					D3DXVECTOR4 rV4;
					vv1 = Transform(vv1, matView);
					v2 = Transform(vv2, matView);

					float fAng = GetAngleOfVectors(vv1, vv2);
					if (fAng < 0.0f) fAng = -fAng;

					if (fAng < PI_FLOAT)
					{
						bCollisionWall = true;

						float fX = fPV - fD;
						float fY = fX * tanf(fAng);

						float fMyRealDist = fRealDist - fY;
						fRealDist = min(fMyRealDist, fRealDist);
					}
				}
			}
		}
	}

	pos2 = pos;
	tar = tarpos + (right2 * fPH);
	dir2 = Normalized(tar - pos2);

	if (ZGetGame()->GetWorld()->GetBsp()->Pick(pos2, dir2, &bpi))
	{
		if (Magnitude(tar - bpi.PickPos) < Magnitude(tar - pos2))
		{
			rvector v1, v2, v3;

			v1 = bpi.PickPos;
			v3 = tar;

			if (ZGetGame()->GetWorld()->GetBsp()->Pick(tarpos, right2, &bpi))
			{
				v2 = bpi.PickPos;

				float fD = Magnitude(tarpos - v2);
				if (fD < fPH)
				{
					rvector vv1 = v1 - v2, vv2 = v2 - v3;
					float fAng = GetAngleOfVectors(vv1, vv2);
					if (fAng < 0.0f) fAng = -fAng;

					if (fAng < (PI_FLOAT / 2))
					{
						bCollisionWall = true;

						float fX = fPH - fD;
						float fY = fX * tanf(fAng);

						float fMyRealDist = fRealDist - fY;
						fRealDist = min(fMyRealDist, fRealDist);
					}
				}
			}
		}
	}

	pos2 = pos;
	tar = tarpos - (up2 * fPV);
	dir2 = Normalized(tar - pos2);
	matView = ViewMatrix(pos2, Normalized(dir2 - pos2), up2);

	if (ZGetGame()->GetWorld()->GetBsp()->Pick(pos2, dir2, &bpi))
	{
		if (Magnitude(tar - bpi.PickPos) < Magnitude(tar - pos2))
		{
			rvector v1, v2, v3;

			v1 = bpi.PickPos;
			v3 = tar;

			if (ZGetGame()->GetWorld()->GetBsp()->Pick(tarpos, -up2, &bpi))
			{
				v2 = bpi.PickPos;

				float fD = Magnitude(tarpos - v2);
				if (fD < fPH)
				{
					bCollisionWall = true;

					rvector vv1 = v1 - v2, vv2 = v2 - v3;
					vv1 = Transform(vv1, matView);
					vv2 = Transform(vv2, matView);

					float fAng = GetAngleOfVectors(vv1, vv2);
					if (fAng < 0.0f) fAng = -fAng;

					if (fAng < (PI_FLOAT / 2))
					{
						float fX = fPV - fD;
						float fY = fX * tanf(fAng);

						float fMyRealDist = fRealDist - fY;
						fRealDist = min(fMyRealDist, fRealDist);
					}
				}
			}
		}
	}

	pos2 = pos;
	tar = tarpos - (right2 * fPH);
	dir2 = Normalized(tar - pos2);

	if (ZGetGame()->GetWorld()->GetBsp()->Pick(pos2, dir2, &bpi))
	{
		if (Magnitude(tar - bpi.PickPos) < Magnitude(tar - pos2))
		{
			rvector v1, v2, v3;

			v1 = bpi.PickPos;
			v3 = tar;

			if (ZGetGame()->GetWorld()->GetBsp()->Pick(tarpos, -right2, &bpi))
			{
				v2 = bpi.PickPos;

				float fD = Magnitude(tarpos - v2);
				if (fD < fPH)
				{
					bCollisionWall = true;

					rvector vv1 = v1 - v2, vv2 = v2 - v3;
					float fAng = GetAngleOfVectors(vv1, vv2);
					if (fAng < 0.0f) fAng = -fAng;

					if (fAng < (PI_FLOAT / 2))
					{
						float fX = fPH - fD;
						float fY = fX * tanf(fAng);

						float fMyRealDist = fRealDist - fY;
						fRealDist = min(fMyRealDist, fRealDist);
					}
				}
			}
		}
	}

	if (fRealDist < 0) fRealDist = 0.0f;

	return bCollisionWall;
}