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


C++ math::Matrix4类代码示例

本文整理汇总了C++中math::Matrix4的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4类的具体用法?C++ Matrix4怎么用?C++ Matrix4使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Matrix4类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setupCameraPerspective

void OpenGLRenderer::setupCameraPerspective(float pitch, float heading, float fov) {
	// TODO: Find a correct and exact formula for the FOV
	GLfloat glFOV = 0.63 * fov; // Approximative and experimental formula
	if (fov > 79.0 && fov < 81.0)
		glFOV = 50.5; // Somewhat good value for fov == 80
	else if (fov > 59.0 && fov < 61.0)
		glFOV = 36.0; // Somewhat good value for fov == 60

	Common::Rect frame = frameViewport();
	glViewport(frame.left, frame.top, frame.width(), frame.height());
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	Math::Matrix4 m = Math::makePerspectiveMatrix(glFOV, (GLfloat)kOriginalWidth / (GLfloat)kFrameHeight, 1.0, 10000.0);
	glMultMatrixf(m.getData());

	// Rotate the model to simulate the rotation of the camera
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glRotatef(pitch, -1.0f, 0.0f, 0.0f);
	glRotatef(heading - 180.0f, 0.0f, 1.0f, 0.0f);

	glGetDoublev(GL_MODELVIEW_MATRIX, _cubeModelViewMatrix);
	glGetDoublev(GL_PROJECTION_MATRIX, _cubeProjectionMatrix);
	glGetIntegerv(GL_VIEWPORT, (GLint *)_cubeViewport);
}
开发者ID:klusark,项目名称:twin,代码行数:25,代码来源:gfx_opengl.cpp

示例2:

void Lua_V2::WorldToScreen() {
	lua_Object xObj = lua_getparam(1);
	lua_Object yObj = lua_getparam(2);
	lua_Object zObj = lua_getparam(3);
	if (!lua_isnumber(xObj) || !lua_isnumber(yObj) || !lua_isnumber(zObj)) {
		lua_pushnumber(0.0);
		lua_pushnumber(0.0);
		return;
	}

	float x = lua_getnumber(xObj);
	float y = lua_getnumber(yObj);
	float z = lua_getnumber(zObj);
	Math::Vector3d pos = Math::Vector3d(x, y, z);

	const Set::Setup *setup = g_emi->getCurrSet()->getCurrSetup();
	const Math::Vector3d interest = setup->_interest;
	const float roll = setup->_roll;
	const Math::Quaternion quat = Math::Quaternion(interest.x(), interest.y(), interest.z(), roll);
	Math::Matrix4 view = quat.toMatrix();
	view.transpose();

	pos -= setup->_pos;
	pos = view.getRotation() * pos;
	pos.z() = -pos.z();

	Math::Matrix4 proj = GfxBase::makeProjMatrix(setup->_fov, setup->_nclip, setup->_fclip);
	proj.transpose();
	Math::Vector4d screen = proj * Math::Vector4d(pos.x(), pos.y(), pos.z(), 1.0);
	screen /= screen.w();

	lua_pushnumber((screen.x() + 1) * 320);
	lua_pushnumber((1 - screen.y()) * 240);
}
开发者ID:Akz-,项目名称:residual,代码行数:34,代码来源:lua_v2.cpp

示例3: setSkeleton

void EMIModel::setSkeleton(Skeleton *skel) {
	if (_skeleton == skel) {
		return;
	}
	_skeleton = skel;
	if (!skel || !_numBoneInfos) {
		return;
	}
	int boneVert = 0;
	delete[] _vertexBoneInfo; _vertexBoneInfo = NULL;
	delete[] _vertexBone; _vertexBone = NULL;
	_vertexBoneInfo = new int[_numBoneInfos];
	_vertexBone = new int[_numBoneInfos]; // Oversized, but yeah.

	for (int i = 0; i < _numBoneInfos; i++) {
		_vertexBoneInfo[i] = _skeleton->findJointIndex(_boneNames[_boneInfos[i]._joint], _skeleton->_numJoints);

		if (_boneInfos[i]._incFac == 1) {
			_vertexBone[boneVert] = i;
			boneVert++;
		}
	}

	Math::Vector3d vertex;
	Math::Matrix4 mat;
	for (int i = 0; i < _numVertices; i++) {
		vertex = _vertices[i];
		if (_vertexBoneInfo[_vertexBone[i]] != -1) {
			mat = _skeleton->_joints[_vertexBoneInfo[_vertexBone[i]]]._absMatrix;
			mat.inverseTranslate(&vertex);
			mat.inverseRotate(&vertex);
		}
		_vertices[i] = vertex;
	}
}
开发者ID:sietschie,项目名称:residualvm,代码行数:35,代码来源:modelemi.cpp

