コード例 #1
0
void Camera::MenuCameraRotation()
{
	// Create rotation matrix
	m_menuRotation += (float)GLOBAL::GetInstance().GetDeltaTime() / 16.0f;
	if (m_menuRotation > 6.28f)
	{
		m_menuRotation = 0.0f;
	}
	DirectX::XMMATRIX rotation = DirectX::XMMatrixRotationY(m_menuRotation);

	// Lock shadows in center.
	DirectX::XMFLOAT3 shadowPosition = GetPosition();
	DirectX::XMStoreFloat3(&shadowPosition, DirectX::XMVector3TransformCoord(DirectX::XMLoadFloat3(&shadowPosition), rotation));
	shadowPosition.x *= 0.8f;
	DirectX::XMFLOAT3 position = DirectX::XMFLOAT3(25.0f + shadowPosition.x, 100.0f, 50.0f);

	UpdatePosition(position);
	UpdateTarget(DirectX::XMFLOAT3(shadowPosition.x, 5.0f, 0.0f));
	UpdateViewMatrix();
	UpdateProjectionMatrix(true);
	GraphicsEngine::SetLightViewAndProjection(GetViewMatrix(), GetProjectionMatrix());

	// Lock camera in center and rotate camera.	
	position = DirectX::XMFLOAT3(0.0f, 40.0f, -24.0f);

	UpdatePosition(position);
	UpdateTarget(DirectX::XMFLOAT3(0.0f, 7.5f, 0.0f));
	UpdateViewMatrix();
	UpdateProjectionMatrix(false);

	DirectX::XMStoreFloat4x4(&m_viewMatrix, DirectX::XMMatrixMultiply(rotation, DirectX::XMLoadFloat4x4(&m_viewMatrix)));

	GraphicsEngine::SetViewAndProjection(GetViewMatrix(), GetProjectionMatrix());
}
コード例 #2
0
void Camera::FollowCharacter(DirectX::XMFLOAT3 p_playerPos)
{
	// Lock shadows on the player.
	DirectX::XMFLOAT3 playerPosition = p_playerPos;
	DirectX::XMFLOAT3 position = DirectX::XMFLOAT3(playerPosition.x + 25.0f, playerPosition.y + 100.0f, playerPosition.z + 50.0f);
	DirectX::XMFLOAT3 target = playerPosition;

	UpdatePosition(position);
	UpdateTarget(target);
	UpdateViewMatrix();
	UpdateProjectionMatrix(true);
	GraphicsEngine::SetLightViewAndProjection(GetViewMatrix(), GetProjectionMatrix());

	// Visibility view projection..
	playerPosition = p_playerPos;
	position = DirectX::XMFLOAT3(playerPosition.x, playerPosition.y + 30.0f, playerPosition.z);
	target = playerPosition;

	UpdatePosition(position);
	UpdateTarget(target);
	UpdateViewMatrix();
	GraphicsEngine::SetViewPolygonMatrix(GetViewMatrix());
	

	// Lock camera on the player.
	playerPosition = p_playerPos;
	position = DirectX::XMFLOAT3(playerPosition.x, playerPosition.y + 30.0f, playerPosition.z - 15.0f);
	target = playerPosition;

	SetOutliningRayPosition(position);
	SetOutliningRayTarget(target);

	if (GLOBAL::GetInstance().CAMERA_MOVING)
	{
		MovingCamera(playerPosition);
	}
	else
	{
		UpdatePosition(position);
		UpdateTarget(target);
		UpdateViewMatrix();
		UpdateProjectionMatrix(false);
		GraphicsEngine::SetViewAndProjection(GetViewMatrix(), GetProjectionMatrix());
		m_oldPosition = position;
	}	

	GraphicsEngine::UpdateVisibilityPolygon(Point(playerPosition.x, playerPosition.z), (float)GLOBAL::GetInstance().GetDeltaTime());
}
コード例 #3
0
ファイル: Camera.cpp プロジェクト: simplerr/Devbox
	//! Constructor.
	Camera::Camera()
	{
		// Set the sensitivity and speed
		SetLookSensitivity(2.0f);
		SetMovementSpeed(0.6f);
		SetLocked(false);

		// Default position and target
		mPosition	= XMFLOAT3(-30, 60, 0);
		mTarget		= XMFLOAT3(0.0f, 0.0f, 0.0f);
		mUp			= XMFLOAT3(0.0f, 1.0f, 0.0f);		// Weird up vector

		// Calculate the new direction.
		UpdatePitchYaw();

		// Build the projection matrix
		XMMATRIX proj = XMMatrixPerspectiveFovLH(XM_PI * 0.25, (float)GlobalApp::GetClientWidth()/(float)GlobalApp::GetClientHeight(), 1.0f, 1000.0f);
		XMStoreFloat4x4(&mProj, proj);

		UpdateViewMatrix();
		
		// Build the camera frustum.
		mFrustum.ConstructFromProjection(GetProjectionMatrix());
		//XNA::ComputeFrustumFromProjection(&mFrustum, &XMLoadFloat4x4(&GetProjectionMatrix()));
	}
