예제 #1
0
void SceneGraphComponent::setSerializedState(GameState& state)
{
	int nodeFlags;
	if (state.readInt32(&nodeFlags))
		return;

	if (m_hordeID > 0) {
		h3dSetNodeFlags(m_hordeID, nodeFlags, true );
	}

	float read_transformation[16];
	for (int i = 0; i < 16; i++) {
		if (state.readFloat(&read_transformation[i]))
			return;
	}
	setTransformation(read_transformation);

	// set last transformation (i. e. one frame ago)
	for (int i = 0; i < 16; i++) {
		if (state.readFloat(&read_transformation[i]))
			return;
	}
	memcpy(m_net_lasttransformation, read_transformation, sizeof(float) * 16);

	// calculate trajectory
	Vec3f t, r, s, lt, lr, ls;

	Matrix4f(m_transformation).decompose(t, r, s);
	Matrix4f(m_net_lasttransformation).decompose(lt, lr, ls);

	if ((s != ls) || (r != lr) || (t != lt))
	{
		if ((t - lt).length() > m_net_maxTrajection) {
			m_net_traject_translation.x = 0;
			m_net_traject_translation.y = 0;
			m_net_traject_translation.z = 0;
			m_net_traject_rotation.x = 0;
			m_net_traject_rotation.y = 0;
			m_net_traject_rotation.z = 0;
			m_net_traject_scale.x = 0;
			m_net_traject_scale.y = 0;
			m_net_traject_scale.z = 0;
		} else {
			m_net_traject_translation = t - lt;
			m_net_traject_rotation = r - lr;
			m_net_traject_scale = s - ls;
		}
		m_net_applyTrajection = true;
	} else
		m_net_applyTrajection = false;

	float remotefps;

	if (state.readFloat(&remotefps))	// to be able to traject accordingly to remote speed (reduces entity "jumping")
		return;

	m_net_traject_speedup = remotefps / GameEngine::FPS();

	//printf("speedup = %f\n", m_net_traject_speedup);
}
예제 #2
0
void SceneGraphComponent::traject()
{
	// apply trajections
	if (m_net_applyTrajection) {

		// apply translation
		m_transformation[12] += m_net_traject_translation.x * m_net_traject_speedup;
		m_transformation[13] += m_net_traject_translation.y * m_net_traject_speedup;
		m_transformation[14] += m_net_traject_translation.z * m_net_traject_speedup;

		// apply rotation
		Matrix4f trans( Matrix4f(m_transformation) * 
			Matrix4f(Quaternion(
				m_net_traject_rotation.x * m_net_traject_speedup,
				m_net_traject_rotation.y * m_net_traject_speedup,
				m_net_traject_rotation.z * m_net_traject_speedup
			)) );
		memcpy( m_transformation, trans.x, sizeof( float ) * 16 );

		// TODO: apply scale

		sendTransformation();

		GameEvent event(GameEvent::E_SET_TRANSFORMATION, GameEventData(m_transformation, 16), this);
		m_owner->executeEvent(&event);
	}
}
예제 #3
0
void SceneGraphComponent::setScale(const Vec3f *scale)
{
	/*Vec3f tr,rotation,sc;
	Matrix4f(m_transformation).decompose(tr,rotation,sc);	
	
	Matrix4f trans = Matrix4f::ScaleMat( scale->x, scale->y, scale->z );
	trans = trans * Matrix4f(Quaternion(rotation.x, rotation.y, rotation.z));
	trans.translate(m_transformation[12], m_transformation[13], m_transformation[14]);
	
	GameEvent event(GameEvent::E_SET_TRANSFORMATION, GameEventData(trans.x, 16), 0);*/

	Vec3f tr,rotation,sc;
	Matrix4f(m_transformation).decompose(tr,rotation,sc);	
	
	Matrix4f trans = Matrix4f::ScaleMat( scale->x, scale->y, scale->z );
	trans = trans * Matrix4f(Quaternion(rotation.x, rotation.y, rotation.z));
	trans.translate(tr.x, tr.y, tr.z);
	
	GameEvent event(GameEvent::E_SET_TRANSFORMATION, GameEventData(trans.x, 16), this);
	if (m_owner->checkEvent(&event))
	{
		// Apply the new transformation
		memcpy( m_transformation, trans.x, sizeof( float ) * 16 );
		// Send it to horde
		sendTransformation();
		//and to the other components
		m_owner->executeEvent(&event);
	}
}
예제 #4
0
void SceneGraphComponent::setRotation(const Vec3f* rotation)
{	
	Vec3f scale = Matrix4f(m_transformation).getScale();	
	Matrix4f trans = Matrix4f::ScaleMat( scale.x, scale.y, scale.z );
	trans = trans * Matrix4f(Quaternion(degToRad(rotation->x), degToRad(rotation->y), degToRad(rotation->z)));
	trans.translate(m_transformation[12], m_transformation[13], m_transformation[14]);
	
	// Create event without sender attribute, such the scenegraph component will be updated using executeEvent too
	//GameEvent event(GameEvent::E_SET_TRANSFORMATION, &GameEventData(trans.x, 16), 0);

	GameEventData* ged = new GameEventData(trans.x, 16);
		GameEvent event(GameEvent::E_SET_TRANSFORMATION, ged, this);
	//GameEvent event(GameEvent::E_SET_TRANSFORMATION, &GameEventData(trans.x, 16), this);
	// Check if the new transformation can be set
	if (m_owner->checkEvent(&event))
	{
		// Apply transformation
		memcpy( m_transformation, trans.x, sizeof( float ) * 16 );
		// Send transformation to horde
		sendTransformation();
		// and to the other components
		m_owner->executeEvent(&event);
	}
	delete ged;
}
예제 #5
0
파일: node.cpp 프로젝트: smatcher/S5old
Matrix4f Node::getGlobalTransform(bool with_scale) const
{
    Matrix4f ret;

    Matrix4f self_mat;

    if(with_scale) {
        const Transformf* trans = static_cast<const Transformf*>(this);
        self_mat = Matrix4f(*trans);
    } else {
        self_mat = Matrix4f(rotation,position);
    }

    if(parent() != 0)
    {
        if(parent()->type() == ParentOfNode::NODE)
        {
            const Node* parentNode = static_cast<const Node*>(parent());
            ret = parentNode->getGlobalTransform(with_scale) * self_mat;
        }
        else
        {
            ret = self_mat;
        }
    }
    else
    {
        logWarn("trying to access globalTransform on unlinked node");
    }
    return ret;
}
예제 #6
0
void test_eigensolver_generic()
{
  int s = 0;
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST_1( eigensolver(Matrix4f()) );
    s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4);
    CALL_SUBTEST_2( eigensolver(MatrixXd(s,s)) );
    TEST_SET_BUT_UNUSED_VARIABLE(s)

    // some trivial but implementation-wise tricky cases
    CALL_SUBTEST_2( eigensolver(MatrixXd(1,1)) );
    CALL_SUBTEST_2( eigensolver(MatrixXd(2,2)) );
    CALL_SUBTEST_3( eigensolver(Matrix<double,1,1>()) );
    CALL_SUBTEST_4( eigensolver(Matrix2d()) );
  }

  CALL_SUBTEST_1( eigensolver_verify_assert(Matrix4f()) );
  s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4);
  CALL_SUBTEST_2( eigensolver_verify_assert(MatrixXd(s,s)) );
  CALL_SUBTEST_3( eigensolver_verify_assert(Matrix<double,1,1>()) );
  CALL_SUBTEST_4( eigensolver_verify_assert(Matrix2d()) );

  // Test problem size constructors
  CALL_SUBTEST_5(EigenSolver<MatrixXf> tmp(s));

  // regression test for bug 410
  CALL_SUBTEST_2(
  {
     MatrixXd A(1,1);
     A(0,0) = std::sqrt(-1.); // is Not-a-Number
     Eigen::EigenSolver<MatrixXd> solver(A);
     VERIFY_IS_EQUAL(solver.info(), NumericalIssue);
  }
  );
