mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
dakfjgkabfiharblkhjadrgkrw
This commit is contained in:
parent
ad860abf7d
commit
1a8976cafd
@ -173,6 +173,36 @@ void Viewer::draw()
|
|||||||
//float rotAngle = (frame * angle_mult) % 360;
|
//float rotAngle = (frame * angle_mult) % 360;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Viewer::drawUi(){
|
||||||
|
|
||||||
|
glCullFace(GL_FRONT);
|
||||||
|
glClear(GL_DEPTH_BUFFER_BIT); // make ui always on top
|
||||||
|
|
||||||
|
QMatrix4x4 projectionMatrix;
|
||||||
|
QMatrix4x4 uiViewMatrix;
|
||||||
|
|
||||||
|
uiViewMatrix.translate(0, -1.5, -4);
|
||||||
|
camera()->getProjectionMatrix(projectionMatrix);
|
||||||
|
|
||||||
|
float colorMult = 0.2 + std::fabs(0.8 * cos(std::fmod(angle_mult * frame + 300, 360) / 360 * M_PI));
|
||||||
|
|
||||||
|
m_program->setUniformValue(m_isSkyLoc, false);
|
||||||
|
m_program->setUniformValue(m_drawTextLoc, true);
|
||||||
|
m_program->setUniformValue(m_isLightLoc, true);
|
||||||
|
|
||||||
|
glBindVertexArray(m_VAOs[VAO_Cube]);
|
||||||
|
uiViewMatrix.scale(.25, .25, .01);
|
||||||
|
uiViewMatrix.translate(-TEX_LENGTH/2.0, 0, 0);
|
||||||
|
for(int i = 0; i<TEX_LENGTH; i++)
|
||||||
|
{
|
||||||
|
TexturePrograms[i]->bind();
|
||||||
|
m_program->setUniformValue(m_mvMatrixLocation, uiViewMatrix);
|
||||||
|
uiViewMatrix.translate(1.2, 0, 0);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Viewer::mouseMoveEvent(QMouseEvent* e) {
|
void Viewer::mouseMoveEvent(QMouseEvent* e) {
|
||||||
//cout << "Viewer::mouseMoveEvent(QMouseEvent* e)" << endl;
|
//cout << "Viewer::mouseMoveEvent(QMouseEvent* e)" << endl;
|
||||||
// Normal QGLViewer behavior.
|
// Normal QGLViewer behavior.
|
||||||
@ -189,31 +219,32 @@ void Viewer::mousePressEvent(QMouseEvent* e) {
|
|||||||
|
|
||||||
PickedGeom selectedGeom = pickGeom(x, y);
|
PickedGeom selectedGeom = pickGeom(x, y);
|
||||||
|
|
||||||
if(!selectedGeom.position.isIdentity() && e->modifiers().testFlag(Qt::ControlModifier))
|
if(!selectedGeom.position.isIdentity() && e->modifiers().testFlag(Qt::ControlModifier))
|
||||||
{
|
{
|
||||||
if(selectedObj.shape->getParent() != nullptr) {
|
std::cout << "Selecting cube" << endl;
|
||||||
// Remove previous selection
|
if(selectedObj.shape->getParent() != nullptr) {
|
||||||
selectedObj.shape->getParent()->getChildren()->erase(
|
// Remove previous selection
|
||||||
std::remove(selectedObj.shape->getParent()->getChildren()->begin(),
|
selectedObj.shape->getParent()->getChildren()->erase(
|
||||||
selectedObj.shape->getParent()->getChildren()->end(),
|
std::remove(selectedObj.shape->getParent()->getChildren()->begin(),
|
||||||
selection),
|
selectedObj.shape->getParent()->getChildren()->end(),
|
||||||
selectedObj.shape->getParent()->getChildren()->end());
|
selection),
|
||||||
}
|
selectedObj.shape->getParent()->getChildren()->end());
|
||||||
selectedObj.shape = selectedGeom.shape;
|
}
|
||||||
selectedObj.shape->getParent()->addChild(selection);
|
selectedObj.shape = selectedGeom.shape;
|
||||||
cubeSelected(true);
|
selectedObj.shape->getParent()->addChild(selection);
|
||||||
}
|
cubeSelected(true);
|
||||||
|
}
|
||||||
|
|
||||||
if(!selectedGeom.position.isIdentity() && e->modifiers().testFlag(Qt::ShiftModifier))
|
if(!selectedGeom.position.isIdentity() && e->modifiers().testFlag(Qt::ShiftModifier))
|
||||||
{
|
{
|
||||||
Cube* c = new Cube;
|
Cube* c = new Cube;
|
||||||
c->setType(TEX_WOODFLOOR);
|
c->setType(selectedTexture);
|
||||||
SceneGroup* container = new SceneGroup;
|
SceneGroup* container = new SceneGroup;
|
||||||
//selectedPosition.copyDataTo(container->transform.data());
|
container->transform = selectedGeom.position;
|
||||||
container->transform = selectedGeom.position;
|
container->addChild(c);
|
||||||
container->addChild(c);
|
root.addChild(container);
|
||||||
root.addChild(container);
|
}
|
||||||
} else QGLViewer::mousePressEvent(e);
|
else QGLViewer::mousePressEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::mouseReleaseEvent(QMouseEvent* e) {
|
void Viewer::mouseReleaseEvent(QMouseEvent* e) {
|
||||||
@ -682,7 +713,9 @@ void Viewer::visit(Cube &s)
|
|||||||
for(int i =0; i<faces; i++)
|
for(int i =0; i<faces; i++)
|
||||||
{
|
{
|
||||||
faceColor->setRgb(s.getColor().rgb() + i);
|
faceColor->setRgb(s.getColor().rgb() + i);
|
||||||
m_program->setUniformValue(m_colorLocation, *faceColor);
|
m_program->setUniformValue(m_colorLocation, *faceColor);/*/
|
||||||
|
QColor* sideColor = new QColor(sideColors[i]);
|
||||||
|
m_program->setUniformValue(m_colorLocation, *sideColor);//*/
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, i*6, 6);
|
glDrawArrays(GL_TRIANGLES, i*6, 6);
|
||||||
}
|
}
|
||||||
@ -802,7 +835,6 @@ void Viewer::deleteSelected() {
|
|||||||
cubeSelected(false);
|
cubeSelected(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Viewer::changeColor(QColor c){
|
void Viewer::changeColor(QColor c){
|
||||||
if(activeCell->getChildren()->size()){
|
if(activeCell->getChildren()->size()){
|
||||||
Shape* shape = dynamic_cast<Shape*> (activeCell->childAt(0));
|
Shape* shape = dynamic_cast<Shape*> (activeCell->childAt(0));
|
||||||
@ -825,34 +857,6 @@ void Viewer::startAniumation(){}
|
|||||||
void Viewer::stopAnimation(){}
|
void Viewer::stopAnimation(){}
|
||||||
|
|
||||||
|
|
||||||
void Viewer::drawUi(){
|
|
||||||
|
|
||||||
glCullFace(GL_FRONT);
|
|
||||||
|
|
||||||
QMatrix4x4 projectionMatrix;
|
|
||||||
QMatrix4x4 uiViewMatrix;
|
|
||||||
|
|
||||||
uiViewMatrix.translate(0, -1.5, -4);
|
|
||||||
camera()->getProjectionMatrix(projectionMatrix);
|
|
||||||
|
|
||||||
float colorMult = 0.2 + std::fabs(0.8 * cos(std::fmod(angle_mult * frame + 300, 360) / 360 * M_PI));
|
|
||||||
|
|
||||||
m_program->setUniformValue(m_isSkyLoc, false);
|
|
||||||
m_program->setUniformValue(m_drawTextLoc, true);
|
|
||||||
m_program->setUniformValue(m_isLightLoc, true);
|
|
||||||
|
|
||||||
glBindVertexArray(m_VAOs[VAO_Cube]);
|
|
||||||
uiViewMatrix.scale(.25, .25, .01);
|
|
||||||
uiViewMatrix.translate(-TEX_LENGTH/2.0, 0, 0);
|
|
||||||
for(int i = 0; i<TEX_LENGTH; i++)
|
|
||||||
{
|
|
||||||
TexturePrograms[i]->bind();
|
|
||||||
m_program->setUniformValue(m_mvMatrixLocation, uiViewMatrix);
|
|
||||||
uiViewMatrix.translate(1.2, 0, 0);
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PickedGeom Viewer::pickGeom(int x, int y){
|
PickedGeom Viewer::pickGeom(int x, int y){
|
||||||
@ -863,6 +867,7 @@ PickedGeom Viewer::pickGeom(int x, int y){
|
|||||||
m_program->setUniformValue(m_isPickingModeLoc, true);
|
m_program->setUniformValue(m_isPickingModeLoc, true);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
|
||||||
isPickingActivated = true;
|
isPickingActivated = true;
|
||||||
|
|
||||||
@ -916,9 +921,9 @@ PickedGeom Viewer::pickGeom(int x, int y){
|
|||||||
QColor* pickedColor = new QColor();
|
QColor* pickedColor = new QColor();
|
||||||
|
|
||||||
pickedColor->setRgb(pdata[512-j][i][0], pdata[512-j][i][1], pdata[512-j][i][2]);
|
pickedColor->setRgb(pdata[512-j][i][0], pdata[512-j][i][1], pdata[512-j][i][2]);
|
||||||
if(i==256 && j == 256) pickedColor->setRgba(0x88FFFFFF);
|
if(i==256 && j == 256) pickedColor->setRgba(0xFFFFFFFF);
|
||||||
if(i==256 && j == 256)
|
if(i==256 && j == 256)
|
||||||
std::cout<<"--- Color under cursor: " << (int)pdata[j][i][0] <<" "<< (int)pdata[j][i][1] <<" "<< (int)pdata[j][i][2] << endl;
|
std::cout<<"--- Color under cursor: " << (int)pdata[j][i][0] <<" "<< (int)pdata[j][i][1] <<" "<< (int)pdata[j][i][2] <<" "<< (int)pdata[j][i][3] << endl;
|
||||||
pickedColor->setAlpha(255);
|
pickedColor->setAlpha(255);
|
||||||
im->setPixelColor(i, j, pickedColor->rgb());
|
im->setPixelColor(i, j, pickedColor->rgb());
|
||||||
}
|
}
|
||||||
@ -927,9 +932,9 @@ PickedGeom Viewer::pickGeom(int x, int y){
|
|||||||
|
|
||||||
glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
|
glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
|
||||||
|
|
||||||
QColor* pickedColor = new QColor(pixelData[0], pixelData[1], pixelData[2]);
|
QColor* pickedColor = new QColor(pixelData[0], pixelData[1], pixelData[2], pixelData[3]);
|
||||||
unsigned int pickedInt = pickedColor->rgb() % 0x1000000; // rgb returns ARGB. go figure.
|
unsigned int pickedInt = pickedColor->rgb() % 0x1000000; // rgb returns ARGB. go figure.
|
||||||
//std::cout << "Picked " << pickedInt << endl;
|
std::cout << "Picked " << pickedInt << endl;
|
||||||
|
|
||||||
QMatrix4x4 pickedPosition = mapColorToPosition.value(pickedInt, identityMatrix);
|
QMatrix4x4 pickedPosition = mapColorToPosition.value(pickedInt, identityMatrix);
|
||||||
Shape* pickedShape = mapColorToShape.value(pickedInt);
|
Shape* pickedShape = mapColorToShape.value(pickedInt);
|
||||||
|
|||||||
@ -162,6 +162,7 @@ private:
|
|||||||
|
|
||||||
TEX_LENGTH
|
TEX_LENGTH
|
||||||
};
|
};
|
||||||
|
unsigned int selectedTexture = TEX_WOODFLOOR;
|
||||||
|
|
||||||
QString TexturePaths[TEX_LENGTH] = {
|
QString TexturePaths[TEX_LENGTH] = {
|
||||||
"src/data/dry_ground.jpg",
|
"src/data/dry_ground.jpg",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user