コード例 #4
0
ファイル: rViewport.cpp プロジェクト: aedotcom/recondite
int rViewport::GetSelectionRay(const rPoint& pos , rRay3& selectionRay) const{
    rMatrix4 projection, view;
    GetProjectionMatrix(projection);
    GetViewMatrix(view);
    
    rVector3 nearPoint , farPoint;
    int result;
    

	rVector3 source((float)pos.x , m_rect.height - (float)pos.y , 0.0f);
    result = rMatrixUtil::Unproject(source, view, projection, m_rect, nearPoint);
	
	if (result == false)
		return false;

    source.z = 1.0f;
    result = rMatrixUtil::Unproject(source, view, projection, m_rect, farPoint);
	
	if (result == false)
		return false;

    rVector3 direction = farPoint - nearPoint;
	direction.Normalize();

	selectionRay.Set(nearPoint, direction);
	return true;
}
コード例 #5
0
ファイル: view.cpp プロジェクト: Johnicholas/EldritchCopy
void View::ApplyToRenderer( IRenderer& Renderer ) const
{
	XTRACE_FUNCTION;

	Renderer.SetViewMatrix( GetViewMatrix() );
	Renderer.SetProjectionMatrix( GetProjectionMatrix() );
}
コード例 #6
0
ファイル: testHdStBasicDrawing.cpp プロジェクト: lvxejay/USD
void
My_TestGLDrawing::DrawTest()
{
    GLfloat clearColor[4] = { 0.1f, 0.1f, 0.1f, 1.0f };
    glClearBufferfv(GL_COLOR, 0, clearColor);

    GLfloat clearDepth[1] = { 1.0f };
    glClearBufferfv(GL_DEPTH, 0, clearDepth);

    int width = GetWidth(), height = GetHeight();
    GfMatrix4d viewMatrix = GetViewMatrix();
    GfMatrix4d projMatrix = GetProjectionMatrix();

    _driver->SetCullStyle(_cullStyle);

    // camera
    _driver->SetCamera(viewMatrix, projMatrix, GfVec4d(0, 0, width, height));

    glViewport(0, 0, width, height);

    glEnable(GL_DEPTH_TEST);

    glBindVertexArray(vao);

    _driver->Draw();

    glBindVertexArray(0);
}
コード例 #7
0
ファイル: view.cpp プロジェクト: Johnicholas/EldritchCopy
Vector4 View::Project( const Vector& Location ) const
{
	const Matrix	ViewProjectionMatrix	= GetViewMatrix() * GetProjectionMatrix();
	const Vector4	ProjectedLocation		= Vector4( Location ) * ViewProjectionMatrix;

	return ProjectedLocation;
}
コード例 #8
0
void RenderPipe_depth_opengl::render( GLuint target )
{
	glDepthMask(GL_FALSE);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, target);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

	glUseProgram(m_pipeProgramID);

	GLuint reg = glGetUniformLocation(m_pipeProgramID, "u_image");
	glUniform1i(reg, 0);
	reg = glGetUniformLocation(m_pipeProgramID, "u_blurredImage");
	glUniform1i(reg, 1);
	reg = glGetUniformLocation(m_pipeProgramID, "u_zBuffer");
	glUniform1i(reg, 2);

	CMatrix inverProjMat = GetProjectionMatrix();
	inverProjMat.Invert();

	m_zInv = inverProjMat.GetColumn(3);	// only need to calculate z value, so only 4th column is needed.

	m_depthOfField = GetDepthOfFieldFactors();

	reg = glGetUniformLocation(m_pipeProgramID, "u_depthOfField");
	if (reg >= 0)
		glUniform4fv(reg, 1, (float *)&m_depthOfField);
	if (reg >= 0)
		reg = glGetUniformLocation(m_pipeProgramID, "u_zInv");
	glUniform4fv(reg, 1, (float *)&m_zInv);


	glActiveTexture(GL_TEXTURE0_ARB);

	glEnable(GL_TEXTURE_2D);
	glActiveTexture(GL_TEXTURE0_ARB);
	glBindTexture(GL_TEXTURE_2D, m_image);

	glActiveTexture(GL_TEXTURE1_ARB);
	glBindTexture(GL_TEXTURE_2D, m_blurredImage);

	glActiveTexture(GL_TEXTURE2_ARB);
	glBindTexture(GL_TEXTURE_2D, m_depthTexture);
	glActiveTexture(GL_TEXTURE0_ARB);

	renderScreenQuad();

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	glDepthMask(GL_TRUE);
}
コード例 #9
0
void Camera::ResetCameraToLight()
{
	// Reset camera.
	DirectX::XMFLOAT3 target = DirectX::XMFLOAT3(0, 0, 0);
	DirectX::XMFLOAT3 position = DirectX::XMFLOAT3(25.0f, 100.0f, 50.0f);

	UpdatePosition(position);
	UpdateTarget(target);

	m_upVector = DirectX::XMFLOAT3(-25.0f, 100.0f, -50.0f);
	DirectX::XMStoreFloat3(&m_upVector, DirectX::XMVector3Normalize(DirectX::XMLoadFloat3(&m_upVector)));

	m_look = DirectX::XMFLOAT3(-25.0f, -100.0f, -50.0f);
	DirectX::XMStoreFloat3(&m_look, DirectX::XMVector3Normalize(DirectX::XMLoadFloat3(&m_look)));

	m_right = DirectX::XMFLOAT3(25.0f, 0.0f, -50.0f);
	DirectX::XMStoreFloat3(&m_right, DirectX::XMVector3Normalize(DirectX::XMLoadFloat3(&m_right)));

	// Projection data.
	float aspectRatio = (float)GLOBAL::GetInstance().MAX_SCREEN_WIDTH / (float)GLOBAL::GetInstance().MAX_SCREEN_HEIGHT;
	UpdateAspectRatio(aspectRatio);
	UpdateFieldOfView(3.141592f * 0.25f);
	UpdateClippingPlanes(0.1f, 1000.0f);
	UpdateViewMatrix();
	UpdateProjectionMatrix(true);

	GraphicsEngine::SetLightViewAndProjection(GetViewMatrix(), GetProjectionMatrix());
}
コード例 #10
0
//src:要被轉換的圖 dst:輸出圖//coord1:轉換後之點//coord2:轉換前之點//T:Acceptable range of threshold after transforming
void   Morphining::DoProjection(IplImage *src,IplImage *dst,vector<Coordinate> adjusted,vector<Coordinate> adjust,double T,bool debug)
{
	CvMat* Matrix = cvCreateMat(3,3,CV_32FC1);
	//rearrage coord to clockwise bcs we need to cut the polygon from image
	cvZero(Matrix);

	Coordinate temp;
	temp = adjusted[3];
	adjusted[3] = adjusted[2];
	adjusted[2] = temp;
	temp = adjust[3];
	adjust[3] = adjust[2];
	adjust[2] = temp;
	
	Matrix = GetProjectionMatrix(adjust,adjusted,debug);
	
	/*PrintMatrix(Matrix,3,3);*/

	//if(SSD(adjusted,adjust,Matrix,T))
	//{ 
		Vertex = new Coordinate [m_numFeature];
		for(int i = 0;i < m_numFeature;i++)Vertex[i] = adjusted[i];
		ProjectionTrsform(src,dst,Matrix,debug);
	/*}*/

	cvReleaseMat(&Matrix);
}
コード例 #11
0
//TODO: need refine!!!
void ctLineBorders::Draw()
{
    //if(!rectDotIndexes) return;
    //glDisable(GL_DEPTH_TEST);
    GetOpenGLContext()->functions()->glBindBuffer(GL_ARRAY_BUFFER, meshVBO);

    if (posAtribLoc != -1)
    {
        GetOpenGLContext()->functions()->glVertexAttribPointer(posAtribLoc, 3, GL_FLOAT, GL_FALSE,
            (3 * sizeof(GLfloat)), (const GLvoid*)0);
        GetOpenGLContext()->functions()->glEnableVertexAttribArray(posAtribLoc);
    }
    else
    {qDebug()<<"isShit pos!!!";}

    m_currentShader->bind();

    m_currentShader->setUniformValue(matrixUniform, GetProjectionMatrix().GetMatrix());
    m_currentShader->setUniformValue(materialUniform, GetMaterial()->GetRGBA());
    m_currentShader->setUniformValue(transformMatrixUniform, GetTransform()->GetGlobalTransformMatrix().GetMatrix());

    glDrawElements(GL_LINE_LOOP, m_dots.count(), GL_UNSIGNED_SHORT, planeIndexes);

    GetOpenGLContext()->functions()->glBindBuffer(GL_ARRAY_BUFFER, 0);
    m_currentShader->release();
}
コード例 #12
0
	void AsWindow::RenderView(double pPartialTickTime)
	{
		//make sure the camera reference is not null
		if (mCamera == 0)
			return;

		mCamera->RenderView(pPartialTickTime, GetProjectionMatrix());
	}