示例4: updatePosition

void SoundTrack::updatePosition() {
    if (!_positioned)
        return;

    Set *set = g_grim->getCurrSet();
    Set::Setup *setup = set->getCurrSetup();
    Math::Vector3d cameraPos = setup->_pos;
    Math::Vector3d vector = _pos - cameraPos;
    float distance = vector.getMagnitude();
    _attenuation = MAX(0.0f, 1.0f - distance / (_volume * 100.0f / Audio::Mixer::kMaxChannelVolume));
    if (!isfinite(_attenuation)) {
        _attenuation = 0.0f;
    }

    Math::Matrix4 worldRot = setup->_rot;
    Math::Vector3d relPos = (_pos - setup->_pos);
    Math::Vector3d p(relPos);
    worldRot.inverseRotate(&p);
    float angle = atan2(p.x(), p.z());
    float pan = sin(angle);
    _balance = (int)(pan * 127.0f);

    if (_handle) {
        g_system->getMixer()->setChannelBalance(*_handle, _balance);
        g_system->getMixer()->setChannelVolume(*_handle, (byte)getEffectiveVolume());
    }
}
开发者ID:timfel,项目名称:residualvm,代码行数:27,代码来源:track.cpp

示例5: setupCameraPerspective

void TinyGLRenderer::setupCameraPerspective(float pitch, float heading, float fov) {
	// TODO: Find a correct and exact formula for the FOV
	TGLfloat glFOV = 0.63 * fov; // Approximative and experimental formula
	if (fov > 79.0 && fov < 81.0)
		glFOV = 50.5; // Somewhat good value for fov == 80
	else if (fov > 59.0 && fov < 61.0)
		glFOV = 36.0; // Somewhat good value for fov == 60

	// NOTE: tinyGL viewport implementation needs to be checked as it doesn't behave the same as openGL
	tglViewport(0, kTopBorderHeight, kOriginalWidth, kFrameHeight);
	tglMatrixMode(TGL_PROJECTION);
	tglLoadIdentity();
	Math::Matrix4 m = Math::makePerspectiveMatrix(glFOV, (TGLfloat)kOriginalWidth / (TGLfloat)kFrameHeight, 1.0, 10000.0);
	tglMultMatrixf(m.getData());

	// Rotate the model to simulate the rotation of the camera
	tglMatrixMode(TGL_MODELVIEW);
	tglLoadIdentity();
	tglRotatef(pitch, -1.0f, 0.0f, 0.0f);
	tglRotatef(heading - 180.0f, 0.0f, 1.0f, 0.0f);

	tglGetFloatv(TGL_MODELVIEW_MATRIX, _cubeModelViewMatrix);
	tglGetFloatv(TGL_PROJECTION_MATRIX, _cubeProjectionMatrix);
	tglGetIntegerv(TGL_VIEWPORT, (TGLint *)_cubeViewport);
}
开发者ID:eriktorbjorn,项目名称:residualvm,代码行数:25,代码来源:gfx_tinygl.cpp

示例6: tglMultMatrix

            inline void tglMultMatrix(const math::Matrix4& matrix)
            {
#if defined(TAU_SCALAR_DOUBLE)
                    glMultTransposeMatrixd((const double*)matrix.getData());
#else
                    glMultTransposeMatrixf((const float*)matrix.getData());
#endif
            }
开发者ID:dylanmckay,项目名称:tau,代码行数:8,代码来源:apiwrap.hpp

示例7: NewtonBodyGetMatrix

