本文整理汇总了C++中Mtx44::SetToIdentity方法的典型用法代码示例。如果您正苦于以下问题:C++ Mtx44::SetToIdentity方法的具体用法?C++ Mtx44::SetToIdentity怎么用?C++ Mtx44::SetToIdentity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mtx44
的用法示例。
在下文中一共展示了Mtx44::SetToIdentity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: glClear
void Scene2::Render()
{
// clear color every frame
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Mtx44 translate, rotate, scale;
Mtx44 model;
Mtx44 view;
Mtx44 projection;
Mtx44 MVP;
translate.SetToIdentity();
rotate.SetToIdentity();
scale.SetToIdentity();
model.SetToIdentity();
view.SetToIdentity();//camera set at world origin
projection.SetToOrtho(-40, +40, -30, +30, -10, +10); //define the world in a cube by these boundaries
glEnableVertexAttribArray(0); //1st attri buffer: vertices
glEnableVertexAttribArray(1);
scale.SetToScale(10, 10, 10);
rotate.SetToRotation(45, 0, 0, 1);
translate.SetToTranslation(5, 5, 0);
model = translate * rotate *scale; //scale, fcollowed by rotate then translate
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]); //update new shader w MVP
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[GEO_TRIANGLE_1]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer[GEO_TRIANGLE_1]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
//draw triangle
glDrawArrays(GL_TRIANGLES, 0, 6); //starting from vertex 0; 3 vertices = 1 triangle
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[GEO_TRIANGLE_1]);
glVertexAttribPointer
(
0, //Attribute 0. Must match layout in shader. usually 0 is for vertex
3, //size
GL_FLOAT, //type
GL_FALSE, //normalised
0, //stride
0 //array buffer offset
);
glEnableVertexAttribArray(1);//2nd attr buffer: colors
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer[GEO_TRIANGLE_1]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(0);
}
示例2:
void Scene3::Render()
{
// Render VBO here
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Temp variables
Mtx44 translate, rotate, scale;
Mtx44 MVP;
//These will be replaced by matrix stack soon
Mtx44 model;
Mtx44 view;
Mtx44 projection;
//Set all matrices to identity
translate.SetToIdentity();
rotate.SetToIdentity();
scale.SetToIdentity();
model.SetToIdentity();
//Set view matrix using camera settings
view.SetToLookAt(
camera.position.x, camera.position.y, camera.position.z,
camera.target.x, camera.target.y, camera.target.z,
camera.up.x, camera.up.y, camera.up.z
);
//Set projection matrix to perspective mode
projection.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 1000.0f); //FOV, Aspect Ratio, Near plane, Far plane
model.SetToIdentity();
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]);
meshList[GEO_AXES]->Render();
rotate.SetToRotation(rotateAngle, 0, 0, 1);
model = rotate;
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]);
/*meshList[GEO_CUBE]->Render();*/
meshList[GEO_SPHERE]->Render();
/*model.SetToIdentity();
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]);*/
/*meshList[GEO_CIRCLE]->Render();*/
/*meshList[GEO_RING]->Render();*/
}
示例3: Render
void SceneGalaxy::Render()
{
// Render VBO here
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Temp variables
Mtx44 translate, rotate, scale;
Mtx44 MVP;
//These will be replaced by matrix stack soon
Mtx44 model;
Mtx44 view;
Mtx44 projection;
//Set all matrices to identity
translate.SetToIdentity();
rotate.SetToIdentity();
scale.SetToIdentity();
model.SetToIdentity();
//Set view matrix using camera settings
viewStack.LoadIdentity();
viewStack.LookAt(
camera.position.x, camera.position.y, camera.position.z,
camera.target.x, camera.target.y, camera.target.z,
camera.up.x, camera.up.y, camera.up.z
);
//Set projection matrix to perspective mode
projection.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 10000.0f); //FOV, Aspect Ratio, Near plane, Far plane
modelStack.PushMatrix();
modelStack.Translate(light[0].position.x, light[0].position.y, light[0].position.z);
modelStack.Scale(0.1f, 0.1f, 0.1f);
renderMesh(meshList[GEO_LIGHTBALL], false);
modelStack.PopMatrix();
/*modelStack.PushMatrix();
renderMesh(meshList[GEO_AXES], false);
modelStack.PopMatrix();*/
modelStack.PushMatrix();
modelStack.Translate(0, 496.9f, 0);
RenderSkybox();
modelStack.PopMatrix();
RenderXwing();
RenderAsteroid();
RenderMissile();
QuestDetail();
RenderTextOnScreen(meshList[GEO_TEXT], "+", Color(0, 1, 0), 3, 13.1, 9);
std::stringstream playerPos;
playerPos << "X = " << camPosX << " Y = " << camPosY << " Z = " << camPosz;
//RenderTextOnScreen(meshList[GEO_TEXT], playerPos.str(), Color(1, 0, 0), 2, 0, 18);
std::stringstream ss;
ss << "FPS:" << fps << " " << playerPos.str();
RenderTextOnScreen(meshList[GEO_TEXT], ss.str(), Color(0, 1, 0), 3, 0, 19);
}
示例4: DrawChild
void SceneNode::DrawChild(SceneManager *sceneManager, Mesh* debugMesh)
{
sceneManager->RenderPush(gameObject3D->getProperties().modelProperties);
#if _DEBUG
if (debugMesh != NULL)
{
Properties trs;
Mtx44 overall;
overall.SetToIdentity();
trs.scale.SetToScale(Vector3(gameObject3D->getHitbox().getLength(), gameObject3D->getHitbox().getHeight(), gameObject3D->getHitbox().getDepth()));
trs.modelProperties = overall * trs.translation * trs.rotation * trs.scale;
sceneManager->RenderPush(trs.modelProperties);
sceneManager->Render3DMesh(debugMesh, false);
sceneManager->RenderPop();
}
#endif
sceneManager->Render3DMesh(gameObject3D->getMesh(), gameObject3D->getReflectLight());
for (unsigned i = 0; i < childNodes.size(); ++i)
{
this->childNodes[i]->DrawChild(sceneManager, debugMesh);
}
sceneManager->RenderPop();
}
示例5: getProperties
Properties GameObject::getProperties(void)
{
Mtx44 overall;
overall.SetToIdentity();
TRS.modelProperties = overall * TRS.translation * TRS.rotation * TRS.scale;
return TRS;
}
示例6: Render
void SceneSkyBox::Render()
{
// Render VBO here
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//These will be replaced by matrix stack soon
Mtx44 model;
Mtx44 view;
Mtx44 projection;
model.SetToIdentity();
//Set view matrix using camera settings
view.SetToLookAt(
camera.position.x, camera.position.y, camera.position.z,
camera.target.x, camera.target.y, camera.target.z,
camera.up.x, camera.up.y, camera.up.z
);
//Set projection matrix to perspective mode
projection.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 1000.0f); //FOV, Aspect Ratio, Near plane, Far plane
viewStack.LoadIdentity();
viewStack.LookAt(camera.position.x, camera.position.y, camera.position.z,
camera.target.x, camera.target.y, camera.target.z,
camera.up.x, camera.up.y, camera.up.z);
modelStack.LoadIdentity();
Position lightPosition_cameraspace = viewStack.Top() * light[0].position;
glUniform3fv(m_parameters[U_LIGHT0_POSITION], 1, &lightPosition_cameraspace.x);
RenderMesh(meshList[GEO_AXES], false);
modelStack.PushMatrix();
modelStack.Translate(light[0].position.x, light[0].position.y, light[0].position.z);
RenderMesh(meshList[GEO_LIGHTBALL], false);
modelStack.PopMatrix();
/*modelStack.PushMatrix();
modelStack.Scale(10, 10, 10);
RenderMesh(meshList[GEO_QUAD], false);
modelStack.PopMatrix();*/
//Loads the Skybox
RenderSkyBox();
//Mario
modelStack.PushMatrix();
modelStack.Scale(10, 10, 10);
modelStack.Translate(0.0f, 1.f, -0.4f);
modelStack.Rotate(90, 0.f, 1.f, 0.f);
modelStack.Rotate(90, 0.f, 0.f, 1.f);
RenderMesh(meshList[GEO_MARIO], false);
modelStack.PopMatrix();
}
示例7: Init
void CCharacter::Init(const Vector3& pos, const Vector3& target, const Vector3& up)
{
this->setTranslate(pos);
this->setScale(Vector3(1,1,1));
Mtx44 R;
R.SetToIdentity();
this->setRotate(R);
this->m_CurrentWeapon = NULL;
this->health = 100;
m_camera.Init(pos, target, up);
}
示例8: GetRotationMatrix
Mtx44 Camera::GetRotationMatrix(bool x, bool y, bool z) const
{
Mtx44 rotationMatrix;
rotationMatrix.SetToIdentity();
if(z)
{
rotationMatrix = rotationMatrix * transform.rotate.MatrixZ();
}
if(y)
{
rotationMatrix = rotationMatrix * transform.rotate.MatrixY();
}
if(x)
{
rotationMatrix = rotationMatrix * transform.rotate.MatrixX();
}
return rotationMatrix;
}
示例9: Render
void MAINMENU::Render()
{
// Render VBO here
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//These will be replaced by matrix stack soon
Mtx44 model;
Mtx44 view;
Mtx44 projection;
model.SetToIdentity();
//Set view matrix using camera settings
view.SetToLookAt(
camera.position.x, camera.position.y, camera.position.z,
camera.target.x, camera.target.y, camera.target.z,
camera.up.x, camera.up.y, camera.up.z
);
//Set projection matrix to perspective mode
projection.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 1000.0f); //FOV, Aspect Ratio, Near plane, Far plane
viewStack.LoadIdentity();
viewStack.LookAt(camera.position.x, camera.position.y, camera.position.z,
camera.target.x, camera.target.y, camera.target.z,
camera.up.x, camera.up.y, camera.up.z);
modelStack.LoadIdentity();
float i = 3;
for (st = menuList.rbegin(); st != menuList.rend(); ++st)
{
RenderTextOnScreen(meshList[TEXT], *st, Color(1, 1, 1), 3, 3, i ++);
}
if (c_UserInterface::GetEnum()->UI == START)
{
RenderTextOnScreen(meshList[TEXT], ">", Color(1, 1, 1), 3, 2, 5);
}
if (c_UserInterface::GetEnum()->UI == OPTIONS)
{
RenderTextOnScreen(meshList[TEXT], ">", Color(1, 1, 1), 3, 2, 4);
}
if (c_UserInterface::GetEnum()->UI == EXIT)
{
RenderTextOnScreen(meshList[TEXT], ">", Color(1, 1, 1), 3, 2, 3);
}
}
示例10: lightDir
void PLANET3::Render()
{
// Render VBO here
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//These will be replaced by matrix stack soon
Mtx44 model;
Mtx44 view;
Mtx44 projection;
model.SetToIdentity();
//Set view matrix using camera settings
view.SetToLookAt(
camera.position.x, camera.position.y, camera.position.z,
camera.target.x, camera.target.y, camera.target.z,
camera.up.x, camera.up.y, camera.up.z
);
//Set projection matrix to perspective mode
projection.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 1000.0f); //FOV, Aspect Ratio, Near plane, Far plane
viewStack.LoadIdentity();
viewStack.LookAt(camera.position.x, camera.position.y, camera.position.z,
camera.target.x, camera.target.y, camera.target.z,
camera.up.x, camera.up.y, camera.up.z);
modelStack.LoadIdentity();
Position lightPosition_cameraspace = viewStack.Top() * light[0].position;
glUniform3fv(m_parameters[U_LIGHT0_POSITION], 1, &lightPosition_cameraspace.x);
Vector3 lightDir(light[1].position.x, light[1].position.y, light[1].position.z);
Vector3 lightDirection_cameraspace2 = viewStack.Top() * lightDir;
glUniform3fv(m_parameters[U_LIGHT1_POSITION], 1, &lightDirection_cameraspace2.x);
RenderMesh(meshList[GEO_AXES], false);
modelStack.PushMatrix();
modelStack.Translate(light[0].position.x, light[0].position.y, light[0].position.z);
RenderMesh(meshList[GEO_LIGHTBALL], false);
modelStack.PopMatrix();
RenderSkyBox();
}
示例11:
void Assignment1::Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Mtx44 translate, rotate, scale;
Mtx44 model;
Mtx44 view;
Mtx44 projection;
Mtx44 MVP;
translate.SetToIdentity();
rotate.SetToIdentity();
scale.SetToIdentity();
model.SetToIdentity();
view.SetToIdentity(); //no need camera for now, set it at World's origin
projection.SetToOrtho(-40, 40, -30, 30, -10, 10); //Our world is a cube defined by these boundaries
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
for (int i = 0; i < 100; i++)
{
//Blood Rain
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[GEO_DOOR]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer[GEO_DOOR]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
scale.SetToScale(0.2, 1, 0);
rotate.SetToRotation(0, 0, 0, 1);
translate.SetToTranslation(rainpositionx[i], rainpositiony[i], 1);
model = translate * rotate * scale;
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]); //update the shader with the new mvp
glDrawArrays(GL_TRIANGLES, 0, 6);
}
//Bird Body
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[GEO_BIRD]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer[GEO_BIRD]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
scale.SetToScale(3, 3, 0);
rotate.SetToRotation(0, 0, 0, 1);
translate.SetToTranslation(translateX2 + 3, 15, 0);
model = translate * rotate * scale;
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]); //update the shader with the new mvp
glDrawArrays(GL_TRIANGLES, 0, 3);
//Bird Beak
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[GEO_BIRD]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer[GEO_BIRD]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
scale.SetToScale(2, 1, 0);
rotate.SetToRotation(0, 0, 0, 1);
translate.SetToTranslation(translateX2 + 6, 15, 0);
model = translate * rotate * scale;
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]); //update the shader with the new mvp
glDrawArrays(GL_TRIANGLES, 0, 3);
//Bird Body 2
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[GEO_BIRD]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer[GEO_BIRD]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
scale.SetToScale(3, 3, 0);
rotate.SetToRotation(0, 0, 0, 1);
translate.SetToTranslation(translateX2 + 9, 10, 0);
model = translate * rotate * scale;
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]); //update the shader with the new mvp
glDrawArrays(GL_TRIANGLES, 0, 3);
//Bird Beak 2
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[GEO_BIRD]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer[GEO_BIRD]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
scale.SetToScale(2, 1, 0);
rotate.SetToRotation(0, 0, 0, 1);
translate.SetToTranslation(translateX2 + 12, 10, 0);
model = translate * rotate * scale;
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]); //update the shader with the new mvp
glDrawArrays(GL_TRIANGLES, 0, 3);
//Moon
for (int numTriangles = 0; numTriangles < 360; numTriangles++)
{
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[GEO_TRIANGLE_1]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer[GEO_TRIANGLE_1]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
scale.SetToScale(scaleAll, scaleAll, 0);
rotate.SetToRotation(static_cast<float>(numTriangles), 0, 0, 1);
translate.SetToTranslation(35, 25, 0);
model = translate * rotate * scale; //scale, followed by rotate, then lastly translate
MVP = projection * view * model; // Remember, matrix multiplication is the other way round
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]); //update the shader with the new mvp
glDrawArrays(GL_TRIANGLES, 0, 3);
//.........这里部分代码省略.........
示例12: Color
void Assignment3::Render()
{
// Render VBO here
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Temp variables
Mtx44 translate, rotate, scale;
Mtx44 MVP;
//These will be replaced by matrix stack soon
Mtx44 model;
Mtx44 view;
Mtx44 projection;
//Set all matrices to identity
translate.SetToIdentity();
rotate.SetToIdentity();
scale.SetToIdentity();
model.SetToIdentity();
//Set view matrix using camera settings
viewStack.LoadIdentity();
viewStack.LookAt(
camera.position.x, camera.position.y, camera.position.z,
camera.target.x, camera.target.y, camera.target.z,
camera.up.x, camera.up.y, camera.up.z
);
//Set projection matrix to perspective mode
projection.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 10000.0f); //FOV, Aspect Ratio, Near plane, Far plane
lighting();
lighting2();
modelStack.PushMatrix();
modelStack.Translate(light[0].position.x, light[0].position.y, light[0].position.z);
modelStack.Scale(0.1f, 0.1f, 0.1f);
renderMesh(meshList[GEO_LIGHTBALL], false);
modelStack.PopMatrix();
/*modelStack.PushMatrix();
renderMesh(meshList[GEO_AXES], false);
modelStack.PopMatrix();*/
modelStack.PushMatrix();
modelStack.Translate(boxX, 496.9, boxZ);
RenderSkybox();
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(snowWallCoord.x, 0, snowWallCoord.z);
modelStack.Rotate(-90, 0, 1, 0);
//modelStack.Scale(10, 10, 10);
renderMesh(meshList[GEO_SNOWWALL], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(snowBallCoord.x, snowBallCoord.y, snowBallCoord.z);
modelStack.Scale(0.2, 0.2, 0.2);
renderMesh(meshList[GEO_SNOWBALLPILE], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(snowBallCoord1.x, snowBallCoord1.y, snowBallCoord1.z);
modelStack.Scale(0.2, 0.2, 0.2);
renderMesh(meshList[GEO_SNOWBALLPILE], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(snowBallCoord2.x, snowBallCoord2.y, snowBallCoord2.z);
modelStack.Scale(0.2, 0.2, 0.2);
renderMesh(meshList[GEO_SNOWBALLPILE], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(snowBallCoord5.x, snowBallCoord5.y, snowBallCoord5.z);
modelStack.Scale(0.2, 0.2, 0.2);
renderMesh(meshList[GEO_SNOWBALLPILE], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(snowBallCoord6.x, snowBallCoord6.y, snowBallCoord6.z);
modelStack.Scale(0.2, 0.2, 0.2);
renderMesh(meshList[GEO_SNOWBALLPILE], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(robbyCoord.x, robbyCoord.y, robbyCoord.z);
modelStack.Scale(0.5, 0.5, 0.5);
modelStack.Rotate(robbyRotate, 0, 1, 0);
modelStack.Rotate(-90, 0, 1, 0);
renderMesh(meshList[GEO_ROBBY], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(0, -1, 0);
modelStack.Rotate(-90, 0, 1, 0);
modelStack.Scale(1500, 1500, 1500);
renderMesh(meshList[GEO_BOTTOM], true);
modelStack.PopMatrix();
//.........这里部分代码省略.........
示例13: lightDir
void PLANET5::Render()
{
// Render VBO here
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//These will be replaced by matrix stack soon
Mtx44 model;
Mtx44 view;
Mtx44 projection;
model.SetToIdentity();
//Set view matrix using camera settings
view.SetToLookAt(
camera.position.x, camera.position.y, camera.position.z,
camera.target.x, camera.target.y, camera.target.z,
camera.up.x, camera.up.y, camera.up.z
);
//Set projection matrix to perspective mode
projection.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 1000.0f); //FOV, Aspect Ratio, Near plane, Far plane
viewStack.LoadIdentity();
viewStack.LookAt(camera.position.x, camera.position.y, camera.position.z,
camera.target.x, camera.target.y, camera.target.z,
camera.up.x, camera.up.y, camera.up.z);
modelStack.LoadIdentity();
Position lightPosition_cameraspace = viewStack.Top() * light[0].position;
glUniform3fv(m_parameters[U_LIGHT0_POSITION], 1, &lightPosition_cameraspace.x);
Vector3 lightDir(light[1].position.x, light[1].position.y, light[1].position.z);
Vector3 lightDirection_cameraspace2 = viewStack.Top() * lightDir;
glUniform3fv(m_parameters[U_LIGHT1_POSITION], 1, &lightDirection_cameraspace2.x);
RenderMesh(meshList[GEO_AXES], false);
/*modelStack.PushMatrix();
modelStack.Translate(light[0].position.x, light[0].position.y, light[0].position.z);
RenderMesh(meshList[GEO_LIGHTBALL], false);
modelStack.PopMatrix();
/* modelStack.PushMatrix();
modelStack.Translate(0.f, 0.f, 0.f);
RenderMesh(meshList[ASTEROID], false);
modelStack.PopMatrix();*/
std::ostringstream fps;
fps << camera.position.x << " " << camera.position.y << " " << camera.position.z;
std::ostringstream fpss;
fpss << camera.target.x << " " << camera.target.y << " " << camera.target.z;
RenderSkyBox();
modelStack.PushMatrix();
modelStack.Translate(0.0f, -35.0f, 0.f);
modelStack.Rotate(rotatespin - 45, 0, 1, 0);
modelStack.Scale(22.0f, 24.0f, 22.0f);
RenderMesh(meshList[SPIN], false);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(0.0f, 8.0f, 0.f);
modelStack.Scale(10.0f, 10.f, 10.f);
RenderMesh(meshList[SPINCAP], false);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(5.0f, translateButton - 6.f, 43.5f);
modelStack.Rotate(25.0f, 1, 0, 0);
modelStack.Scale(2.f, 3.0f, 2.f);
RenderMesh(meshList[BUTTON], false);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(5.0f, -6.0f, 45.0f);
modelStack.Rotate(-90.0f, 0, 1, 0);
modelStack.Scale(2.0f, 2.0f, 2.0f);
RenderMesh(meshList[BUTTONSTAND], false);
modelStack.PopMatrix();
//////////////////////GEMS ARE OUTRAGREOUS//////////////////////////
modelStack.PushMatrix();
modelStack.Translate(-50.0f, translategem1 - 5.7f, -81.5f);
modelStack.Rotate(22.0f, 1, 0, 0);
modelStack.Scale(2.f, 3.0f, 2.f);
RenderMesh(meshList[BUTTON], false);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(-50.0f, -6.0f, -80.0f);
modelStack.Rotate(-90.0f, 0, 1, 0);
modelStack.Scale(2.0f, 2.0f, 2.0f);
RenderMesh(meshList[BUTTONSTAND], false);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(-50.0f, flygem1, -90.0f);
modelStack.Rotate(rotategem1, 0, 1, 0);
//.........这里部分代码省略.........
示例14:
void Assignment1::Render()
{
// Render VBO here
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Mtx44 translate, rotate, scale;
Mtx44 model;
Mtx44 view;
Mtx44 projection;
Mtx44 MVP;
translate.SetToIdentity();
rotate.SetToIdentity();
scale.SetToIdentity();
model.SetToIdentity();
view.SetToIdentity();
projection.SetToOrtho(-40, 40, -30, 30, -10, 10);
glEnableVertexAttribArray(0);// 1st attribute buffer: vertices
glEnableVertexAttribArray(1); // 2nd attribute buffer : colors
//<landscape>
scale.SetToScale(125, 125, 125);
rotate.SetToRotation(0, 0, 0, 1);
translate.SetToTranslation(0,-125,1);
model = translate * rotate * scale;
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[LANDSCAPE_1]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer[LANDSCAPE_1]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 5);
model.SetToIdentity();
scale.SetToScale(20, 20, 20);
rotate.SetToRotation(0, 0, 0, 1);
translate.SetToTranslation(25, 0, 0);
model = translate * rotate * scale;
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[LANDSCAPE_1]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer[LANDSCAPE_1]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 5);
model.SetToIdentity();
scale.SetToScale(50, 20, 20);
rotate.SetToRotation(0, 0, 0, 1);
translate.SetToTranslation(10, -5, -0.5);
model = translate * rotate * scale;
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[LANDSCAPE_1]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer[LANDSCAPE_1]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 5);
//</landscape>
//<cloud>
scale.SetToScale(10, 10, 10);
rotate.SetToRotation(25, 0, 0, 1);
translate.SetToTranslation(cloudMovement , 25, 0.5f);
model = translate * rotate * scale;
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[CLOUDS_2]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer[CLOUDS_2]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 12);
//</cloud>
//<sun>
scale.SetToScale(5, 5, 5);
rotate.SetToRotation(rotateAngle, 0, 0, 1);
translate.SetToTranslation(-25, 20, 0);
model = translate * rotate * scale;
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[SUN_3]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer[SUN_3]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 9);
//</sun>
//<explosion>
scale.SetToScale(explosionSize, explosionSize, explosionSize);
rotate.SetToRotation(explosionRotation, 0, 0, 1);
translate.SetToTranslation(-25, 20, 0);
model = translate * rotate * scale;
MVP = projection * view * model;
glUniformMatrix4fv(m_parameters[U_MVP], 1, GL_FALSE, &MVP.a[0]);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer[EXPLOSION_4]);
//.........这里部分代码省略.........
示例15:
void SceneLight2::Render()
{
// Render VBO here
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Temp variables
Mtx44 translate, rotate, scale;
Mtx44 MVP;
//These will be replaced by matrix stack soon
Mtx44 model;
Mtx44 view;
Mtx44 projection;
//Set all matrices to identity
translate.SetToIdentity();
rotate.SetToIdentity();
scale.SetToIdentity();
model.SetToIdentity();
//Set view matrix using camera settings
viewStack.LoadIdentity();
viewStack.LookAt(
camera.position.x, camera.position.y, camera.position.z,
camera.target.x, camera.target.y, camera.target.z,
camera.up.x, camera.up.y, camera.up.z
);
//Set projection matrix to perspective mode
projection.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 1000.0f); //FOV, Aspect Ratio, Near plane, Far plane
lighting();
lighting2();
modelStack.PushMatrix();
modelStack.Translate(light[0].position.x, light[0].position.y, light[0].position.z);
modelStack.Scale(0.5f, 0.5f, 0.5f);
renderMesh(meshList[GEO_LIGHTBALL], false);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(light[1].position.x, light[1].position.y, light[1].position.z);
modelStack.Scale(0.5f, 0.5f, 0.5f);
renderMesh(meshList[GEO_LIGHTBALL], false);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(0, 0, 0);
renderMesh(meshList[GEO_SPHERE], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(2, 0, 0);
renderMesh(meshList[GEO_SPHERE1], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(-2, 0, 0);
renderMesh(meshList[GEO_SPHERE2], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(2, 0, 2);
renderMesh(meshList[GEO_SPHERE3], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(-2, 0, 2);
renderMesh(meshList[GEO_SPHERE4], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(0, 0, 2);
renderMesh(meshList[GEO_SPHERE5], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(0, 0, -2);
renderMesh(meshList[GEO_SPHERE6], true);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(2, 0, -2);
renderMesh(meshList[GEO_SPHERE7], true);
modelStack.PopMatrix();
/*modelStack.PushMatrix();
modelStack.Translate(-2, 0, -2);
renderMesh(meshList[GEO_CYLINDER], true);
modelStack.PopMatrix();*/
//modelStack.PopMatrix();
modelStack.PushMatrix();
renderMesh(meshList[GEO_AXES], false);
modelStack.PopMatrix();
modelStack.PushMatrix();
modelStack.Translate(0, -1, 0);
modelStack.Scale(10, 10, 10);
renderMesh(meshList[GEO_QUAD], true);
modelStack.PopMatrix();
}