コード例 #13
0
	float AbstractViewer::ProjectDepth(float depth)
	{
		const Matrix4f& projectionMatrix = GetProjectionMatrix();
		float a = projectionMatrix(2, 2);
		float b = projectionMatrix(2, 3);

		return (0.5f * (-a * depth + b) / depth + 0.5f);
	}
コード例 #14
0
ファイル: Camera.cpp プロジェクト: pauljnixon/Graphics
Matrix Camera::GetFilmToWorldMatrix() {
    GetProjectionMatrix();
    //scaling.print();
    GetModelViewMatrix();
    //modelView.print();
    Matrix m = invert(scaling * modelView);
    //m.print();
    return m;
}
コード例 #15
0
void Camera::ToggleFullscreen(bool p_fullscreen)
{
	GLOBAL::GetInstance().SWITCHING_SCREEN_MODE = true;

	if (p_fullscreen)
	{
		// Go to fullscreen
		GLOBAL::GetInstance().CURRENT_SCREEN_WIDTH = GLOBAL::GetInstance().MAX_SCREEN_WIDTH;
		GLOBAL::GetInstance().CURRENT_SCREEN_HEIGHT = GLOBAL::GetInstance().MAX_SCREEN_HEIGHT;
		SetWindowPos(GraphicsEngine::GetWindowHandle(), HWND_TOP, 0, 0, GLOBAL::GetInstance().CURRENT_SCREEN_WIDTH, GLOBAL::GetInstance().CURRENT_SCREEN_HEIGHT, SWP_SHOWWINDOW);
		//GraphicsEngine::GetInstance()->ToggleFullscreen(true);

		// Update aspect ratio.
		float aspectRatio = (float)GLOBAL::GetInstance().CURRENT_SCREEN_WIDTH / (float)GLOBAL::GetInstance().CURRENT_SCREEN_HEIGHT;
		UpdateAspectRatio(aspectRatio);
		UpdateProjectionMatrix(false);
		GraphicsEngine::SetViewAndProjection(GetViewMatrix(), GetProjectionMatrix());

		// Set both window positions.
		HWND console = GetConsoleWindow();
		MoveWindow(console, GLOBAL::GetInstance().CURRENT_SCREEN_WIDTH, 0, 670, 1000, true);
	}

	else
	{
		// Go to windowed mode.
		GLOBAL::GetInstance().CURRENT_SCREEN_WIDTH = GLOBAL::GetInstance().MIN_SCREEN_WIDTH;
		GLOBAL::GetInstance().CURRENT_SCREEN_HEIGHT = GLOBAL::GetInstance().MIN_SCREEN_HEIGHT;
		//GraphicsEngine::GetInstance()->ToggleFullscreen(false);

		// Update aspect ratio.
		float aspectRatio = (float)GLOBAL::GetInstance().CURRENT_SCREEN_WIDTH / (float)GLOBAL::GetInstance().CURRENT_SCREEN_HEIGHT;
		UpdateAspectRatio(aspectRatio);
		UpdateProjectionMatrix(false);
		GraphicsEngine::SetViewAndProjection(GetViewMatrix(), GetProjectionMatrix());

		// Set both window positions.
		HWND console = GetConsoleWindow();
		MoveWindow(console, GLOBAL::GetInstance().CURRENT_SCREEN_WIDTH, 0, 670, 1000, true);
		SetWindowPos(GraphicsEngine::GetWindowHandle(), HWND_TOP, 0, 0, GLOBAL::GetInstance().CURRENT_SCREEN_WIDTH, GLOBAL::GetInstance().CURRENT_SCREEN_HEIGHT, SWP_SHOWWINDOW);
	}

	GLOBAL::GetInstance().SWITCHING_SCREEN_MODE = false;
}
コード例 #16
0
ファイル: rViewport.cpp プロジェクト: aedotcom/recondite
void rViewport::GetViewProjectionMatrix(rMatrix4& matrix) const{
	rMatrix4 projection, view;

	if (m_camera){
		GetProjectionMatrix(projection);
		GetViewMatrix(view);
	}

	matrix = projection * view;
}
コード例 #17
0
ファイル: Camera.cpp プロジェクト: sephirot47/Bang
Vector2 Camera::WorldToScreenNDCPoint(const Vector3 &position)
{
    Matrix4 p, v;
    GetProjectionMatrix(&p);
    GetViewMatrix(&v);
    Vector4 v4 = p * v * Vector4(position, 1);
    v4 /= v4.w;

    return Vector2(v4.xy());
}
コード例 #18
0
glm::mat4 Camera::GetViewProjectionMatrix() const
{
	// @TODO 1 - Calculate View Projection Matrix
	//           The projection matrix is hardcoded below
	//           The view matrix is set in the derived camera classes.
	//glm::mat4 viewProjection(15.0f); // identity, you need to change this

	//we need 
	return GetProjectionMatrix() * GetViewMatrix();
}
コード例 #19
0
ファイル: FWCamera.cpp プロジェクト: gunsafighter/core3d
	void FWCamera::BuildFrustum()
	{
		// COMMENT : Calculate frustum planes
		Matrix4x4 kMatFrustum = GetViewMatrix() * GetProjectionMatrix();

		// COMMENT : Near
		m_akFrustum[0] = Plane(
			kMatFrustum._14 + kMatFrustum._13, 
			kMatFrustum._24 + kMatFrustum._23, 
			kMatFrustum._34 + kMatFrustum._33, 
			kMatFrustum._44 + kMatFrustum._43);

		// COMMENT : Far
		m_akFrustum[1] = Plane(
			kMatFrustum._14 - kMatFrustum._13, 
			kMatFrustum._24 - kMatFrustum._23, 
			kMatFrustum._34 - kMatFrustum._33, 
			kMatFrustum._44 - kMatFrustum._43);

		// COMMENT : Left
		m_akFrustum[2] = Plane(
			kMatFrustum._14 + kMatFrustum._11, 
			kMatFrustum._24 + kMatFrustum._21, 
			kMatFrustum._34 + kMatFrustum._31, 
			kMatFrustum._44 + kMatFrustum._41);

		// COMMENT : Right
		m_akFrustum[3] = Plane(
			kMatFrustum._14 - kMatFrustum._11, 
			kMatFrustum._24 - kMatFrustum._21, 
			kMatFrustum._34 - kMatFrustum._31, 
			kMatFrustum._44 - kMatFrustum._41);

		// COMMENT : Top
		m_akFrustum[4] = Plane(
			kMatFrustum._14 - kMatFrustum._12, 
			kMatFrustum._24 - kMatFrustum._22, 
			kMatFrustum._34 - kMatFrustum._32, 
			kMatFrustum._44 - kMatFrustum._42);

		// COMMENT : Bottom
		m_akFrustum[5] = Plane(
			kMatFrustum._14 + kMatFrustum._12, 
			kMatFrustum._24 + kMatFrustum._22, 
			kMatFrustum._34 + kMatFrustum._32, 
			kMatFrustum._44 + kMatFrustum._42);

		m_akFrustum[0].kNormal.Normalize();
		m_akFrustum[1].kNormal.Normalize();
		m_akFrustum[2].kNormal.Normalize();
		m_akFrustum[3].kNormal.Normalize();
		m_akFrustum[4].kNormal.Normalize();
		m_akFrustum[5].kNormal.Normalize();
	}