//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
const Math::Point3
PhysicsActor::getPosition()
{
    Math::Point3 position;
    Math::Matrix4 matrix;
    NewtonBodyGetMatrix(m_pActor, matrix.m_array);
    matrix.getPosition(position);
    return position;
}
开发者ID:SgtFlame,项目名称:indiezen,代码行数:10,代码来源:PhysicsActor.cpp

示例8: intersectRay

bool VisualActor::intersectRay(const Math::Ray &ray, const Math::Vector3d position, float direction) {
	Math::Matrix4 inverseModelMatrix = getModelMatrix(position, direction);
	inverseModelMatrix.inverse();

	// Build an object local ray from the world ray
	Math::Ray localRay = ray;
	localRay.transform(inverseModelMatrix);

	return _model->intersectRay(localRay);
}
开发者ID:Nitrus,项目名称:residualvm,代码行数:10,代码来源:actor.cpp

示例9:

Math::Matrix4 VisualActor::getModelMatrix(const Math::Vector3d& position, float direction) {
	Math::Matrix4 posMatrix;
	posMatrix.setPosition(position);

	Math::Matrix4 rot1;
	rot1.buildAroundX(90);

	Math::Matrix4 rot2;
	rot2.buildAroundY(270 - direction);

	Math::Matrix4 scale;
	scale.setValue(2, 2, -1.0f);

	return posMatrix * rot1 * rot2 * scale;
}
开发者ID:Nitrus,项目名称:residualvm,代码行数:15,代码来源:actor.cpp

示例10: setupCameraPerspective

void BaseRenderer::setupCameraPerspective(float pitch, float heading, float fov) {
	_projectionMatrix = makeProjectionMatrix(fov);
	_modelViewMatrix = Math::Matrix4(180.0f - heading, pitch, 0.0f, Math::EO_YXZ);

	Math::Matrix4 proj = _projectionMatrix;
	Math::Matrix4 model = _modelViewMatrix;
	proj.transpose();
	model.transpose();

	_mvpMatrix = proj * model;

	_frustum.setup(_mvpMatrix);

	_mvpMatrix.transpose();
}
开发者ID:Nitrus,项目名称:residualvm,代码行数:15,代码来源:gfx.cpp

示例11: render

void OpenGLSPropRenderer::render(const Math::Vector3d position, float direction) {
	if (_faceVBO == -1) {
		// Update the OpenGL Buffer Objects if required
		clearVertices();
		uploadVertices();
	}

	_gfx->set3DMode();

	Math::Matrix4 model = getModelMatrix(position, direction);
	Math::Matrix4 view = StarkScene->getViewMatrix();
	Math::Matrix4 projection = StarkScene->getProjectionMatrix();

	Math::Matrix4 mvp = projection * view * model;
	mvp.transpose();

	_shader->use(true);
	_shader->setUniform("mvp", mvp);

	const Common::Array<Formats::BiffMesh::Face> &faces = _model->getFaces();
	const Common::Array<Formats::BiffMesh::Material> &materials = _model->getMaterials();

	for (Common::Array<Formats::BiffMesh::Face>::const_iterator face = faces.begin(); face != faces.end(); ++face) {
		const Formats::BiffMesh::Material &material = materials[face->materialId];

		// For each face draw its vertices from the VBO, indexed by the EBO
		const Gfx::Texture *tex = _texture->getTexture(material.texture);
		if (tex) {
			tex->bind();
		} else {
			glBindTexture(GL_TEXTURE_2D, 0);
		}

		GLuint ebo = _faceEBO[face];

		_shader->enableVertexAttribute("position", _faceVBO, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), 0);
		_shader->enableVertexAttribute("normal", _faceVBO, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), 12);
		_shader->enableVertexAttribute("texcoord", _faceVBO, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), 24);
		_shader->use(true);
		_shader->setUniform("textured", tex != nullptr);
		_shader->setUniform("color", Math::Vector3d(material.r, material.g, material.b));

		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
		glDrawElements(GL_TRIANGLES, face->vertexIndices.size(), GL_UNSIGNED_INT, 0);

		glUseProgram(0);
	}
}
开发者ID:Nitrus,项目名称:residualvm,代码行数:48,代码来源:openglsprop.cpp

