本文整理汇总了C++中Mat4::rotate方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat4::rotate方法的具体用法?C++ Mat4::rotate怎么用?C++ Mat4::rotate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat4
的用法示例。
在下文中一共展示了Mat4::rotate方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
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));
}
示例2: rotate
GLCamera* GLCamera::rotate(const Vec3& vec, GLfloat angle) {
Vec3 normal;
normal.normalize(vec);
Mat4 rotate;
rotate.rotate(normal, angle);
position.subtract(target).transform(rotate).add(target);
invalid = true;
return this;
}
示例3: exportPieceToObj
bool SlvPainter::exportPieceToObj(ObjExport& oe, int f) const
{
const PicDef *pdef = m_scube->dt[f].sdef();
Shape::FaceDef *face = &m_scube->shape->faces[f];
//int rtnindx = m_scube->dt[i].abs_rt;
int rtnindx = rotationSub(m_scube->dt[f].abs_rt, pdef->dispRot);
Mat4 curMatrix = Mat4::translation(face->ex.x, face->ex.y, face->ex.z);
switch (face->dr)
{
case XY_PLANE:
curMatrix.translate(0, 0, 1);
curMatrix.rotate(90, 0, 1, 0);
break;
case XZ_PLANE:
curMatrix.rotate(90, 0, 1, 0);
curMatrix.rotate(90, 0, 0, 1);
break;
case YZ_PLANE:
// no need to do any rotation
break;
}
curMatrix.translate(0.5, 2.5, 2.5);
curMatrix.rotate(rtnindx * -90, 1, 0, 0);
if (rtnindx >= 4) {
curMatrix.rotate(180, 0, 0, 1);
curMatrix.rotate(90, 1, 0, 0);
}
curMatrix.translate(-0.5, -2.5, -2.5);
return PicPainter(pdef).exportToObj(oe, curMatrix);
}
示例4: testQuat
void testQuat()
{
Mat4 m;
m.identity();
m.rotate(45, 1, 0, 0);
//m.transpose();
Quaternion q = Quaternion::fromMat(m);
Mat4 m2 = q.toMatrix();
Quaternion q2 = Quaternion::fromMat(m2);
getchar();
}
示例5: update
void OBBTest::update(float dt)
{
if (_pick)
return;
_drawAABB->clear();
Mat4 mat = Mat4::IDENTITY;
mat.rotate(Vec3::UNIT_Y, 0.01f);
_obb.transform(mat);
Vec3 corners[8] = {};
_obb.getCorners(corners);
_drawAABB->setPosition3D(_obb._center);
_drawAABB->drawCube(corners, Color4F(0,0,1,1));
}
示例6: draw
void draw() {
drawDevice->clear();
drawDevice->clearFramebuffer();
if(state == TITLE) {
static float t = 1;
t += 0.0005;
drawDevice->runTitleProgram(scene->getTexture("title"),
scene->getTexture("title-space"),
t);
} else if (state == GAME || state == END) {
Mat4 vmat;
Mat4 sky_vmat;
Vec4 side = player_forward.cross(player_vector).normalized();
vmat.setXRow(side);
vmat.setYRow(player_vector);
vmat.setZRow(player_forward);
sky_vmat = Mat4().scaled(10, 10, 10) * vmat;
vmat.translate(Vec4(0, -115, 0));
static float end_gaze = 0.0f;
if(state == END) {
if(end_gaze > -M_PI/2.0f)
end_gaze -= 0.010;
else everyOneDies = true;
}
Mat4 gaze;
gaze.rotate(0.6+end_gaze, Vec4(1, 0, 0));
vmat = gaze * vmat;
sky_vmat = gaze * sky_vmat;
drawDevice->runSkyboxProgram(
scene->getTexture("sky-day"),
scene->getTexture("sky-night"),
sky_vmat, Vec4());
scene->draw(drawDevice, vmat);
for(int j = 0; j < life->GetHeight(); j++) {
for(int i = 0; i < life->GetWidth(); i++) {
if(life->GetCell(i, j)) {
Mat4 mmat;
Vec4 p = life->GetCellSphereCoordinate(i, j);
mmat = stableBasisFromUpVector(p);
mmat.translate(p.scaled(100));
drawDevice->runMeshProgram(scene->getMesh("tree"),
scene->getTexture("tree"),
vmat * mmat);
//plant->position = up.scaled(100.f);
//plant->rotation = randomBasisFromUpVector(up);
//plant->scale = Vec4(2, 2, 2);
}
}
}
}
drawDevice->runOutputProgram(fade);
window->SwapBuffers();
}
示例7: input
void input() {
SDL_PumpEvents();
SDL_Event event;
while(SDL_PollEvent(&event)) {
if(event.type == SDL_QUIT) {
running = false;
}
}
uint8_t *keystate = SDL_GetKeyState(NULL);
static int spaceDownCount = 0;
if(keystate[SDLK_SPACE]) {
spaceDownCount++;
} else {
spaceDownCount = 0;
}
if(state == TITLE) {
if(keystate[SDLK_SPACE]) {
Mix_PlayChannelTimed(-1, Mix_LoadWAV("res/startGame.wav"), 0, -1);
Mix_PlayChannelTimed(-1, music, -1, -1);
state = GAME;
}
} else if(state == GAME) {
if(keystate[SDLK_SPACE] && spaceDownCount == 1) {
running = false;
}
if(keystate[SDLK_UP]) {
player_vector -= player_forward.scaled(0.010);
player_vector.normalize();
player_forward = player_forward.orth(player_vector);
player_forward.normalize();
}
if(keystate[SDLK_DOWN]) {
player_vector += player_forward.scaled(0.007);
player_vector.normalize();
player_forward = player_forward.orth(player_vector);
player_forward.normalize();
}
if(keystate[SDLK_LEFT]) {
Mat4 rot;
rot.rotate(-0.05, player_vector);
player_forward = rot.mul(player_forward);
player_forward.normalize();
}
if(keystate[SDLK_RIGHT]) {
Mat4 rot;
rot.rotate(0.05, player_vector);
player_forward = rot.mul(player_forward);
player_forward.normalize();
}
} else if(state == END) {
if(keystate[SDLK_SPACE] && spaceDownCount == 1) {
running = false;
}
}
}
示例8: onDraw
void CubeTextureVAO::onDraw(const Mat4 &transform, bool transformUpdated, Ref* ss)
{
Director::getInstance()->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
Director::getInstance()->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
Director::getInstance()->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
Director::getInstance()->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
Mat4 modelViewMatrix;
Mat4::createLookAt(Vec3(0, 0, 5), Vec3(0, 0, 0), Vec3(0, -1, 0), &modelViewMatrix);
//modelViewMatrix.translate(0, 0, 0);
static float rotation = -20;
modelViewMatrix.rotate(Vec3(0, 1, 0), CC_DEGREES_TO_RADIANS(rotation));
modelViewMatrix.translate(-1, 2, 0);
Mat4 projectionMatrix;
Mat4::createPerspective(60, 480 / 320, 1.0, 42, &projectionMatrix);
Director::getInstance()->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, projectionMatrix);
Director::getInstance()->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, modelViewMatrix);
#if Use_Custom_Shader
////-------- 使用自定义的shader渲染顶点数据 begin ----
mShaderProgram->use();
mShaderProgram->setUniformsForBuiltins();
#else
//-------- 使用cocos的shader渲染顶点数据 begin ----
GLProgram* glProgram = getGLProgram();
glProgram->use();
glProgram->setUniformsForBuiltins();
//-------- 使用cocos的shader渲染顶点数据 end ----
#endif
// 0 ~ 1 之间波动
float tmp22 = sinf(counter*0.01);
counter++;
//先激活VAO, 在激活VBO,才能获取到缓冲区的映射
//再进行数据修改,然后取消映射
glBindVertexArray(_quadVAO);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
//GLfloat* data2 = NULL;
//data2 = (GLfloat*)glMapBufferRange(GL_ARRAY_BUFFER, (GLintptr)0, (GLsizeiptr)50, GL_MAP_WRITE_BIT);
//if (data2 != (GLfloat*)NULL) {
// data2[9 * 0 + 0] = tmp22; /* Modify X values */
// //data2[9 * 0 + 1] += tmp22; /* Modify Y values */
// data2[9 * 1 + 1] = tmp22; /* Modify Y values */
// glUnmapBuffer(GL_ARRAY_BUFFER);
//}
//else
//{
// int a = 1;
//}
////set sampler
GL::bindTexture2DN(0, _textureID);
//glActiveTexture( GL_TEXTURE0 );
//glBindTexture(GL_TEXTURE_2D, _textureID);
GL::blendFunc(mBlendFunc.src, mBlendFunc.dst);
//glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, 0);
//解除激活
glBindVertexArray(0);
//glUniform1i(_textureUniform, 0); // unnecc in practice
// 0 ~ 1 之间波动
float tmp = sinf(tmpCount*0.01);
//float tmp = sinf(tmpCount*0.005);
tmp = tmp < 0 ? -tmp : tmp;
tmpCount++;
#define g_iWeightNumber 17
//////设置blur权重
//float weightArr[g_iWeightNumber] = { 0.9 };
//GLuint weightLoc = glGetUniformLocation(mShaderProgram->getProgram(), "g_aryWeight");
//glUniform1fv(weightLoc, g_iWeightNumber, weightArr);
////设置横向blur偏移数组
//float offsetArr[g_iWeightNumber * 2] = { 0.1 };
//GLuint offsetLoc = glGetUniformLocation(mShaderProgram->getProgram(), "g_aryVerticalOffset");
//glUniform2fv(offsetLoc, g_iWeightNumber, offsetArr);
#if Use_Custom_Shader
//过滤向量
float hor[2] = { 0.00, 0.00 };
if (touching)
{
hor[0] = tmp;
//.........这里部分代码省略.........
示例9: 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)
{
//.........这里部分代码省略.........
示例10: 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);
}
}
}
}