コード例 #20
0
ファイル: Camera.cpp プロジェクト: sephirot47/Bang
Vector3 Camera::ScreenNDCPointToWorld(const Vector2 &screenNDCPos, float zFromCamera)
{
    Matrix4 p, v;
    GetProjectionMatrix(&p);
    GetViewMatrix(&v);

    // Pass coordinates to clip space, to invert them using projInversed
    Vector4 clipCoords = Vector4(screenNDCPos, 1.0, 1.0) * zFromCamera;
    Vector4 res4 = p.Inversed() * clipCoords;
    Vector3 res = res4.xyz();
    res = (v.Inversed() * Vector4(res, 1.0f)).xyz();
    return res;
}
コード例 #21
0
	const cMatrixf& cLight3DSpot::GetViewProjMatrix()
	{
		if(mlViewProjMatrixCount != GetTransformUpdateCount() || mbViewProjUpdated || mbProjectionUpdated)
		{
			m_mtxViewProj = cMath::MatrixMul(GetProjectionMatrix(),GetViewMatrix());
			m_mtxViewProj = cMath::MatrixMul(g_mtxTextureUnitFix, m_mtxViewProj);

			mlViewProjMatrixCount = GetTransformUpdateCount();
			mbViewProjUpdated = false;
		}

		return m_mtxViewProj;
	}