示例12:

Math::Matrix4 VisualProp::getModelMatrix(const Math::Vector3d& position, float direction) {
	Math::Matrix4 posMatrix;
	posMatrix.setPosition(position);

	Math::Matrix4 rot1;
	rot1.buildAroundX(90);

	Math::Matrix4 rot2;
	rot2.buildAroundY(270 - direction);

	Math::Matrix4 scale;
	scale.setValue(2, 2, -1.0f);

	Math::Matrix4 modelTransform = _model->getTransform();

	// FIXME: Why has the scale to be after the model transform?
	return posMatrix * rot1 * rot2 * modelTransform * scale;
}
开发者ID:ComputeLinux,项目名称:residualvm,代码行数:18,代码来源:prop.cpp

示例13: getPosition

//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void
PhysicsActor::setOrientation(const Math::Matrix4& _orient)
{
    // transfer values from input matrix to temporary matrix:
    Math::Matrix4 matrix;
    for (int i = 0; i < 16; i++)
    {
        matrix.m_array[i] = _orient.m_array[i];
    }

    // add offset to orientation matrix before setting body:
    Math::Point3 pos;
    pos = getPosition();
    matrix.setPosition(pos);

    setActivationState(true);
    m_activationState = 1;

    NewtonBodySetMatrix(m_pActor, matrix.m_array);
}
开发者ID:SgtFlame,项目名称:indiezen,代码行数:21,代码来源:PhysicsActor.cpp

示例14: setupCameraPerspective

void ShaderRenderer::setupCameraPerspective(float pitch, float heading, float fov) {
  // TODO: Find a correct and exact formula for the FOV
  GLfloat glFOV = 0.63 * fov; // Approximative and experimental formula
  if (fov > 79.0 && fov < 81.0)
    glFOV = 50.5; // Somewhat good value for fov == 80
  else if (fov > 59.0 && fov < 61.0)
    glFOV = 36.0; // Somewhat good value for fov == 60

  glViewport(0, kBottomBorderHeight, kOriginalWidth, kFrameHeight);

  const Math::Vector2d topLeft = Math::Vector2d(0, kBottomBorderHeight + kFrameHeight);
  const Math::Vector2d bottomRight = Math::Vector2d(kOriginalWidth, kBottomBorderHeight);
  _viewport = Math::Rect2d(topLeft, bottomRight);

  float nclip = 1.0, fclip = 10000.0;
  float aspect = _viewport.getWidth() / _viewport.getHeight();

  // taken from glm
  float range = nclip * tan(glFOV / 2 * (LOCAL_PI / 180));
  float left = -range * aspect;
  float right = range * aspect;
  float bottom = -range;
  float top = range;

  Math::Matrix4 proj;
  proj(0,0) = (2.0f * nclip) / (right - left);
  proj(1,1) = (2.0f * nclip) / (top - bottom);
  proj(2,0) = (right + left) / (right - left);
  proj(2,1) = 0.0f; // (top + bottom) / (top - bottom);
  proj(2,2) = -(fclip + nclip) / (fclip - nclip);
  proj(2,3) = -1.0f;
  proj(3,2) = -(2.0f * fclip * nclip) / (fclip - nclip);
  proj(3,3) = 0.0f;
  proj.transpose();

  Math::Matrix4 model = Math::Quaternion::fromEuler(180.0f - heading, pitch, 0.0f).toMatrix();
  model.transpose();

  _mvpMatrix = proj * model;
  _mvpMatrix.transpose();
}
开发者ID:ZydrateJunkie,项目名称:grim_mouse,代码行数:41,代码来源:gfx_opengl_shaders.cpp

示例15: SetObjectTransform

void Transform::SetObjectTransform( const Math::Matrix4& transform )
{
    Math::Scale scale;
    Math::EulerAngles rotate;
    Math::Vector3 translate;
    transform.Decompose( scale, rotate, translate );

    m_Scale = scale;
    m_Rotate = rotate;
    m_Translate = translate;
    m_ObjectTransform = transform;
}
开发者ID:goofoo,项目名称:Helium,代码行数:12,代码来源:Transform.cpp


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