예제 #7
0
void test_eigensolver_generic()
{
  int s = 0;
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST_1( eigensolver(Matrix4f()) );
    s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4);
    CALL_SUBTEST_2( eigensolver(MatrixXd(s,s)) );

    // some trivial but implementation-wise tricky cases
    CALL_SUBTEST_2( eigensolver(MatrixXd(1,1)) );
    CALL_SUBTEST_2( eigensolver(MatrixXd(2,2)) );
    CALL_SUBTEST_3( eigensolver(Matrix<double,1,1>()) );
    CALL_SUBTEST_4( eigensolver(Matrix2d()) );
  }

  CALL_SUBTEST_1( eigensolver_verify_assert(Matrix4f()) );
  s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4);
  CALL_SUBTEST_2( eigensolver_verify_assert(MatrixXd(s,s)) );
  CALL_SUBTEST_3( eigensolver_verify_assert(Matrix<double,1,1>()) );
  CALL_SUBTEST_4( eigensolver_verify_assert(Matrix2d()) );

  // Test problem size constructors
  CALL_SUBTEST_5(EigenSolver<MatrixXf> tmp(s));

  // regression test for bug 410
  CALL_SUBTEST_2(
  {
     MatrixXd A(1,1);
     A(0,0) = std::sqrt(-1.);
     Eigen::EigenSolver<MatrixXd> solver(A);
     MatrixXd V(1, 1);
     V(0,0) = solver.eigenvectors()(0,0).real();
  }
  );
예제 #8
0
Matrix4f CalculateCameraTimeWarpMatrix( const Quatf &from, const Quatf &to )
{
    Matrix4f		lastSensorMatrix = Matrix4f( to ).Transposed();
    Matrix4f		lastViewMatrix = Matrix4f( from ).Transposed();
	Matrix4f		timeWarp = ( lastSensorMatrix * lastViewMatrix.Inverted() );

	return timeWarp;
}
void DistortionRenderer::RenderBothDistortionMeshes(void)
{
	Device->BeginScene();

	D3DCOLOR clearColor = D3DCOLOR_RGBA(
		(int)(RState.ClearColor[0] * 255.0f),
		(int)(RState.ClearColor[1] * 255.0f),
		(int)(RState.ClearColor[2] * 255.0f),
		(int)(RState.ClearColor[3] * 255.0f));

	Device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_STENCIL | D3DCLEAR_ZBUFFER, clearColor, 0, 0);

	for (int eye=0; eye<2; eye++)
	{
		FOR_EACH_EYE * e = &eachEye[eye];
		D3DVIEWPORT9 vp;
        vp.X=0; vp.Y=0;
        vp.Width=ScreenSize.w;	vp.Height=ScreenSize.h;
        vp.MinZ=0; vp.MaxZ = 1;

		Device->SetViewport(&vp);
		Device->SetStreamSource( 0, e->dxVerts,0, sizeof(ovrDistortionVertex) );
		Device->SetVertexDeclaration( VertexDecl ); 
		Device->SetIndices( e->dxIndices );
		Device->SetPixelShader( PixelShader );
		Device->SetTexture( 0, e->texture);

		//Choose which vertex shader, with associated additional inputs
		if (RState.DistortionCaps & ovrDistortionCap_TimeWarp)
		{          
			Device->SetVertexShader( VertexShaderTimewarp );  

            ovrMatrix4f timeWarpMatrices[2];            
            ovrHmd_GetEyeTimewarpMatrices(HMD, (ovrEyeType)eye,
                                          RState.EyeRenderPoses[eye], timeWarpMatrices);

			//Need to transpose the matrices
			timeWarpMatrices[0] = Matrix4f(timeWarpMatrices[0]).Transposed();
			timeWarpMatrices[1] = Matrix4f(timeWarpMatrices[1]).Transposed();

            // Feed identity like matrices in until we get proper timewarp calculation going on
			Device->SetVertexShaderConstantF(4, (float *) &timeWarpMatrices[0],4);
			Device->SetVertexShaderConstantF(20,(float *) &timeWarpMatrices[1],4);
        }
		else
		{
			Device->SetVertexShader( VertexShader );  
		}

		//Set up vertex shader constants
		Device->SetVertexShaderConstantF( 0, ( FLOAT* )&(e->UVScaleOffset[0]), 1 );
		Device->SetVertexShaderConstantF( 2, ( FLOAT* )&(e->UVScaleOffset[1]), 1 );

		Device->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,0,0,e->numVerts,0,e->numIndices/3);
	}

	Device->EndScene();
}
예제 #10
0
	void Camera::computeViewMatrix( void)
	{
		Matrix4f rotMatrix;
		rotMatrix *= Matrix4f().RotateX(m_pitchInDegrees);
		rotMatrix *= Matrix4f().RotateY(m_yawInDegrees);
		rotMatrix *= Matrix4f().RotateZ(m_rollInDegrees);
	
		LookAt(m_position.XYZ, (m_position + rotMatrix.GetXYZRow(2)).XYZ, rotMatrix.GetXYZRow(1).XYZ);
	}
