本文整理汇总了C++中Mat4::scale方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat4::scale方法的具体用法?C++ Mat4::scale怎么用?C++ Mat4::scale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat4
的用法示例。
在下文中一共展示了Mat4::scale方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getModelMatrix
Mat4 Entity::getModelMatrix() {
Mat4 mat;
mat.scale(scale.x, scale.y, scale.z);
mat = mat * rotation;
mat.translate(position);
return mat;
}
示例2: draw
void BillboardParticleSystem::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
begin();
Vec3 scale;
transform.getScale(&scale);
Mat4 billboardTransform;
billboardTransform.translate(transform.m[12],transform.m[13],transform.m[14]);
billboardTransform.scale(scale);
CCASSERT( _particleIdx == 0 || _particleIdx == _particleCount, "Abnormal error in particle quad");
//quad command
if(_particleIdx > 0)
{
_quadCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, _quads, _particleIdx, transform);
renderer->addCommand(&_quadCommand);
}
end();
}
示例3: draw
void TerrainMesh::draw(const helsing::Mat4& modelViewMatrix, const helsing::Mat4& projectionMatrix) {
using helsing::Mat4;
float midpoint = (width-1)/2.0;
float s = 65.0/(width-1.0);
Mat4 mv = modelViewMatrix;
mv = mv.scale(s,s,s);
mv = mv.translate(-midpoint,0,-midpoint);
shader->use(mv, projectionMatrix);
glBindVertexArray(vaoId);
glDrawElements(
GL_TRIANGLE_STRIP,
numberOfVertices,
GL_UNSIGNED_INT,
0 //Specifies a pointer to the location where the indices are stored.
);
glBindVertexArray(0); //disable vertex array object
}
示例4: update
bool GLCamera::update() {
if (invalid) {
if ((style == LAYER) || (style == BACKGROUND)) {
projection16fv.set(0);
projection16fv[0] = 2.0f / width;
projection16fv[5] = -2.0f / height;
projection16fv[12] = -1.0f + target.x * projection16fv[0];
projection16fv[13] = 1.0f + target.y * projection16fv[5];
projection16fv[10] = projection16fv[15] = 1.0f;
/*
{ 2/w, 0, 0, 0} rX = sX * 2 / w - 1 <=> (0..w) -> (-1..+1)
{ 0, -2/h, 0, 0} rY = sY * -2 / h + 1 <=> (0..w) -> (+1..-1) // flip vertical
{ 0, 0, 1, 0}
{ -1, 1, 0, 1}
*/
view16fv.identity();
} else {
if (style == ORTHOGRAPHIC) {
GLfloat w2 = width / 2.0f;
GLfloat h2 = height / 2.0f;
projection16fv.ortho(-w2, w2, -h2, h2, min, max);
} else if (style == PERSPECTIVE) {
Vec3 v;
v.set(scale);
Mat4 scale;
scale.scale(v);
projection16fv.perspective(fov, width/height, min, max).multiply(scale);
}
view16fv.lookAt(position, target, head);
}
if (style != BACKGROUND) {
projection16fv.multiply(context->ratio16fv, projection16fv);
}
invalid = false;
return true;
}
return false;
}
示例5: if
void Animate3D::update(float t)
{
if (_target)
{
if (_state == Animate3D::Animate3DState::FadeIn && _lastTime > 0.f)
{
_accTransTime += (t - _lastTime) * getDuration();
_weight = _accTransTime / _transTime;
if (_weight >= 1.0f)
{
_accTransTime = _transTime;
_weight = 1.0f;
_state = Animate3D::Animate3DState::Running;
s_fadeInAnimates.erase(_target);
s_runningAnimates[_target] = this;
}
}
else if (_state == Animate3D::Animate3DState::FadeOut && _lastTime > 0.f)
{
_accTransTime += (t - _lastTime) * getDuration();
_weight = 1 - _accTransTime / _transTime;
if (_weight <= 0.0f)
{
_accTransTime = _transTime;
_weight = 0.0f;
s_fadeOutAnimates.erase(_target);
_target->stopAction(this);
return;
}
}
float lastTime = _lastTime;
_lastTime = t;
if (_quality != Animate3DQuality::QUALITY_NONE)
{
if (_weight > 0.0f)
{
float transDst[3], rotDst[4], scaleDst[3];
float* trans = nullptr, *rot = nullptr, *scale = nullptr;
if (_playReverse){
t = 1 - t;
lastTime = 1.0f - lastTime;
}
t = _start + t * _last;
lastTime = _start + lastTime * _last;
for (const auto& it : _boneCurves) {
auto bone = it.first;
auto curve = it.second;
if (curve->translateCurve)
{
curve->translateCurve->evaluate(t, transDst, _translateEvaluate);
trans = &transDst[0];
}
if (curve->rotCurve)
{
curve->rotCurve->evaluate(t, rotDst, _roteEvaluate);
rot = &rotDst[0];
}
if (curve->scaleCurve)
{
curve->scaleCurve->evaluate(t, scaleDst, _scaleEvaluate);
scale = &scaleDst[0];
}
bone->setAnimationValue(trans, rot, scale, this, _weight);
}
for (const auto& it : _nodeCurves)
{
auto node = it.first;
auto curve = it.second;
Mat4 transform;
if (curve->translateCurve)
{
curve->translateCurve->evaluate(t, transDst, _translateEvaluate);
transform.translate(transDst[0], transDst[1], transDst[2]);
}
if (curve->rotCurve)
{
curve->rotCurve->evaluate(t, rotDst, _roteEvaluate);
Quaternion qua(rotDst[0], rotDst[1], rotDst[2], rotDst[3]);
transform.rotate(qua);
}
if (curve->scaleCurve)
{
curve->scaleCurve->evaluate(t, scaleDst, _scaleEvaluate);
transform.scale(scaleDst[0], scaleDst[1], scaleDst[2]);
}
node->setAdditionalTransform(&transform);
}
if (!_keyFrameUserInfos.empty()){
float prekeyTime = lastTime * getDuration() * _frameRate;
float keyTime = t * getDuration() * _frameRate;
std::vector<Animate3DDisplayedEventInfo*> eventInfos;
for (auto keyFrame : _keyFrameUserInfos)
{
//.........这里部分代码省略.........
示例6: onDraw
void Skybox::onDraw(const Mat4& transform, uint32_t /*flags*/)
{
auto camera = Camera::getVisitingCamera();
Mat4 cameraModelMat = camera->getNodeToWorldTransform();
Mat4 projectionMat = camera->getProjectionMatrix();
// Ignore the translation
cameraModelMat.m[12] = cameraModelMat.m[13] = cameraModelMat.m[14] = 0;
// prescale the matrix to account for the camera fov
cameraModelMat.scale(1 / projectionMat.m[0], 1 / projectionMat.m[5], 1.0);
auto state = getGLProgramState();
state->apply(transform);
Vec4 color(_displayedColor.r / 255.f, _displayedColor.g / 255.f, _displayedColor.b / 255.f, 1.f);
state->setUniformVec4("u_color", color);
state->setUniformMat4("u_cameraRot", cameraModelMat);
glEnable(GL_DEPTH_TEST);
RenderState::StateBlock::_defaultState->setDepthTest(true);
glDepthFunc(GL_LEQUAL);
RenderState::StateBlock::_defaultState->setDepthFunction(RenderState::DEPTH_LEQUAL);
glEnable(GL_CULL_FACE);
RenderState::StateBlock::_defaultState->setCullFace(true);
glCullFace(GL_BACK);
RenderState::StateBlock::_defaultState->setCullFaceSide(RenderState::CULL_FACE_SIDE_BACK);
glDisable(GL_BLEND);
RenderState::StateBlock::_defaultState->setBlend(false);
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(_vao);
}
else
{
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(Vec3), nullptr);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
}
glDrawElements(GL_TRIANGLES, (GLsizei)6, GL_UNSIGNED_BYTE, nullptr);
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(0);
}
else
{
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4);
CHECK_GL_ERROR_DEBUG();
}
示例7: if
void Animate3D::update(float t)
{
if (_target)
{
if (_state == Animate3D::Animate3DState::FadeIn && _lastTime > 0.f)
{
_accTransTime += (t - _lastTime) * getDuration();
_weight = _accTransTime / _transTime;
if (_weight >= 1.0f)
{
_accTransTime = _transTime;
_weight = 1.0f;
_state = Animate3D::Animate3DState::Running;
s_fadeInAnimates.erase(_target);
s_runningAnimates[_target] = this;
}
}
else if (_state == Animate3D::Animate3DState::FadeOut && _lastTime > 0.f)
{
_accTransTime += (t - _lastTime) * getDuration();
_weight = 1 - _accTransTime / _transTime;
if (_weight <= 0.0f)
{
_accTransTime = _transTime;
_weight = 0.0f;
s_fadeOutAnimates.erase(_target);
}
}
_lastTime = t;
if (_weight > 0.0f)
{
float transDst[3], rotDst[4], scaleDst[3];
float* trans = nullptr, *rot = nullptr, *scale = nullptr;
if (_playReverse)
t = 1 - t;
t = _start + t * _last;
for (const auto& it : _boneCurves) {
auto bone = it.first;
auto curve = it.second;
if (curve->translateCurve)
{
curve->translateCurve->evaluate(t, transDst, _translateEvaluate);
trans = &transDst[0];
}
if (curve->rotCurve)
{
curve->rotCurve->evaluate(t, rotDst, _roteEvaluate);
rot = &rotDst[0];
}
if (curve->scaleCurve)
{
curve->scaleCurve->evaluate(t, scaleDst, _scaleEvaluate);
scale = &scaleDst[0];
}
bone->setAnimationValue(trans, rot, scale, this, _weight);
}
for (const auto& it : _nodeCurves)
{
auto node = it.first;
auto curve = it.second;
Mat4 transform;
if (curve->translateCurve)
{
curve->translateCurve->evaluate(t, transDst, _translateEvaluate);
transform.translate(transDst[0], transDst[1], transDst[2]);
}
if (curve->rotCurve)
{
curve->rotCurve->evaluate(t, rotDst, _roteEvaluate);
Quaternion qua(rotDst[0], rotDst[1], rotDst[2], rotDst[3]);
transform.rotate(qua);
}
if (curve->scaleCurve)
{
curve->scaleCurve->evaluate(t, scaleDst, _scaleEvaluate);
transform.scale(scaleDst[0], scaleDst[1], scaleDst[2]);
}
node->setAdditionalTransform(&transform);
}
}
}
}