コード例 #22
0
void Camera::MovingCamera(DirectX::XMFLOAT3 p_pos)
{
	float moveX, moveY, centerX, centerY, posX, posY;
	centerX = GLOBAL::GetInstance().CURRENT_SCREEN_WIDTH * 0.5f;
	centerY = GLOBAL::GetInstance().CURRENT_SCREEN_HEIGHT * 0.5f;
	posX = InputManager::GetInstance()->GetMousePositionX() - centerX;
	posY = InputManager::GetInstance()->GetMousePositionY() - centerY;
	float procX = posX / 440;
	float procY = posY / 352; // 512 *0,68 //0.68 = 440/640;
	if (procX > 1.0)
		procX = 1.0;
	if (procX < -1.0)
		procX = -1.0;
	if (procY > 1.0)
		procY = 1.0;
	if (procY < -1.0)
		procY = -1.0;

	moveX = 8 * procX;
	moveY = 8 * procY;

	DirectX::XMFLOAT3 position, target, finalPos;
	DirectX::XMFLOAT3 playerPosition = p_pos;
	position = DirectX::XMFLOAT3(playerPosition.x + moveX, playerPosition.y + 30.0f, playerPosition.z - moveY - 15.0f);
	target = DirectX::XMFLOAT3(playerPosition.x + moveX, 0, playerPosition.z - moveY);

	DirectX::XMStoreFloat3(&finalPos, SmoothStep(DirectX::XMLoadFloat3(&m_oldPosition), DirectX::XMLoadFloat3(&position), 0.25f));
	
	// Set max limits
	if (finalPos.x < -38)
		finalPos.x = -38;
	if (finalPos.x > 38)
		finalPos.x = 38;
	if (finalPos.z > 35)
		finalPos.z = 35;
	if (finalPos.z < -58)
		finalPos.z = -58;

	target = DirectX::XMFLOAT3(finalPos.x, 0, finalPos.z + 15.0f);

	UpdatePosition(finalPos);
	UpdateTarget(target);
	UpdateViewMatrix();
	UpdateProjectionMatrix(false);
	GraphicsEngine::SetViewAndProjection(GetViewMatrix(), GetProjectionMatrix());

	m_oldPosition = finalPos;

	SetOutliningRayPosition(finalPos);
	SetOutliningRayTarget(playerPosition);
};
コード例 #23
0
	cFrustum* cLight3DSpot::GetFrustum()
	{
		if(mlFrustumMatrixCount != GetTransformUpdateCount() || mbFrustumUpdated || mbProjectionUpdated)
		{
			mpFrustum->SetViewProjMatrix(	GetProjectionMatrix(),
											GetViewMatrix(),
											mfFarAttenuation,mfNearClipPlane,
											mfFOV,mfAspect,GetWorldPosition(),false);
			mbFrustumUpdated = false;
			mlFrustumMatrixCount = GetTransformUpdateCount();
		}

		return mpFrustum;
	}
