本文整理汇总了C++中Mat4类的典型用法代码示例。如果您正苦于以下问题:C++ Mat4类的具体用法?C++ Mat4怎么用?C++ Mat4使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mat4类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RenderSprite
void RenderSprite(float size, Vec3 *eyePos, Mat4 matModelView)
{
if(size == 0)
return;
size /= 2;
glPushMatrix();
matModelView.Translate(*eyePos);
matModelView = matModelView.Inverse();
glMultMatrixf(matModelView.m);
glDisable(GL_CULL_FACE);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0.0f, 1.0f);
glVertex3f( -size, size, 0);
glTexCoord2f(1.0f, 1.0f);
glVertex3f( size, size, 0);
glTexCoord2f(0.0f, 0.0f);
glVertex3f( -size, -size, 0);
glTexCoord2f(1.0f, 0.0f);
glVertex3f( size, -size, 0);
glEnd();
glEnable(GL_CULL_FACE);
glPopMatrix();
}
示例2: GetShot
bool GetShot(Shot* shot, Vec3 poi, Vec3 momentum)
{
if(blood_material != NULL)
for (int i = 0; i < 8; ++i)
{
Particle* p = new Particle(corpse->game_state, poi, Random3D::RandomNormalizedVector(Random3D::Rand(5)) + momentum * Random3D::Rand(), NULL, blood_material, Random3D::Rand(0.05f, 0.15f), 0.25f);
p->gravity = 9.8f;
p->damp = 0.05f;
corpse->game_state->Spawn(p);
}
Mat4 xform;
{
xform = rbi->GetTransformationMatrix();
float ori_values[] = {xform[0], xform[1], xform[2], xform[4], xform[5], xform[6], xform[8], xform[9], xform[10]};
Quaternion rigid_body_ori = Quaternion::FromRotationMatrix(Mat3(ori_values).Transpose());
Vec3 pos = xform.TransformVec3(0, 0, 0, 1);
xform = Mat4::FromPositionAndOrientation(pos, rigid_body_ori.ToMat3().Transpose());
}
Vec3 pos = xform.TransformVec3(0, 0, 0, 1);
Vec3 x_axis = xform.TransformVec3(1, 0, 0, 0);
Vec3 y_axis = xform.TransformVec3(0, 1, 0, 0);
Vec3 z_axis = xform.TransformVec3(0, 0, 1, 0);
Vec3 local_poi;
local_poi = poi - pos;
local_poi = Vec3(Vec3::Dot(local_poi, x_axis), Vec3::Dot(local_poi, y_axis), Vec3::Dot(local_poi, z_axis));
local_poi = local_poi.x * x_axis + local_poi.y * y_axis + local_poi.z * z_axis;
rbi->Activate();
rbi->ApplyImpulse(momentum, local_poi);
return true;
}
示例3: Mat4Stack
Mat4Stack(void)
{
Mat4<T> mat;
mat.setIdentity();
stack.push(mat);
}
示例4: while
void Geometry::update(u32 delta)
{
char szPath[MAX_PATH] = {0};
char szPath2[MAX_PATH];
while(mAniTime.current > mAniTime.end)
{
mAniTime.current -= mAniTime.end;
}
if (mSkin && mSkeleton)
{
mSkeleton->update(mAniTime, *mSkin);
}
if (!mStopAimation)
{
mAniTime.current += delta * m_speed;;
}
//
Vec3 speed(0.000, 0.000, 0.0);
Quaternion q(0, 0, 0, 0.000*mAniTime.current);
Mat4 tQ(q);
Mat4 tT = Mat4::IDENTITY;
Vec3 offsetMatrix(-0.5, -0.5, 0.0);
tT.setTrans(offsetMatrix);
mUVMatrix = tT.inverse() * tQ * tT;
//
mMaterial->update(delta);
}
示例5:
Mat4 Mat4::scaled(float x, float y, float z) const {
Mat4 m;
m.v[0] = x;
m.v[5] = y;
m.v[10] = z;
return m.mul(*this);
}
示例6: Mat4
Mat4& BcCamera::GetTransform()
{
Mat4* Ret = new Mat4();
Ret->Translate(m_Position);
Ret->Rotate(m_Rotation);
return *Ret;
}
示例7: glOrtho
void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val)
{
Mat4 O;
O.loadIdentity();
O.M[0][0] = 2.0 / (right - left);
O.M[1][1] = 2.0 / (top - bottom);
O.M[0][3] = -(right + left) / (right - left);
O.M[1][3] = -(top + bottom) / (top - bottom);
if (dxcompat_zrange01){
O.M[2][2] = 1.0 /(far_val - near_val);
O.M[2][3] = -near_val / (far_val - near_val);
}
else {
O.M[2][2] = 2.0 / (far_val - near_val); // -2.0 used in OpenGL documentation but can't be right!
O.M[2][3] = -(far_val + near_val) / (far_val - near_val);
}
if (g_modelview)
modelmat.mulrightby(O);
else
projectionmat.mulrightby(O);
}
示例8:
void Mat4::Rotate(const Vec3 &axis, const float angle)
{
Mat4 tmp;
tmp.BuildRotate(axis, angle);
(*this) *= tmp;
}
示例9: calc_projective
void calc_projective (const std::vector<double>& frame_ts,
const std::vector<Vec4>& gyro_quat,
const std::vector<Vec3>& acc_trans,
const std::vector<double>& gyro_ts,
CalibrationParams calib,
std::vector<Mat4>& projective)
{
int index0 = 0;
int index1 = 0;
size_t frame_count = frame_ts.size();
for (int fid = 0; fid < frame_count; fid++) {
const double ts0 = frame_ts[fid] + calib.gyro_delay;
Quatern quat0 = interp_gyro_quatern(ts0, gyro_quat, gyro_ts, index0) + Quatern(calib.gyro_drift);
const double ts1 = frame_ts[fid + 1] + calib.gyro_delay;
Quatern quat1 = interp_gyro_quatern(ts1, gyro_quat, gyro_ts, index1) + Quatern(calib.gyro_drift);
Vec3 trans0 = acc_trans[fid];
Vec3 trans1 = acc_trans[fid + 1];
Mat4 extr0 = calc_extrinsic(quat0, trans0);
Mat4 extr1 = calc_extrinsic(quat1, trans1);
Mat3 intr = calc_intrinsic(calib.fx, calib.fy, calib.cx, calib.cy, calib.skew);
Mat4 intrinsic = Mat4(Vec4(intr.v0, 0),
Vec4(intr.v1, 0),
Vec4(intr.v2, 0),
Vec4(0, 0, 0, 1));
projective[fid] = intrinsic * extr0 * extr1.transpose() * intrinsic.inverse();
}
}
示例10: getModelMatrix
Mat4 Entity::getModelMatrix() {
Mat4 mat;
mat.scale(scale.x, scale.y, scale.z);
mat = mat * rotation;
mat.translate(position);
return mat;
}
示例11: get_transformation
Mat4 * get_transformation(Transform *self)
{
Mat4 *t = NULL;
Mat4 *r = NULL;
Mat4 *s = NULL;
t = mat4_init_translation(self->translation->x,
self->translation->y,
self->translation->z);
r = mat4_init_rotation(self->rotation->x,
self->rotation->y,
self->rotation->z);
s = mat4_init_scaling(self->scaling->x,
self->scaling->y,
self->scaling->z);
if (t && r && s)
{
return(s->mul(s, (t->mul(t,r))));
}
else
{
return(NULL);
}
}
示例12: Vec3
void ABBTest::update(float dt)
{
if (_pick)
return;
_drawAABB->clear();
Vec3 extents = Vec3(60, 30, 60);
_aabb = AABB(-extents, extents);
static float angle = 0.f;
if (angle > 360) {
angle = 0;
}
angle+=0.01f;
Mat4 mat = Mat4::IDENTITY;
mat.rotate(Vec3::UNIT_Y, angle);
_aabb.transform(mat);
Vec3 corners[8] = {};
_aabb.getCorners(corners);
_drawAABB->setPosition3D(_aabb.getCenter());
_drawAABB->drawCube(corners, Color4F(0,0,1,1));
}
示例13: setTransform
void Camera::setTransform(const Vec4 &_pos, const Vec4 &_rotation )
{
m_position = _pos;
m_rotation = _rotation;
m_viewMatrix.identity();
// // Rotation
m_viewMatrix.rotate(_rotation);
// Translate
Mat4 tmp;
tmp.identity();
tmp.m_m[3][0] = _pos.m_x;
tmp.m_m[3][1] = _pos.m_y;
tmp.m_m[3][2] = _pos.m_z;
// tmp.m_m[0][3] *= -1;
// tmp.m_m[3][0] *= -1;
// tmp.m_m[1][3] *= -1;
// tmp.m_m[3][1] *= -1;
tmp *= m_viewMatrix;
m_viewMatrix = tmp;
setView();
}
示例14: intersects
bool Ray::intersects(const OBB& obb, float* distance) const
{
AABB aabb;
aabb._min = - obb._extents;
aabb._max = obb._extents;
Ray ray;
ray._direction = _direction;
ray._origin = _origin;
Mat4 mat = Mat4::IDENTITY;
mat.m[0] = obb._xAxis.x;
mat.m[1] = obb._xAxis.y;
mat.m[2] = obb._xAxis.z;
mat.m[4] = obb._yAxis.x;
mat.m[5] = obb._yAxis.y;
mat.m[6] = obb._yAxis.z;
mat.m[8] = obb._zAxis.x;
mat.m[9] = obb._zAxis.y;
mat.m[10] = obb._zAxis.z;
mat.m[12] = obb._center.x;
mat.m[13] = obb._center.y;
mat.m[14] = obb._center.z;
mat = mat.getInversed();
ray.transform(mat);
return ray.intersects(aabb, distance);
}
示例15: getModelPrototype
void ModelStatic::calculateBoundingBox(AABB& box)
{
zeq_model_proto_t* proto = getModelPrototype();
if (!proto)
return;
Mat4 matrix = getModelMatrix();
Vec3 pos;
for (VertexBuffer* vb : proto->getVertexBuffers())
{
for (Vertex& vert : *vb)
{
matrix.transformVector(pos, vert.pos);
box.addInternalPoint(pos);
}
}
for (VertexBuffer* vb : proto->getVertexBuffersNoCollide())
{
for (Vertex& vert : *vb)
{
matrix.transformVector(pos, vert.pos);
box.addInternalPoint(pos);
}
}
}