void Displayable::set_rot(const Matrix4 &m) { if (fixed()) return; // only transform unfixed objects // do trans for all children as well for (int i=0; i < num_children; i++) child(i)->set_rot(m); if (!rotating()) return; rotm = m; need_matrix_recalc(); }
// reset the transformation to the identity matrix void Displayable::reset_transformation(void) { // only reset if we're not fixed and given operations are allowed if (scaling()) scale=1; if (rotating()) { rotm.identity(); } if (glob_translating()) globt[0] = globt[1] = globt[2] = 0; if (cent_translating()) centt[0] = centt[1] = centt[2] = 0; need_matrix_recalc(); // do reset for all children as well for (int i=0; i < num_children; i++) child(i)->reset_transformation(); }
void Displayable::set_rot(float x, char axis) { if (fixed()) return; // only transform unfixed objects // do trans for all children as well for (int i=0; i < num_children; i++) child(i)->set_rot(x, axis); if (!rotating()) return; // apply rotation to identity, and then multiply this by old rot matrix rotm.identity(); rotm.rot(x,axis); need_matrix_recalc(); }
void Displayable::add_rot(float x, char axis) { if (fixed()) return; // only transform unfixed objects // do trans for all children as well for (int i=0; i < num_children; i++) child(i)->add_rot(x, axis); if (!rotating()) return; // Need to apply the new rotation first Matrix4 mat; mat.rot(x, axis); mat.multmatrix(rotm); rotm = mat; need_matrix_recalc(); }
QPointF UBGraphicsDelegateFrame::getFixedPointFromPos() { QPointF fixedPoint; if (!moving() && !rotating()) { if (resizingTop()) { if (mMirrorX && mMirrorY) { if ((0 < mAngle) && (mAngle < 90)) fixedPoint = delegated()->sceneBoundingRect().topLeft(); else fixedPoint = delegated()->sceneBoundingRect().topRight(); } else { if ((0 < mAngle) && (mAngle <= 90)) fixedPoint = delegated()->sceneBoundingRect().bottomRight(); else fixedPoint = delegated()->sceneBoundingRect().bottomLeft(); } } else if (resizingLeft()) { if (mMirrorX && mMirrorY) { if ((0 < mAngle) && (mAngle < 90)) fixedPoint = delegated()->sceneBoundingRect().bottomLeft(); else fixedPoint = delegated()->sceneBoundingRect().topLeft(); } else { if ((0 < mAngle) && (mAngle <= 90)) fixedPoint = delegated()->sceneBoundingRect().topRight(); else fixedPoint = delegated()->sceneBoundingRect().bottomRight(); } } } return fixedPoint; }
void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (None == mCurrentTool) return; QLineF move = QLineF(mStartingPoint, event->scenePos()); qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180); qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180); qreal width = delegated()->boundingRect().width() * mTotalScaleX; qreal height = delegated()->boundingRect().height() * mTotalScaleY; if (mOperationMode == Scaling) { if(!rotating()) { mTranslateX = moveX; // Perform the resize if (resizingBottomRight()) { // ----------------------------------------------------- // ! We want to keep the aspect ratio with this resize ! // ----------------------------------------------------- qreal scaleX; qreal scaleY; if(!mMirrorX) { scaleX = (width + moveX) / width; } else { scaleX = (width - moveX) / width; } if(!mMirrorY) { scaleY = (height + moveY) / height; } else { scaleY = (height - moveY) / height; } qreal scaleFactor = (scaleX + scaleY) / 2; // Do not allow resizing of image size under frame size if (canResizeBottomRight(width, height, scaleFactor)) { if (mRespectRatio) { mScaleX = scaleFactor; mScaleY = scaleFactor; } else { mScaleX = scaleX; mScaleY = scaleY; } } } else if (resizingLeft() || resizingRight()) { if(width != 0) { qreal scaleX = 0.0; if(resizingLeft()) { scaleX = (width - moveX) / width; } else if(resizingRight()) { scaleX = (width + moveX) / width; } if(mDelegate->isFlippable() && qAbs(scaleX) != 0) { if((qAbs(width * scaleX)) < 2*mFrameWidth) { bool negative = (scaleX < 0)?true:false; if(negative) { if(mMirrorX) scaleX = 2*mFrameWidth/width; else scaleX = -2*mFrameWidth/width; } else { scaleX = -1; mFlippedX = !mFlippedX; } } mScaleX = scaleX; } else if (scaleX > 1 || (width * scaleX) > 2 * mFrameWidth) { mScaleX = scaleX; if(resizingLeft()) { mTranslateX = moveX; } } } } else if(resizingTop() || resizingBottom()) { if(height != 0) { qreal scaleY = 0.0; if(resizingTop()) { scaleY = (height - moveY) / height; } else if(resizingBottom()) { scaleY = (height + moveY) / height; } if(mDelegate->isFlippable() && qAbs(scaleY) != 0) { if((qAbs(height * scaleY)) < 2*mFrameWidth) { bool negative = (scaleY < 0)?true:false; if(negative) { if(mMirrorY) scaleY = 2*mFrameWidth/width; else scaleY = -2*mFrameWidth/width; } else { scaleY = -1; mFlippedY = !mFlippedY; } } mScaleY = scaleY; } else if (scaleY > 1 || (height * scaleY) > 2 * mFrameWidth) { mScaleY = scaleY; if(resizingTop()) { mTranslateY = moveY; } } } } } } if (rotating()) { mTranslateX = 0; mTranslateY = 0; QLineF startLine(sceneBoundingRect().center(), event->lastScenePos()); QLineF currentLine(sceneBoundingRect().center(), event->scenePos()); mAngle += startLine.angleTo(currentLine); if ((int)mAngle % 45 >= 45 - mAngleTolerance || (int)mAngle % 45 <= mAngleTolerance) { mAngle = qRound(mAngle / 45) * 45; mAngleOffset += startLine.angleTo(currentLine); if ((int)mAngleOffset % 360 > mAngleTolerance && (int)mAngleOffset % 360 < 360 - mAngleTolerance) { mAngle += mAngleOffset; mAngleOffset = 0; } } else if ((int)mAngle % 30 >= 30 - mAngleTolerance || (int)mAngle % 30 <= mAngleTolerance) { mAngle = qRound(mAngle / 30) * 30; mAngleOffset += startLine.angleTo(currentLine); if ((int)mAngleOffset % 360 > mAngleTolerance && (int)mAngleOffset % 360 < 360 - mAngleTolerance) { mAngle += mAngleOffset; mAngleOffset = 0; } } setCursorFromAngle(QString::number((int)mAngle % 360)); } else if (moving()) { mTranslateX = move.dx(); mTranslateY = move.dy(); moveLinkedItems(move); } if (mOperationMode == Scaling || moving() || rotating()) { QTransform tr = buildTransform(); if (resizingRight() || resizingBottom() || resizingBottomRight()) { QPointF ref; // we just detects coordinates of corner before and after scaling and then moves object at diff between them. if (resizingBottomRight() && (mMirrorX || mMirrorY)) { if (mFlippedX && !mMirrorX && mFlippedY)// && !mMirrorY) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).x() - tr.map(delegated()->boundingRect().bottomLeft()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).y() - tr.map(delegated()->boundingRect().bottomLeft()).y(); } else if ((mFlippedX || mMirrorX) && (mFlippedY || mMirrorY)) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); } else if (mFlippedX || mMirrorX) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().topRight()).x() - tr.map(delegated()->boundingRect().topRight()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().topRight()).y() - tr.map(delegated()->boundingRect().topRight()).y(); } else if (mFlippedY || mMirrorY) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).x() - tr.map(delegated()->boundingRect().bottomLeft()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).y() - tr.map(delegated()->boundingRect().bottomLeft()).y(); } else { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); } } else { mTranslateX += mInitialTransform.map(delegated()->boundingRect().topLeft()).x() - tr.map(delegated()->boundingRect().topLeft()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().topLeft()).y() - tr.map(delegated()->boundingRect().topLeft()).y(); } } else if (resizingTop() || resizingLeft()) { QPointF bottomRight = tr.map(delegated()->boundingRect().bottomRight()); QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().bottomRight()); mTranslateX += fixedPoint.x() - bottomRight.x(); mTranslateY += fixedPoint.y() - bottomRight.y(); } delegated()->setTransform(buildTransform()); } else // resizing/resizing horizontally { if (resizingBottomRight()) { static QSizeF incV = QSizeF(); static QSizeF incH = QSizeF(); if (mMirrorX && mMirrorY) mCurrentTool = ResizeTop; else mCurrentTool = ResizeBottom; incV = resizeDelegate(moveX, moveY); mOriginalSize += incV; if (mMirrorX && mMirrorY) mCurrentTool = ResizeLeft; else mCurrentTool = ResizeRight; move = QLineF(event->lastScenePos(), event->scenePos()); moveX = move.length() * cos((move.angle() - mAngle) * PI / 180); moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180); mFixedPoint = getFixedPointFromPos(); incH = resizeDelegate(moveX, moveY); mOriginalSize -= incV; mOriginalSize += incH; mCurrentTool = ResizeBottomRight; } else resizeDelegate(moveX, moveY); } event->accept(); }
void GLWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //material float ambient0[] = {0.0f, 0.0f, 0.0f, 1.0f}; float ambient1[] = {0.7f, 0.7f, 0.7f, 1.0f}; float ambient2[] = {0.8f, 0.8f, 0.2f, 1.0f}; float diffuse0[] = {0.0f, 0.0f, 0.0f, 1.0f}; float diffuse1[] = {0.1f, 0.5f, 0.8f, 1.0f}; float specular0[] = {0.0f, 0.0f, 0.0f, 1.0f}; float specular1[] = {1.0f, 1.0f, 1.0f, 1.0f}; float shininess0 = 0.0f; float shininess1 = 5.0f; float shininess2 = 100.0f; float emission0[] = {0.0f, 0.0f, 0.0f, 1.0f}; float emission1[] = {0.3f, 0.2f, 0.2f, 0.0f}; //ambient if(modelambient==0){ glMaterialfv(GL_FRONT, GL_AMBIENT, ambient0);} else if(modelambient==1){ glMaterialfv(GL_FRONT, GL_AMBIENT, ambient1);} else{ glMaterialfv(GL_FRONT, GL_AMBIENT, ambient2);} //diffuse if(modeldiffuse==0){ glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse0);} else{ glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse1);} //specular if(modelspecular==0){ glMaterialfv(GL_FRONT, GL_SPECULAR, specular0);} else{ glMaterialfv(GL_FRONT, GL_SPECULAR, specular1);} //shininess if(modelshininess==0){ glMaterialf(GL_FRONT, GL_SHININESS, shininess0);} else if(modelshininess==1){ glMaterialf(GL_FRONT, GL_SHININESS, shininess1);} else{ glMaterialf(GL_FRONT, GL_SHININESS, shininess2);} //emission if(modelemission==0){ glMaterialfv(GL_FRONT, GL_EMISSION, emission0);} else{ glMaterialfv(GL_FRONT, GL_EMISSION, emission1);} //effect if(lighteffect==1){ glColorMaterial(GL_FRONT, GL_AMBIENT);} else if(lighteffect==2){ glColorMaterial(GL_FRONT, GL_DIFFUSE);} else if(lighteffect==10){glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);} //SNOWMAN -------------------------------------------------------------------------------- GLUquadricObj *quadric; quadric = gluNewQuadric(); gluQuadricDrawStyle(quadric, GLU_FILL ); glEnable(GL_COLOR_MATERIAL); glPushMatrix(); glRotated(xRot / 16.0, 1.0, 0.0, 0.0); glRotated(yRot / 16.0, 0.0, 1.0, 0.0); glRotated(zRot / 16.0, 0.0, 0.0, 1.0); rotating(); //head glColor3f(1.0f, 1.0f, 1.0f); glTranslatef(0.0f,4.0f,0.0f); gluSphere(quadric, 1.0f, 50, 50); //left eyes glColor3f(0.0f, 0.0f, 0.0f ); glTranslatef(0.3f,0.3f,1.0f); gluSphere(quadric, 0.15f, 50, 50); glTranslatef(-0.3f,-0.3f,-1.0f); //right eyes glColor3f(0.0f, 0.0f, 0.0f ); glTranslatef(-0.3f,0.3f,1.0f); gluSphere(quadric, 0.15f, 50, 50); glTranslatef(0.3f,-0.3f,-1.0f); //nose glColor3f(1.0f, 0.549f, 0.0f); glTranslatef(0.0f,0.0f,1.0f); drawCylinder(1.0f,0.2f,0.01f,50,50); //body glColor3f(1.0f, 0.0f, 0.0f); glTranslatef(0.0f,-2.5f,-1.0f); gluSphere(quadric, 2.0f, 50, 50); //button glColor3f(0.0f, 0.0f, 0.0f ); glTranslatef(0.0f,1.0f,1.7f); gluSphere(quadric, 0.2f, 50, 50); glTranslatef(0.0f,-1.0f,0.3f); gluSphere(quadric, 0.2f, 50, 50); glTranslatef(0.0f,-1.0f,-0.3f); gluSphere(quadric, 0.2f, 50, 50); glTranslatef(0.0f,1.0f,-1.7f); //left hand glColor3f(0.545f, 0.271f, 0.075f); glTranslatef(1.5f,1.0f,0.0f); glRotated(90,0.0,1.0,0.0); glRotated(-30,1.0,0.0,0.0); drawCylinder(2.5f,0.2f,0.2,50,50); glRotated(30,1.0,0.0,0.0); glRotated(-90,0.0,1.0,0.0); //right hand glTranslatef(-3.0f,0.0f,0.0f); glRotated(-90,0.0,1.0,0.0); glRotated(-30,1.0,0.0,0.0); drawCylinder(2.5f,0.2f,0.2,50,50); glRotated(30,1.0,0.0,0.0); glRotated(90,0.0,1.0,0.0); //bottom glColor3f(0.0f, 1.0f, 0.0f); glTranslatef(1.5f,-5.0f,0.0f); gluSphere(quadric, 3.0f, 50, 50); glPopMatrix(); //hat glColor3f(0.0f, 0.0f, 1.0f ); glPushMatrix(); glRotated(xRot / 16.0, 1.0, 0.0, 0.0); glRotated(yRot / 16.0, 0.0, 1.0, 0.0); glRotated(zRot / 16.0, 0.0, 0.0, 1.0); rotating(); glTranslatef(0.0f,6.0f,0.0f); glRotatef(90,1.0,0.0,0.0); drawCylinder(1.25f, 0.8f, 0.7f, 50,50); glTranslatef(0.0f,0.0f,1.15f); drawCylinder(0.1f, 1.2f, 1.2f, 50,50); glPopMatrix(); glDisable(GL_COLOR_MATERIAL); }
/** Updated the item - rotates it, takes care of items coming back into * the game after it has been collected. * \param ticks Number of physics time steps - should be 1. */ void Item::updateGraphics(float dt) { if (m_node == NULL) return; if (m_graphical_type != getGrahpicalType()) { handleNewMesh(getGrahpicalType()); m_graphical_type = getGrahpicalType(); } float time_till_return = stk_config->ticks2Time(getTicksTillReturn()); bool is_visible = isAvailable() || time_till_return <= 1.0f || (getType() == ITEM_BUBBLEGUM && getOriginalType() == ITEM_NONE && !isUsedUp()); m_node->setVisible(is_visible); m_node->setPosition(getXYZ().toIrrVector()); if (!m_was_available_previously && isAvailable()) { // This item is now available again - make sure it is not // scaled anymore. m_node->setScale(core::vector3df(1, 1, 1)); } if (!isAvailable() && time_till_return <= 1.0f) { // Make it visible by scaling it from 0 to 1: if (rotating()) { float angle = fmodf((float)(World::getWorld()->getTicksSinceStart() + getTicksTillReturn()) / 40.0f, M_PI * 2); btMatrix3x3 m; m.setRotation(getOriginalRotation()); btQuaternion r = btQuaternion(m.getColumn(1), angle) * getOriginalRotation(); Vec3 hpr; hpr.setHPR(r); m_node->setRotation(hpr.toIrrHPR()); } m_node->setVisible(true); m_node->setScale(core::vector3df(1, 1, 1)*(1 - time_till_return)); } if (isAvailable()) { Vec3 hpr; if (rotating()) { // have it rotate float angle = fmodf((float)World::getWorld()->getTicksSinceStart() / 40.0f, M_PI * 2); btMatrix3x3 m; m.setRotation(getOriginalRotation()); btQuaternion r = btQuaternion(m.getColumn(1), angle) * getOriginalRotation(); hpr.setHPR(r); } else hpr.setHPR(getOriginalRotation()); m_node->setRotation(hpr.toIrrHPR()); } // if item is available m_was_available_previously = isAvailable(); } // updateGraphics