예제 #11
0
Matrix4f RenderingEngine::getProjectedTransformation(Transform transform)
{
    Matrix4f transformationMatrix = getTransformation(transform);
    Matrix4f projectionMatrix = (*Matrix4f().initProjection((float)FOV, (float)m_iWidth, (float)m_iHeight, (float)zNear, (float)zFar));
	Matrix4f cameraRotation = Camera::mainCamera->transform.rotation.toRotationMatrix();
	Matrix4f cameraTranslation = (*Matrix4f().initTranslation(-Camera::mainCamera->transform.position.x, -Camera::mainCamera->transform.position.y, -Camera::mainCamera->transform.position.z));

    return projectionMatrix * cameraRotation * cameraTranslation * transformationMatrix;
}
예제 #12
0
RenderingEngine::RenderingEngine(const Window& window) :
	m_plane(Mesh("plane.obj")),
	m_window(&window),
	m_tempTarget(window.GetWidth(), window.GetHeight(), 0, GL_TEXTURE_2D, GL_NEAREST, GL_RGBA, GL_RGBA, false, GL_COLOR_ATTACHMENT0),
	m_planeMaterial("renderingEngine_filterPlane", m_tempTarget, 1, 8),
	m_defaultShader("forward-ambient"),
	m_shadowMapShader("shadowMapGenerator"),
	m_nullFilter("filter-null"),
	m_gausBlurFilter("filter-gausBlur7x1"),
	m_fxaaFilter("filter-fxaa"),
	m_altCameraTransform(Vector3f(0,0,0), Quaternion(Vector3f(0,1,0),ToRadians(180.0f))),
	m_altCamera(Matrix4f().InitIdentity(), &m_altCameraTransform)
{
	SetSamplerSlot("diffuse",   0);
	SetSamplerSlot("normalMap", 1);
	SetSamplerSlot("dispMap",   2);
	SetSamplerSlot("shadowMap", 3);
	SetSamplerSlot("roughMap",	4);
	
	SetSamplerSlot("filterTexture", 0);
	
	SetVector3f("ambient", Vector3f(0.2f, 0.2f, 0.2f));
	
	SetFloat("fxaaSpanMax", 8.0f);
	SetFloat("fxaaReduceMin", 1.0f/128.0f);
	SetFloat("fxaaReduceMul", 1.0f/8.0f);
	SetFloat("fxaaAspectDistortion", 150.0f);

	SetTexture("displayTexture", Texture(m_window->GetWidth(), m_window->GetHeight(), 0, GL_TEXTURE_2D, GL_LINEAR, GL_RGBA, GL_RGBA, true, GL_COLOR_ATTACHMENT0));

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	glFrontFace(GL_CW);
	glCullFace(GL_BACK);
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
	//glEnable(GL_DEPTH_CLAMP);
	//glEnable(GL_MULTISAMPLE);
	//glEnable(GL_FRAMEBUFFER_SRGB);
	                  
	//m_planeMaterial("renderingEngine_filterPlane", m_tempTarget, 1, 8);
	m_planeTransform.SetScale(1.0f);
	m_planeTransform.Rotate(Quaternion(Vector3f(1,0,0), ToRadians(90.0f)));
	m_planeTransform.Rotate(Quaternion(Vector3f(0,0,1), ToRadians(180.0f)));
	
	for(int i = 0; i < NUM_SHADOW_MAPS; i++)
	{
		int shadowMapSize = 1 << (i + 1);
		m_shadowMaps[i] = Texture(shadowMapSize, shadowMapSize, 0, GL_TEXTURE_2D, GL_LINEAR, GL_RG32F, GL_RGBA, true, GL_COLOR_ATTACHMENT0);
		m_shadowMapTempTargets[i] = Texture(shadowMapSize, shadowMapSize, 0, GL_TEXTURE_2D, GL_LINEAR, GL_RG32F, GL_RGBA, true, GL_COLOR_ATTACHMENT0);
	}
	
	m_lightMatrix = Matrix4f().InitScale(Vector3f(0,0,0));	
}
void test_matrix_power()
{
  CALL_SUBTEST_2(test2dRotation<double>(1e-13));
  CALL_SUBTEST_1(test2dRotation<float>(2e-5));  // was 1e-5, relaxed for clang 2.8 / linux / x86-64
  CALL_SUBTEST_9(test2dRotation<long double>(1e-13)); 
  CALL_SUBTEST_2(test2dHyperbolicRotation<double>(1e-14));
  CALL_SUBTEST_1(test2dHyperbolicRotation<float>(1e-5));
  CALL_SUBTEST_9(test2dHyperbolicRotation<long double>(1e-14));

  CALL_SUBTEST_10(test3dRotation<double>(1e-13));
  CALL_SUBTEST_11(test3dRotation<float>(1e-5));
  CALL_SUBTEST_12(test3dRotation<long double>(1e-13));

  CALL_SUBTEST_2(testGeneral(Matrix2d(),         1e-13));
  CALL_SUBTEST_7(testGeneral(Matrix3dRowMajor(), 1e-13));
  CALL_SUBTEST_3(testGeneral(Matrix4cd(),        1e-13));
  CALL_SUBTEST_4(testGeneral(MatrixXd(8,8),      2e-12));
  CALL_SUBTEST_1(testGeneral(Matrix2f(),         1e-4));
  CALL_SUBTEST_5(testGeneral(Matrix3cf(),        1e-4));
  CALL_SUBTEST_8(testGeneral(Matrix4f(),         1e-4));
  CALL_SUBTEST_6(testGeneral(MatrixXf(2,2),      1e-3)); // see bug 614
  CALL_SUBTEST_9(testGeneral(MatrixXe(7,7),      1e-13));
  CALL_SUBTEST_10(testGeneral(Matrix3d(),        1e-13));
  CALL_SUBTEST_11(testGeneral(Matrix3f(),        1e-4));
  CALL_SUBTEST_12(testGeneral(Matrix3e(),        1e-13));

  CALL_SUBTEST_2(testSingular(Matrix2d(),         1e-13));
  CALL_SUBTEST_7(testSingular(Matrix3dRowMajor(), 1e-13));
  CALL_SUBTEST_3(testSingular(Matrix4cd(),        1e-13));
  CALL_SUBTEST_4(testSingular(MatrixXd(8,8),      2e-12));
  CALL_SUBTEST_1(testSingular(Matrix2f(),         1e-4));
  CALL_SUBTEST_5(testSingular(Matrix3cf(),        1e-4));
  CALL_SUBTEST_8(testSingular(Matrix4f(),         1e-4));
  CALL_SUBTEST_6(testSingular(MatrixXf(2,2),      1e-3));
  CALL_SUBTEST_9(testSingular(MatrixXe(7,7),      1e-13));
  CALL_SUBTEST_10(testSingular(Matrix3d(),        1e-13));
  CALL_SUBTEST_11(testSingular(Matrix3f(),        1e-4));
  CALL_SUBTEST_12(testSingular(Matrix3e(),        1e-13));

  CALL_SUBTEST_2(testLogThenExp(Matrix2d(),         1e-13));
  CALL_SUBTEST_7(testLogThenExp(Matrix3dRowMajor(), 1e-13));
  CALL_SUBTEST_3(testLogThenExp(Matrix4cd(),        1e-13));
  CALL_SUBTEST_4(testLogThenExp(MatrixXd(8,8),      2e-12));
  CALL_SUBTEST_1(testLogThenExp(Matrix2f(),         1e-4));
  CALL_SUBTEST_5(testLogThenExp(Matrix3cf(),        1e-4));
  CALL_SUBTEST_8(testLogThenExp(Matrix4f(),         1e-4));
  CALL_SUBTEST_6(testLogThenExp(MatrixXf(2,2),      1e-3));
  CALL_SUBTEST_9(testLogThenExp(MatrixXe(7,7),      1e-13));
  CALL_SUBTEST_10(testLogThenExp(Matrix3d(),        1e-13));
  CALL_SUBTEST_11(testLogThenExp(Matrix3f(),        1e-4));
  CALL_SUBTEST_12(testLogThenExp(Matrix3e(),        1e-13));
}
예제 #14
0
Matrix4f RenderingEngine::getTransformation(Transform transform)
{
    Matrix4f translation = (*Matrix4f().initTranslation(transform.position.x,
                                                        transform.position.y,
                                                        transform.position.z));
    /*Matrix4f rotationMatrix = (*Matrix4f().initRotation(transform.vRotation.x,
                                                        transform.vRotation.y,
                                                        transform.vRotation.z));*/
	Matrix4f rotationMatrix = transform.rotation.toRotationMatrix();

    Matrix4f scaleMatrix = (*Matrix4f().initScale(transform.scale.x,
                                                  transform.scale.y,
                                                  transform.scale.z));
    return translation * rotationMatrix * scaleMatrix;
}
예제 #15
0
파일: UI.cpp 프로젝트: jjoo172/CS171
/* Handles mouse motion events. */
void UI::handleMouseMotion(int x, int y) {
    UI *ui = UI::getSingleton();

    // If the left button is being clicked, and the mouse has moved, and the
    // mouse is in the window, then update the arcball UI
    if (ui->mouse_down && (x != ui->mouse_x || y != ui->mouse_y) &&
        (x >= 0 && x < ui->xres && y >= 0 && y < ui->yres))
    {
        // Set up some matrices we need
        Matrix4f camera_to_ndc = Matrix4f();
        Matrix4f world_to_camera = Matrix4f();
        glGetFloatv(GL_PROJECTION_MATRIX, camera_to_ndc.data());
        glGetFloatv(GL_MODELVIEW_MATRIX, world_to_camera.data());
        Matrix3f ndc_to_world = camera_to_ndc.topLeftCorner(3, 3).inverse();

        // Get the two arcball vectors by transforming from NDC to camera
        // coordinates, ignoring translation components
        Vector3f va =
            (ndc_to_world * ui->getArcballVector(ui->mouse_x, ui->mouse_y)).normalized();
        Vector3f vb = (ndc_to_world * ui->getArcballVector(x, y)).normalized();
        
        // Compute the angle between them and the axis to rotate around
        // (this time rotated into world space, where the matrix is applied)
        Vector3f arcball_axis =
            (world_to_camera.topLeftCorner(3, 3).transpose() * va.cross(vb)).normalized();
        float arcball_angle = acos(fmax(fmin(va.dot(vb), 1.0), -1.0));

        // Update current arcball rotation and overall object rotation matrices
        makeRotateMat(ui->arcball_rotate_mat.data(), arcball_axis[0],
            arcball_axis[1], arcball_axis[2], arcball_angle);
        ui->arcball_object_mat =
            ui->arcball_rotate_mat * ui->arcball_object_mat;
        
        // If the arcball should rotate the entire scene, update the light
        // rotation matrix too 
        if (ui->arcball_scene) {
            ui->arcball_light_mat =
                ui->arcball_rotate_mat * ui->arcball_light_mat;
        }
        
        // Update the arcball start position
        ui->mouse_x = x;
        ui->mouse_y = y;
        
        // Update the image
        glutPostRedisplay();
    }
}
예제 #16
0
void RenderingEngine::ApplyFilter(const Shader& filter, const Texture& source, const Texture* dest)
{
	assert(&source != dest);
	if(dest == 0)
	{
		m_window->BindAsRenderTarget();
	}
	else
	{
		dest->BindAsRenderTarget();
	}
	
	SetTexture("filterTexture", source);
	
	m_altCamera.SetProjection(Matrix4f().InitIdentity());
	m_altCamera.GetTransform()->SetPos(Vector3f(0,0,0));
	m_altCamera.GetTransform()->SetRot(Quaternion(Vector3f(0,1,0),ToRadians(180.0f)));
	
//	const Camera* temp = m_mainCamera;
//	m_mainCamera = m_altCamera;

	glClear(GL_DEPTH_BUFFER_BIT);
	filter.Bind();
	filter.UpdateUniforms(m_planeTransform, m_planeMaterial, *this, m_altCamera);
	m_plane.Draw();
	
//	m_mainCamera = temp;
	SetTexture("filterTexture", 0);
}
예제 #17
0
Scale::Scale(float x, float y, float z){
	mat = Matrix4f();
	mat(0, 0) = x;
	mat(1, 1) = y;
	mat(2, 2) = z;
	mat(3, 3) = 1;
}
예제 #18
0
파일: Entity.cpp 프로젝트: erenik/engine
/// Recalculates the transformation matrix. All parts by default. If recursively, will update children (or parents?) recursively upon update.
void Entity::RecalculateMatrix(int whichParts/*= true*/, bool recursively /* = false*/)
{
	if (whichParts > TRANSLATION_ONLY || hasRotated)
	{
		if (whichParts == ALL_PARTS || hasRotated)
		{
			RecalcRotationMatrix(true);
		}
		localTransform = Matrix4f();
#ifdef USE_SSE
		// Translation should be just pasting in position.. no?
		localTransform.col3.data = localPosition.data;
		localTransform.col3.w = 1;
#else
		localTransform.Multiply((Matrix4f::Translation(position)));
#endif
		localTransform.Multiply(localRotation);
		// No use multiplying if not new scale.
		if (hasRescaled || whichParts)
			UPDATE_SCALING_MATRIX
		if (relevantScale)
			localTransform.Multiply(scalingMatrix);
			// Ensure it has a scale..?
	//	assert(transformationMatrix.HasValidScale());
	}
	// No rotation? -> 
	else 
	{
예제 #19
0
파일: test3.cpp 프로젝트: Whitestar/vmath
	void testInversion()
	{
		float data1[] =
		{
			1,2,3,4,
			2,3,4,1,
			3,4,1,2,
			4,1,2,3
		};

		float data2[] =
		{
			-9,  1,  1, 11,
			 1,  1, 11, -9,
			 1, 11, -9,  1,
			11, -9,  1,  1
		};

		mi1 = Matrix4f(data1);
		mi2 = mi1.inverse();
		Matrix4f imr(data2);
		imr = imr * 1/40.0f;

		/*
		std::cout << "mi1 = \n" << mi1 << std::endl;
		std::cout << "mi2 = \n" << mi2 << std::endl;
		std::cout << "imr = \n" << imr << std::endl;
		*/
		CPPUNIT_ASSERT(mi2 == imr);

	}
예제 #20
0
	Matrix4f Transform::getTransformation() {
		Matrix4f transMat = Matrix4f();
		transMat.initTranslation(translation.getX(),
					 translation.getY(),
					 translation.getZ() );
		Matrix4f rotMat = Matrix4f();
		rotMat.initRotation(rotation.getX(),
				    rotation.getY(),
				    rotation.getZ() );
		Matrix4f scaleMat = Matrix4f();
		scaleMat.initScale(scale.getX(),
				   scale.getY(),
				   scale.getZ() );

		return (transMat * (rotMat * scaleMat));
	}
예제 #21
0
Matrix4f MeganekkoActivity::Frame( const VrFrame & vrFrame )
{
    Scene * scene = GetScene();
    JNIEnv * jni = app->GetJava()->Env;

    jni->CallVoidMethod(app->GetJava()->ActivityObject, frameMethodId, (jlong)(intptr_t)&vrFrame);

    const bool headsetIsMounted = vrFrame.DeviceStatus.HeadsetIsMounted;
    if (!HmdMounted && headsetIsMounted) {
        jni->CallVoidMethod(app->GetJava()->ActivityObject, onHmdMountedMethodId);
    } else if (HmdMounted && !headsetIsMounted) {
        jni->CallVoidMethod(app->GetJava()->ActivityObject, onHmdUnmountedMethodId);
    }
    HmdMounted = headsetIsMounted;

    // Apply Camera movement to centerViewMatrix
    ovrMatrix4f input = vrFrame.DeviceStatus.DeviceIsDocked
            ? Matrix4f::Translation(scene->GetViewPosition())
            : Matrix4f::Translation(scene->GetViewPosition()) * Matrix4f(internalSensorRotation);
    Matrix4f centerViewMatrix = vrapi_GetCenterEyeViewMatrix( &app->GetHeadModelParms(), &vrFrame.Tracking, &input );

    scene->SetCenterViewMatrix(centerViewMatrix);

    // Update GUI systems last, but before rendering anything.
    GuiSys->Frame( vrFrame, centerViewMatrix);

    gl_delete.processQueues();
    scene->PrepareForRendering();


    return centerViewMatrix;
}
예제 #22
0
void test_stdvector_overload()
{
  // some non vectorizable fixed sizes
  CALL_SUBTEST_1(check_stdvector_matrix(Vector2f()));
  CALL_SUBTEST_1(check_stdvector_matrix(Matrix3f()));
  CALL_SUBTEST_2(check_stdvector_matrix(Matrix3d()));

  // some vectorizable fixed sizes
  CALL_SUBTEST_1(check_stdvector_matrix(Matrix2f()));
  CALL_SUBTEST_1(check_stdvector_matrix(Vector4f()));
  CALL_SUBTEST_1(check_stdvector_matrix(Matrix4f()));
  CALL_SUBTEST_2(check_stdvector_matrix(Matrix4d()));

  // some dynamic sizes
  CALL_SUBTEST_3(check_stdvector_matrix(MatrixXd(1,1)));
  CALL_SUBTEST_3(check_stdvector_matrix(VectorXd(20)));
  CALL_SUBTEST_3(check_stdvector_matrix(RowVectorXf(20)));
  CALL_SUBTEST_3(check_stdvector_matrix(MatrixXcf(10,10)));

  // some Transform
  CALL_SUBTEST_4(check_stdvector_transform(Affine2f())); // does not need the specialization (2+1)^2 = 9
  CALL_SUBTEST_4(check_stdvector_transform(Affine3f()));
  CALL_SUBTEST_4(check_stdvector_transform(Affine3d()));

  // some Quaternion
  CALL_SUBTEST_5(check_stdvector_quaternion(Quaternionf()));
  CALL_SUBTEST_5(check_stdvector_quaternion(Quaterniond()));
}
예제 #23
0
파일: matrix.cpp 프로젝트: Anteru/renderdoc
Matrix4f Matrix4f::Orthographic(const float near, const float far)
{
  float L = -10.0f;
  float R = 10.0f;

  float T = 10.0f;
  float B = -10.0f;

  float N = -fabsf(far - near) * 0.5f;
  float F = fabsf(far - near) * 0.5f;

  if(far < near)
  {
    float tmp = F;
    F = N;
    N = tmp;
  }

  float ortho[16] = {
      2.0f / (R - L), 0.0f,           0.0f,           (L + R) / (L - R),
      0.0f,           2.0f / (T - B), 0.0f,           (T + B) / (B - T),
      0.0f,           0.0f,           1.0f / (F - N), (F + N) / (N - F),
      0.0f,           0.0f,           0.0f,           1.0f,
  };

  return Matrix4f(ortho);
}
예제 #24
0
Matrix4f GridSystem::RotationMatrixOnAxis(float angle, float u, float v, float w)
{
	float rotationMatrix[4][4];
	float L = (u*u + v * v + w * w);
	angle = angle * M_PI / 180.0; //converting to radian value
	float u2 = u * u;
	float v2 = v * v;
	float w2 = w * w;

	rotationMatrix[0][0] = (u2 + (v2 + w2) * cos(angle)) / L;
	rotationMatrix[0][1] = (u * v * (1 - cos(angle)) - w * sqrt(L) * sin(angle)) / L;
	rotationMatrix[0][2] = (u * w * (1 - cos(angle)) + v * sqrt(L) * sin(angle)) / L;
	rotationMatrix[0][3] = 0.0;

	rotationMatrix[1][0] = (u * v * (1 - cos(angle)) + w * sqrt(L) * sin(angle)) / L;
	rotationMatrix[1][1] = (v2 + (u2 + w2) * cos(angle)) / L;
	rotationMatrix[1][2] = (v * w * (1 - cos(angle)) - u * sqrt(L) * sin(angle)) / L;
	rotationMatrix[1][3] = 0.0;

	rotationMatrix[2][0] = (u * w * (1 - cos(angle)) - v * sqrt(L) * sin(angle)) / L;
	rotationMatrix[2][1] = (v * w * (1 - cos(angle)) + u * sqrt(L) * sin(angle)) / L;
	rotationMatrix[2][2] = (w2 + (u2 + v2) * cos(angle)) / L;
	rotationMatrix[2][3] = 0.0;

	rotationMatrix[3][0] = 0.0;
	rotationMatrix[3][1] = 0.0;
	rotationMatrix[3][2] = 0.0;
	rotationMatrix[3][3] = 1.0;

	return Matrix4f(rotationMatrix[0][0], rotationMatrix[0][1], rotationMatrix[0][2], rotationMatrix[0][3], 
		rotationMatrix[1][0], rotationMatrix[1][1], rotationMatrix[1][2], rotationMatrix[1][3], 
		rotationMatrix[2][0], rotationMatrix[2][1], rotationMatrix[2][2], rotationMatrix[2][3], 
		rotationMatrix[3][0], rotationMatrix[3][1], rotationMatrix[3][2], rotationMatrix[3][3]);
}
예제 #25
0
void test_mapstaticmethods()
{
  ptr = internal::aligned_new<float>(1000);
  for(int i = 0; i < 1000; i++) ptr[i] = float(i);

  const_ptr = ptr;

  CALL_SUBTEST_1(( mapstaticmethods(Matrix<float, 1, 1>()) ));
  CALL_SUBTEST_1(( mapstaticmethods(Vector2f()) ));
  CALL_SUBTEST_2(( mapstaticmethods(Vector3f()) ));
  CALL_SUBTEST_2(( mapstaticmethods(Matrix2f()) ));
  CALL_SUBTEST_3(( mapstaticmethods(Matrix4f()) ));
  CALL_SUBTEST_3(( mapstaticmethods(Array4f()) ));
  CALL_SUBTEST_4(( mapstaticmethods(Array3f()) ));
  CALL_SUBTEST_4(( mapstaticmethods(Array33f()) ));
  CALL_SUBTEST_5(( mapstaticmethods(Array44f()) ));
  CALL_SUBTEST_5(( mapstaticmethods(VectorXf(1)) ));
  CALL_SUBTEST_5(( mapstaticmethods(VectorXf(8)) ));
  CALL_SUBTEST_6(( mapstaticmethods(MatrixXf(1,1)) ));
  CALL_SUBTEST_6(( mapstaticmethods(MatrixXf(5,7)) ));
  CALL_SUBTEST_7(( mapstaticmethods(ArrayXf(1)) ));
  CALL_SUBTEST_7(( mapstaticmethods(ArrayXf(5)) ));
  CALL_SUBTEST_8(( mapstaticmethods(ArrayXXf(1,1)) ));
  CALL_SUBTEST_8(( mapstaticmethods(ArrayXXf(8,6)) ));

  internal::aligned_delete(ptr, 1000);
}
예제 #26
0
Matrix4f Matrix4f::operator*(const Matrix4f matrix2)
{
	return Matrix4f(
	//First row of the new matrix.
	(m_matrix[0][0] * matrix2.Get(0,0)) + (m_matrix[1][0] * matrix2.Get(0,1)) + (m_matrix[2][0] * matrix2.Get(0,2)) + (m_matrix[3][0] * matrix2.Get(0,3)), 
	(m_matrix[0][0] * matrix2.Get(1,0)) + (m_matrix[1][0] * matrix2.Get(1,1)) + (m_matrix[2][0] * matrix2.Get(1,2)) + (m_matrix[3][0] * matrix2.Get(1,3)), 
	(m_matrix[0][0] * matrix2.Get(2,0)) + (m_matrix[1][0] * matrix2.Get(2,1)) + (m_matrix[2][0] * matrix2.Get(2,2)) + (m_matrix[3][0] * matrix2.Get(2,3)), 
	(m_matrix[0][0] * matrix2.Get(3,0)) + (m_matrix[1][0] * matrix2.Get(3,1)) + (m_matrix[2][0] * matrix2.Get(3,2)) + (m_matrix[3][0] * matrix2.Get(3,3)), 
	//Second row of the new matrix.
	(m_matrix[0][1] * matrix2.Get(0,0)) + (m_matrix[1][1] * matrix2.Get(0,1)) + (m_matrix[2][1] * matrix2.Get(0,2)) + (m_matrix[3][1] * matrix2.Get(0,3)), 
	(m_matrix[0][1] * matrix2.Get(1,0)) + (m_matrix[1][1] * matrix2.Get(1,1)) + (m_matrix[2][1] * matrix2.Get(1,2)) + (m_matrix[3][1] * matrix2.Get(1,3)), 
	(m_matrix[0][1] * matrix2.Get(2,0)) + (m_matrix[1][1] * matrix2.Get(2,1)) + (m_matrix[2][1] * matrix2.Get(2,2)) + (m_matrix[3][1] * matrix2.Get(2,3)), 
	(m_matrix[0][1] * matrix2.Get(3,0)) + (m_matrix[1][1] * matrix2.Get(3,1)) + (m_matrix[2][1] * matrix2.Get(3,2)) + (m_matrix[3][1] * matrix2.Get(3,3)), 
	//Third row of the new matrix.
	(m_matrix[0][2] * matrix2.Get(0,0)) + (m_matrix[1][2] * matrix2.Get(0,1)) + (m_matrix[2][2] * matrix2.Get(0,2)) + (m_matrix[3][2] * matrix2.Get(0,3)), 
	(m_matrix[0][2] * matrix2.Get(1,0)) + (m_matrix[1][2] * matrix2.Get(1,1)) + (m_matrix[2][2] * matrix2.Get(1,2)) + (m_matrix[3][2] * matrix2.Get(1,3)), 
	(m_matrix[0][2] * matrix2.Get(2,0)) + (m_matrix[1][2] * matrix2.Get(2,1)) + (m_matrix[2][2] * matrix2.Get(2,2)) + (m_matrix[3][2] * matrix2.Get(2,3)), 
	(m_matrix[0][2] * matrix2.Get(3,0)) + (m_matrix[1][2] * matrix2.Get(3,1)) + (m_matrix[2][2] * matrix2.Get(3,2)) + (m_matrix[3][2] * matrix2.Get(3,3)), 
	//Fourth row of the new matrix.
	(m_matrix[0][3] * matrix2.Get(0,0)) + (m_matrix[1][3] * matrix2.Get(0,1)) + (m_matrix[2][3] * matrix2.Get(0,2)) + (m_matrix[3][3] * matrix2.Get(0,3)), 
	(m_matrix[0][3] * matrix2.Get(1,0)) + (m_matrix[1][3] * matrix2.Get(1,1)) + (m_matrix[2][3] * matrix2.Get(1,2)) + (m_matrix[3][3] * matrix2.Get(1,3)), 
	(m_matrix[0][3] * matrix2.Get(2,0)) + (m_matrix[1][3] * matrix2.Get(2,1)) + (m_matrix[2][3] * matrix2.Get(2,2)) + (m_matrix[3][3] * matrix2.Get(2,3)), 
	(m_matrix[0][3] * matrix2.Get(3,0)) + (m_matrix[1][3] * matrix2.Get(3,1)) + (m_matrix[2][3] * matrix2.Get(3,2)) + (m_matrix[3][3] * matrix2.Get(3,3))
	);
}
예제 #27
0
void test_qtvector()
{
    // some non vectorizable fixed sizes
    CALL_SUBTEST(check_qtvector_matrix(Vector2f()));
    CALL_SUBTEST(check_qtvector_matrix(Matrix3f()));
    CALL_SUBTEST(check_qtvector_matrix(Matrix3d()));

    // some vectorizable fixed sizes
    CALL_SUBTEST(check_qtvector_matrix(Matrix2f()));
    CALL_SUBTEST(check_qtvector_matrix(Vector4f()));
    CALL_SUBTEST(check_qtvector_matrix(Matrix4f()));
    CALL_SUBTEST(check_qtvector_matrix(Matrix4d()));

    // some dynamic sizes
    CALL_SUBTEST(check_qtvector_matrix(MatrixXd(1,1)));
    CALL_SUBTEST(check_qtvector_matrix(VectorXd(20)));
    CALL_SUBTEST(check_qtvector_matrix(RowVectorXf(20)));
    CALL_SUBTEST(check_qtvector_matrix(MatrixXcf(10,10)));

    // some Transform
    CALL_SUBTEST(check_qtvector_transform(Transform2f()));
    CALL_SUBTEST(check_qtvector_transform(Transform3f()));
    CALL_SUBTEST(check_qtvector_transform(Transform3d()));
    //CALL_SUBTEST(check_qtvector_transform(Transform4d()));

    // some Quaternion
    CALL_SUBTEST(check_qtvector_quaternion(Quaternionf()));
    CALL_SUBTEST(check_qtvector_quaternion(Quaternionf()));
}
예제 #28
0
void test_adjoint()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST_1( adjoint(Matrix<float, 1, 1>()) );
    CALL_SUBTEST_2( adjoint(Matrix3d()) );
    CALL_SUBTEST_3( adjoint(Matrix4f()) );
    CALL_SUBTEST_4( adjoint(MatrixXcf(internal::random<int>(1,50), internal::random<int>(1,50))) );
    CALL_SUBTEST_5( adjoint(MatrixXi(internal::random<int>(1,50), internal::random<int>(1,50))) );
    CALL_SUBTEST_6( adjoint(MatrixXf(internal::random<int>(1,50), internal::random<int>(1,50))) );
  }
  // test a large matrix only once
  CALL_SUBTEST_7( adjoint(Matrix<float, 100, 100>()) );

#ifdef EIGEN_TEST_PART_4
  {
    MatrixXcf a(10,10), b(10,10);
    VERIFY_RAISES_ASSERT(a = a.transpose());
    VERIFY_RAISES_ASSERT(a = a.transpose() + b);
    VERIFY_RAISES_ASSERT(a = b + a.transpose());
    VERIFY_RAISES_ASSERT(a = a.conjugate().transpose());
    VERIFY_RAISES_ASSERT(a = a.adjoint());
    VERIFY_RAISES_ASSERT(a = a.adjoint() + b);
    VERIFY_RAISES_ASSERT(a = b + a.adjoint());

    // no assertion should be triggered for these cases:
    a.transpose() = a.transpose();
    a.transpose() += a.transpose();
    a.transpose() += a.transpose() + b;
    a.transpose() = a.adjoint();
    a.transpose() += a.adjoint();
    a.transpose() += a.adjoint() + b;
  }
#endif
}
예제 #29
0
// static
Matrix4f Matrix4f::rotation( const Quat4f& q )
{
	Quat4f qq = q.normalized();

	float xx = qq.x() * qq.x();
	float yy = qq.y() * qq.y();
	float zz = qq.z() * qq.z();

	float xy = qq.x() * qq.y();
	float zw = qq.z() * qq.w();

	float xz = qq.x() * qq.z();
	float yw = qq.y() * qq.w();

	float yz = qq.y() * qq.z();
	float xw = qq.x() * qq.w();

	return Matrix4f
	(
		1.0f - 2.0f * ( yy + zz ),		2.0f * ( xy - zw ),				2.0f * ( xz + yw ),				0.0f,
		2.0f * ( xy + zw ),				1.0f - 2.0f * ( xx + zz ),		2.0f * ( yz - xw ),				0.0f,
		2.0f * ( xz - yw ),				2.0f * ( yz + xw ),				1.0f - 2.0f * ( xx + yy ),		0.0f,
		0.0f,							0.0f,							0.0f,							1.0f
	);
}
예제 #30
0
void test_stdvector()
{
  // some non vectorizable fixed sizes
  CALL_SUBTEST_1(check_stdvector_matrix(Vector2f()));
  CALL_SUBTEST_1(check_stdvector_matrix(Matrix3f()));
  CALL_SUBTEST_2(check_stdvector_matrix(Matrix3d()));

  // some vectorizable fixed sizes
  CALL_SUBTEST_1(check_stdvector_matrix(Matrix2f()));
  CALL_SUBTEST_1(check_stdvector_matrix(Vector4f()));
  CALL_SUBTEST_1(check_stdvector_matrix(Matrix4f()));
  CALL_SUBTEST_2(check_stdvector_matrix(Matrix4d()));

  // some dynamic sizes
  CALL_SUBTEST_3(check_stdvector_matrix(MatrixXd(1,1)));
  CALL_SUBTEST_3(check_stdvector_matrix(VectorXd(20)));
  CALL_SUBTEST_3(check_stdvector_matrix(RowVectorXf(20)));
  CALL_SUBTEST_3(check_stdvector_matrix(MatrixXcf(10,10)));

  // some Transform
  CALL_SUBTEST_4(check_stdvector_transform(Projective2f()));
  CALL_SUBTEST_4(check_stdvector_transform(Projective3f()));
  CALL_SUBTEST_4(check_stdvector_transform(Projective3d()));
  //CALL_SUBTEST(heck_stdvector_transform(Projective4d()));

  // some Quaternion
  CALL_SUBTEST_5(check_stdvector_quaternion(Quaternionf()));
  CALL_SUBTEST_5(check_stdvector_quaternion(Quaterniond()));
}