コード例 #24
0
	Vector3f AbstractViewer::Project(const Nz::Vector3f& worldPosition) const
	{
		Vector4f pos4D(worldPosition, 1.f);
		pos4D = GetViewMatrix() * pos4D;
		pos4D = GetProjectionMatrix() * pos4D;
		pos4D /= pos4D.w;

		Rectf viewport = Rectf(GetViewport());

		Nz::Vector3f screenPosition(pos4D.x * 0.5f + 0.5f, -pos4D.y * 0.5f + 0.5f, pos4D.z * 0.5f + 0.5f);
		screenPosition.x = screenPosition.x * viewport.width + viewport.x;
		screenPosition.y = screenPosition.y * viewport.height + viewport.y;

		return screenPosition;
	}
コード例 #25
0
ファイル: CurrentState.cpp プロジェクト: Prnbs/ShadomMap
Matrix CurrentState::GetShadowBiasMatrix(Matrix ModelMatrix){
  /*  if(shadowMat)
        return ShadowBiasMatrix;
    else{*/
        ShadowBiasMatrix = IDENTITY_MATRIX;
		shadowMat = true;
		Matrix MV = MultiplyMatrices(&(GetShadowViewMatrix()), &ModelMatrix);
		Matrix MVP =  MultiplyMatrices(&(GetProjectionMatrix()), &MV);
        Matrix bias = IDENTITY_MATRIX;
        bias.m[0] = 0.5; bias.m[5] = 0.5; bias.m[10] = 0.5;
        bias.m[12] = 0.5; bias.m[13] = 0.5; bias.m[14] = 0.5;
		ShadowBiasMatrix = MultiplyMatrices(&ShadowBiasMatrix, &MVP);
		return ShadowBiasMatrix;
	//}
}
コード例 #26
0
void CMglMatrixManager::ConvertToScreenVector(D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pInVector)
{
	InitCheck();

	_D3DVIEWPORTx vp;
	vp.X = 0;
	vp.Y = 0;
	vp.Width = m_myudg->GetWidth();
	vp.Height = m_myudg->GetHeight();
	vp.MinZ = 0.0f;
	vp.MaxZ = 1.0f;
	
	D3DXVec3Project(pOut, pInVector, &vp,
		&(GetProjectionMatrix()),
		&(GetViewMatrix()),
		+&(m_pWorldMgr->GetMatrix()));
}
コード例 #27
0
ファイル: camera.cpp プロジェクト: Alriightyman/RTS
void CAMERA::Update(MOUSE &mouse, float timeDelta)
{
	//Restrict focus movment to the xz-plane
	m_right.y = m_look.y = 0.0f;
	D3DXVec3Normalize(&m_look, &m_look);
	D3DXVec3Normalize(&m_right, &m_right);

	//Move Focus (i.e. Scroll)
	if(mouse.x < mouse.m_viewport.left + 10)	Scroll(-m_right * timeDelta * 30.0f);
	if(mouse.x > mouse.m_viewport.right - 10)	Scroll(m_right * timeDelta * 30.0f);
	if(mouse.y < mouse.m_viewport.top + 10)		Scroll(m_look * timeDelta * 30.0f);
	if(mouse.y > mouse.m_viewport.bottom - 10)	Scroll(-m_look * timeDelta * 30.0f);

	//Move Camera (i.e. Change Angle)
	if(KEYDOWN(VK_LEFT))Yaw(-timeDelta);
	if(KEYDOWN(VK_RIGHT))Yaw(timeDelta);
	if(KEYDOWN(VK_UP))Pitch(timeDelta);
	if(KEYDOWN(VK_DOWN))Pitch(-timeDelta);
	
	//Zoom (i.e. change fov)
	if(KEYDOWN(VK_ADD))Zoom(-timeDelta);
	if(KEYDOWN(VK_SUBTRACT))Zoom(timeDelta);

	//Change m_radius
	if(mouse.WheelUp())  ChangeRadius(-1.0f);
	if(mouse.WheelDown())ChangeRadius(1.0f);

	//Calculate Eye Position
	float sideRadius = m_radius * cos(m_beta);
	float height = m_radius * sin(m_beta);

	m_eye = D3DXVECTOR3(m_focus.x + sideRadius * cos(m_alpha),
					  m_focus.y + height, 
					  m_focus.z + sideRadius * sin(m_alpha));

	if(m_pDevice != NULL)
	{
		D3DXMATRIX view = GetViewMatrix();
		D3DXMATRIX projection = GetProjectionMatrix();

		m_pDevice->SetTransform(D3DTS_VIEW, &view);
		m_pDevice->SetTransform(D3DTS_PROJECTION, &projection);

		CalculateFrustum(view, projection);
	}	
}
コード例 #28
0
dVector dSceneRender::ScreenToGlobal (const dVector& screen) const
{
	dFloat width = dFloat  (GetViewPortWidth());
	dFloat height = dFloat (GetViewPortHeight());
	dVector p0 (2.0f * screen.m_x / width - 1.0f, 2.0f * (height - screen.m_y) / height - 1.0f, 2.0f * screen.m_z - 1.0f, 1.0f);

	dMatrix modelview (GetModelViewMatrix());
	dMatrix projection (GetProjectionMatrix());
	dMatrix matrix (modelview * projection);
	dMatrix invMatrix (matrix.Inverse4x4());
	dVector p1 (invMatrix.RotateVector4x4(p0));

	p1.m_w = 1.0f / p1.m_w;
	p1 = p1.Scale(p1.m_w);
	p1.m_w = 1.0f;
	return p1;
}
コード例 #29
0
ファイル: ysviewcontrol.cpp プロジェクト: Jenny19880324/MCG03
void Ys3DDrawingEnvironment::TransformScreenCoordTo3DLine(YsVec3 &org,YsVec3 &vec,double sx,double sy) const
{
	if(YSTRUE==screenOriginIsTopLeft)
	{
		sy=(double)windowHeight-sy;
	}

	const YsMatrix4x4 &viewMat=GetViewMatrix();
	const YsMatrix4x4 &projMat=GetProjectionMatrix();
	const YsMatrix4x4 projViewMat=projMat*viewMat;

	const YsVec3 p1(sx,sy,-1.0),p2(sx,sy,1.0);
	YsTransformScreenCoordTo3DCoord(org,p1,viewport,projViewMat);
	YsTransformScreenCoordTo3DCoord(vec,p2,viewport,projViewMat);

	vec-=org;
	vec.Normalize();
}
コード例 #30
0
ファイル: Camera.cpp プロジェクト: simplerr/Devbox
	//! Updates the view matrix.
	void Camera::UpdateViewMatrix()
	{
		// Update the right vector.
		XMVECTOR up = XMLoadFloat3(&mUp);
		XMVECTOR dir = XMLoadFloat3(&GetDirection());
		XMVECTOR right = XMVector3Cross(up, dir);
		right = XMVector3Normalize(right);
		XMStoreFloat3(&mRight, right);

		// Update the view matrix
		XMVECTOR pos = XMLoadFloat3(&mPosition);
		XMVECTOR target = XMLoadFloat3(&mTarget);
		XMStoreFloat4x4(&mView, XMMatrixLookAtLH(pos, target, up));

		XMFLOAT4X4 viewProj;
		XMStoreFloat4x4(&viewProj, XMLoadFloat4x4(&GetViewMatrix()) * XMLoadFloat4x4(&GetProjectionMatrix()));
		mFrustum.BuildFromViewProjection(viewProj);
	}