本文整理汇总了C++中Matrix4f函数的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4f函数的具体用法?C++ Matrix4f怎么用?C++ Matrix4f使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Matrix4f函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: h3dSetNodeFlags
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: trans
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: Matrix4f
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: Matrix4f
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;
}
示例5: test_eigensolver_generic
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);
}
);
示例6: test_eigensolver_generic
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();
}
);
示例7: CalculateCameraTimeWarpMatrix
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;
}
示例8: D3DCOLOR_RGBA
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();
}
示例9: Matrix4f
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);
}
示例10: getTransformation
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;
}
示例11: m_plane
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));
}
示例12: test_matrix_power
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));
}
示例13: Matrix4f
/* 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();
}
}
示例14: assert
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);
}
示例15: Matrix4f
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;
}