当前位置: 首页>>代码示例>>C++>>正文


C++ Mat4类代码示例

本文整理汇总了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();
}
开发者ID:pedroedrasousa,项目名称:opengl-stuff-cpp,代码行数:29,代码来源:Main.cpp

示例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;
		}
开发者ID:alubitz,项目名称:cibraryengine,代码行数:35,代码来源:Corpse.cpp

示例3: Mat4Stack

	Mat4Stack(void)
	{
		Mat4<T>		mat;

		mat.setIdentity();
		stack.push(mat);
	}
开发者ID:rdavid42,项目名称:demo,代码行数:7,代码来源:Mat4Stack.hpp

示例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);
}
开发者ID:,项目名称:,代码行数:27,代码来源:

示例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);
}
开发者ID:bsurmanski,项目名称:ggj2016,代码行数:7,代码来源:mat.cpp

示例6: Mat4

Mat4& BcCamera::GetTransform()
{
    Mat4* Ret = new Mat4();
    Ret->Translate(m_Position);
    Ret->Rotate(m_Rotation);
    return *Ret;
}
开发者ID:djdduty,项目名称:LD29,代码行数:7,代码来源:Camera.cpp

示例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);
}
开发者ID:ghtalpo,项目名称:gideros,代码行数:25,代码来源:dxcompat.cpp

示例8:

void Mat4::Rotate(const Vec3 &axis, const float angle)
{
	Mat4 tmp;
	
	tmp.BuildRotate(axis, angle);
	(*this) *= tmp;
}
开发者ID:pedroedrasousa,项目名称:opengl-stuff-cpp,代码行数:7,代码来源:Matrix.cpp

示例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();
    }
}
开发者ID:zongwave,项目名称:IPASS,代码行数:35,代码来源:calc_projective2d.cpp

示例10: getModelMatrix

Mat4 Entity::getModelMatrix() {
    Mat4 mat;
    mat.scale(scale.x, scale.y, scale.z);
    mat = mat * rotation;
    mat.translate(position);
    return mat;
}
开发者ID:bsurmanski,项目名称:BosTek8042,代码行数:7,代码来源:entity.cpp

示例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);
	}
}
开发者ID:dwprojects,项目名称:poly_test,代码行数:25,代码来源:transform.c

示例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));
}
开发者ID:ArkightCrossfaith,项目名称:learning-cocos2dx,代码行数:26,代码来源:Chapter9_6.cpp

示例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();
}
开发者ID:,项目名称:,代码行数:28,代码来源:

示例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);

}
开发者ID:jun496276723,项目名称:CocosMFCEditor,代码行数:34,代码来源:CCRay.cpp

示例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);
        }
    }
}
开发者ID:Zaela,项目名称:ZEQ-API,代码行数:28,代码来源:model_static.cpp


注:本文中的Mat4类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。