mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
Hierarchy Transform (Wonky Delete)
This commit is contained in:
parent
8a54b8810d
commit
9957a0bae0
@ -56,6 +56,9 @@ namespace
|
|||||||
const int numTriSphere = numColSphere*(numRowSphere-1)*2 + 2*numColSphere;
|
const int numTriSphere = numColSphere*(numRowSphere-1)*2 + 2*numColSphere;
|
||||||
|
|
||||||
const GLuint particleLimit = 1024;
|
const GLuint particleLimit = 1024;
|
||||||
|
QMap<QRgb, QMatrix4x4> mapColorToPosition;
|
||||||
|
QMap<QRgb, Shape*> mapColorToShape;
|
||||||
|
QRgb currentPickerColor;
|
||||||
|
|
||||||
int m_lDirectionLocation;
|
int m_lDirectionLocation;
|
||||||
int m_normalMatrixLoc;
|
int m_normalMatrixLoc;
|
||||||
@ -435,7 +438,7 @@ void Viewer::mousePressEvent(QMouseEvent* e) {
|
|||||||
SceneGroup* container = new SceneGroup;
|
SceneGroup* container = new SceneGroup;
|
||||||
container->transform = selectedGeom.position;
|
container->transform = selectedGeom.position;
|
||||||
container->addChild(c);
|
container->addChild(c);
|
||||||
root.addChild(container);
|
selectedGeom.shape->getParent()->addChild(container);
|
||||||
startSwingAnimation();
|
startSwingAnimation();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@ -1049,6 +1052,27 @@ void Viewer::visit(Cube &s)
|
|||||||
QMatrix4x4 modelViewMatrix = modelStack.top() * QMatrix4x4(s.transform);
|
QMatrix4x4 modelViewMatrix = modelStack.top() * QMatrix4x4(s.transform);
|
||||||
QColor* faceColor = new QColor;
|
QColor* faceColor = new QColor;
|
||||||
|
|
||||||
|
if(isPickingActivated) {
|
||||||
|
// Register self for picking
|
||||||
|
QColor c;
|
||||||
|
c.setRgb(currentPickerColor);
|
||||||
|
s.setColor(c);
|
||||||
|
for (int j = 0; j<3; j++)
|
||||||
|
{
|
||||||
|
for(int i = -1; i<=1; i+=2)
|
||||||
|
{
|
||||||
|
QMatrix4x4 currentTransform = QMatrix4x4();
|
||||||
|
int components[3] = {0, 0, 0};
|
||||||
|
components[j] = i;
|
||||||
|
//std::cout << "Setting " << startColor << " to {" << components[0] << ", " << components[0] << ", " << components[1] << ", " << components[2] << "}\n";
|
||||||
|
currentTransform.translate(components[1], -components[2], -components[0]);
|
||||||
|
mapColorToPosition.insert(currentPickerColor, currentTransform);
|
||||||
|
mapColorToShape.insert(currentPickerColor, &s);
|
||||||
|
currentPickerColor++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glBindVertexArray(m_VAOs[VAO_Cube]);
|
glBindVertexArray(m_VAOs[VAO_Cube]);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
@ -1211,6 +1235,16 @@ void Viewer::deleteSelected() {
|
|||||||
// selection),
|
// selection),
|
||||||
// selectedObj.shape->getParent()->getChildren()->end());
|
// selectedObj.shape->getParent()->getChildren()->end());
|
||||||
|
|
||||||
|
// Get Children if available, and attach to parent
|
||||||
|
if(selectedObj.shape->getParent()->getChildren()->size() > 1) {
|
||||||
|
for(int i = 0; i < selectedObj.shape->getParent()->getChildren()->size(); i++) {
|
||||||
|
if(selectedObj.shape != selectedObj.shape->getParent()->getChildren()->at(i)) {
|
||||||
|
selectedObj.shape->getParent()->getParent()->addChild(selectedObj.shape->getParent()->getChildren()->at(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
selectedObj.shape->getParent()->getParent()->getChildren()->erase(
|
selectedObj.shape->getParent()->getParent()->getChildren()->erase(
|
||||||
std::remove(selectedObj.shape->getParent()->getParent()->getChildren()->begin(),
|
std::remove(selectedObj.shape->getParent()->getParent()->getChildren()->begin(),
|
||||||
selectedObj.shape->getParent()->getParent()->getChildren()->end(),
|
selectedObj.shape->getParent()->getParent()->getChildren()->end(),
|
||||||
@ -1301,8 +1335,10 @@ PickedGeom Viewer::pickGeom(int x, int y){
|
|||||||
|
|
||||||
isPickingActivated = true;
|
isPickingActivated = true;
|
||||||
|
|
||||||
QMap<QRgb, QMatrix4x4> mapColorToPosition;
|
mapColorToPosition.clear();
|
||||||
QMap<QRgb, Shape*> mapColorToShape;
|
mapColorToShape.clear();
|
||||||
|
currentPickerColor = 1;
|
||||||
|
|
||||||
QColor c;
|
QColor c;
|
||||||
QRgb startColor = 1; // alpha must be 100%, glReadPixels doesn't resturn alpha
|
QRgb startColor = 1; // alpha must be 100%, glReadPixels doesn't resturn alpha
|
||||||
unsigned char pixelData[3];
|
unsigned char pixelData[3];
|
||||||
@ -1310,34 +1346,34 @@ PickedGeom Viewer::pickGeom(int x, int y){
|
|||||||
// Give each cube a color, let each cube manage their face-color assignment
|
// Give each cube a color, let each cube manage their face-color assignment
|
||||||
//std::cout << "Iterating through " << root.getChildren()->size() << " items"<<endl;
|
//std::cout << "Iterating through " << root.getChildren()->size() << " items"<<endl;
|
||||||
|
|
||||||
for(int i = 0; i<root.getChildren()->size(); i++)
|
// for(int i = 0; i<root.getChildren()->size(); i++)
|
||||||
{
|
// {
|
||||||
//std::cout << " iterating... " << i << endl;
|
// //std::cout << " iterating... " << i << endl;
|
||||||
SceneGroup* current = dynamic_cast<SceneGroup*>(root.childAt(i));
|
// SceneGroup* current = dynamic_cast<SceneGroup*>(root.childAt(i));
|
||||||
Shape* currentCube;
|
// Shape* currentCube;
|
||||||
|
|
||||||
if(current->getChildren()->size())
|
// if(current->getChildren()->size())
|
||||||
{
|
// {
|
||||||
currentCube = dynamic_cast<Shape*>(current->childAt(0));
|
// currentCube = dynamic_cast<Shape*>(current->childAt(0));
|
||||||
}
|
// }
|
||||||
|
|
||||||
c.setRgb(startColor);
|
// c.setRgb(startColor);
|
||||||
currentCube->setColor(c);
|
// currentCube->setColor(c);
|
||||||
if(currentCube) for (int j = 0; j<3; j++)
|
// if(currentCube) for (int j = 0; j<3; j++)
|
||||||
{
|
// {
|
||||||
for(int i = -1; i<=1; i+=2)
|
// for(int i = -1; i<=1; i+=2)
|
||||||
{
|
// {
|
||||||
QMatrix4x4 currentTransform = QMatrix4x4(current->transform);
|
// QMatrix4x4 currentTransform = QMatrix4x4(current->transform);
|
||||||
int components[3] = {0, 0, 0};
|
// int components[3] = {0, 0, 0};
|
||||||
components[j] = i;
|
// components[j] = i;
|
||||||
//std::cout << "Setting " << startColor << " to {" << components[0] << ", " << components[0] << ", " << components[1] << ", " << components[2] << "}\n";
|
// //std::cout << "Setting " << startColor << " to {" << components[0] << ", " << components[0] << ", " << components[1] << ", " << components[2] << "}\n";
|
||||||
currentTransform.translate(components[1], -components[2], -components[0]);
|
// currentTransform.translate(components[1], -components[2], -components[0]);
|
||||||
mapColorToPosition.insert(startColor, currentTransform);
|
// mapColorToPosition.insert(startColor, currentTransform);
|
||||||
mapColorToShape.insert(startColor, currentCube);
|
// mapColorToShape.insert(startColor, currentCube);
|
||||||
startColor++;
|
// startColor++;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
root.accept(*this);
|
root.accept(*this);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user