mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-25 12:01:21 +00:00
Fixing geometry bug and adding backface culling.
This commit is contained in:
parent
b94626fb5d
commit
df30603767
@ -88,14 +88,15 @@ void Viewer::draw()
|
|||||||
|
|
||||||
// stack<QMatrix4x4> modelStack;
|
// stack<QMatrix4x4> modelStack;
|
||||||
modelViewMatrix.scale(0.95);
|
modelViewMatrix.scale(0.95);
|
||||||
modelViewMatrix.rotate(45, 0, 1, 0);
|
|
||||||
|
|
||||||
rot = QQuaternion::fromAxisAndAngle(1, 0, 1, 90/60 * frame);
|
//modelViewMatrix.rotate(45, 0, 1, 0);
|
||||||
// uncomment this and the cube translation in init()
|
// uncomment this and the cube translation in init()
|
||||||
// to see the cube spin
|
// to see the cube spin
|
||||||
|
/*rot = QQuaternion::fromAxisAndAngle(1, 0, 1, 90/60 * frame);
|
||||||
modelViewMatrix.rotate(rot);
|
modelViewMatrix.rotate(rot);
|
||||||
projectionMatrix.translate(0, -5, 0);
|
projectionMatrix.translate(0, -5, 0);
|
||||||
projectionMatrix.rotate(15, 1, 0, 0);
|
projectionMatrix.rotate(15, 1, 0, 0);//*/
|
||||||
|
|
||||||
m_program->setUniformValue(m_projMatrixLocation, projectionMatrix);
|
m_program->setUniformValue(m_projMatrixLocation, projectionMatrix);
|
||||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||||
|
|
||||||
@ -210,11 +211,8 @@ void Viewer::init()
|
|||||||
{
|
{
|
||||||
// We want to restrict ourselves to a 2D viewer.
|
// We want to restrict ourselves to a 2D viewer.
|
||||||
//camera()->setType(qglviewer::Camera::ORTHOGRAPHIC);
|
//camera()->setType(qglviewer::Camera::ORTHOGRAPHIC);
|
||||||
setMouseBinding(Qt::NoModifier, Qt::LeftButton, CAMERA, SCREEN_ROTATE);
|
//setMouseBinding(Qt::NoModifier, Qt::LeftButton, CAMERA, SCREEN_ROTATE);
|
||||||
//setMouseBinding(Qt::AltModifier, Qt::LeftButton, CAMERA, NO_MOUSE_ACTION);//*/
|
//setMouseBinding(Qt::AltModifier, Qt::LeftButton, CAMERA, NO_MOUSE_ACTION);//*/
|
||||||
//setMouseBinding(Qt::NoModifier, Qt::MouseButton(Qt::LeftButton + Qt::MidButton), CAMERA, NO_MOUSE_ACTION);
|
|
||||||
//setMouseBinding(Qt::ControlModifier, Qt::MouseButton(Qt::LeftButton + Qt::MidButton), CAMERA, NO_MOUSE_ACTION);
|
|
||||||
//setMouseBinding(Qt::ShiftModifier, Qt::MouseButton(Qt::LeftButton + Qt::MidButton), CAMERA, NO_MOUSE_ACTION);
|
|
||||||
|
|
||||||
// Our scene will be from -5 to 5 in X and Y (the grid will be 10x10).
|
// Our scene will be from -5 to 5 in X and Y (the grid will be 10x10).
|
||||||
setSceneRadius(5);
|
setSceneRadius(5);
|
||||||
@ -228,15 +226,19 @@ void Viewer::init()
|
|||||||
initShaders();
|
initShaders();
|
||||||
initGeometries();
|
initGeometries();
|
||||||
|
|
||||||
|
{
|
||||||
Shape* cube = new Cube();
|
Shape* cube = new Cube();
|
||||||
cube->setColor(*activeColor);
|
cube->setColor(*activeColor);
|
||||||
|
|
||||||
// uncomment this and the quaternion transformation in draw()
|
// uncomment this and the quaternion transformation in draw()
|
||||||
// to see the cube rotate.
|
// to see the cube rotate. This is how we can easily make the sun.
|
||||||
// cube->transform.translate(3, 0, 0);
|
// cube->transform.translate(3, 0, 0);
|
||||||
|
|
||||||
SceneGroup *c = new SceneGroup();
|
SceneGroup *c = new SceneGroup();
|
||||||
c->addChild(cube);
|
c->addChild(cube);
|
||||||
root.addChild(c);
|
root.addChild(c);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Viewer::initShaders()
|
void Viewer::initShaders()
|
||||||
{
|
{
|
||||||
@ -275,6 +277,9 @@ void Viewer::initGeometries()
|
|||||||
{
|
{
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glEnable( GL_BLEND );
|
glEnable( GL_BLEND );
|
||||||
|
glEnable( GL_CULL_FACE );
|
||||||
|
glFrontFace( GL_CCW );
|
||||||
|
glCullFace( GL_BACK );
|
||||||
glClearColor(0.0,0.0,0.0,0.0);
|
glClearColor(0.0,0.0,0.0,0.0);
|
||||||
|
|
||||||
// Create our VertexArrays Objects and VertexBuffer Objects
|
// Create our VertexArrays Objects and VertexBuffer Objects
|
||||||
@ -300,8 +305,8 @@ void Viewer::initGeometries()
|
|||||||
{ -0.5, 0.5, 0.5 }, { 0.5, 0.5, 0.5 }, { 0.5, 0.5, -0.5 },
|
{ -0.5, 0.5, 0.5 }, { 0.5, 0.5, 0.5 }, { 0.5, 0.5, -0.5 },
|
||||||
{ 0.5, 0.5, -0.5 }, { -0.5, 0.5, -0.5 }, { -0.5, 0.5, 0.5 },
|
{ 0.5, 0.5, -0.5 }, { -0.5, 0.5, -0.5 }, { -0.5, 0.5, 0.5 },
|
||||||
//Bottom
|
//Bottom
|
||||||
{ -0.5, -0.5, 0.5 }, { 0.5, -0.5, 0.5 }, { 0.5, -0.5, -0.5 },
|
{ -0.5, -0.5, 0.5 }, { 0.5, -0.5, -0.5 }, { 0.5, -0.5, 0.5 },
|
||||||
{ 0.5, -0.5, -0.5 }, { -0.5, -0.5, -0.5 }, { -0.5, -0.5, 0.5 }
|
{ 0.5, -0.5, -0.5 }, { -0.5, -0.5, 0.5 }, { -0.5, -0.5, -0.5 }
|
||||||
};
|
};
|
||||||
|
|
||||||
glBindVertexArray(m_VAOs[VAO_Cube]);
|
glBindVertexArray(m_VAOs[VAO_Cube]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user