Ejemplo n.º 1
0
// Center of tree
void centerBranch(int depth) {
    int terminatingBranch = 0;
    if (depth == 0) {
        translateBy(0, 5 * (1.0 / scaleFactor), 0);
        terminatingLeaf();
        return;
    } // if
    
    if (depth == 1) {
        terminatingBranch = TERM;
    } // if
    
    translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0);
    drawBranch(CENTER, depth);
    
    // Left branch
    pushMatrix();
    turnLeft();
    translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0);
    drawBranch(LEFT | terminatingBranch, depth);
    leftBranch(depth - 1);
    popMatrix();
    
    // 3D left branch
    pushMatrix();
    rotateBy(90, 0, 1, 0);
    rotateBy(15, 0, 0, 1);
    translateBy(1, 0, 0);
    turnLeft();
    translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0);
    drawBranch(LEFT | terminatingBranch, depth);
    leftBranch(depth - 1);
    popMatrix();
    
    translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0);
    drawBranch(CENTER, depth);
    
    // Right branch
    pushMatrix();
    turnRight();
    translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0);
    drawBranch(RIGHT | terminatingBranch, depth);
    rightBranch(depth - 1);
    popMatrix();
    
    // 3D right branch
    pushMatrix();
    rotateBy(90, 0, 1, 0);
    rotateBy(-15, 0, 0, 1);
    translateBy(-1, 0, 0);
    turnRight();
    translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0);
    drawBranch(RIGHT | terminatingBranch, depth);
    rightBranch(depth - 1);
    popMatrix();
    
    translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0);
    drawBranch(CENTER | TERM, depth);
    centerBranch(depth - 1);
} // centerBranch
Ejemplo n.º 2
0
void WidgetGL::mouseMoveEvent(QMouseEvent *event)
{
    int dx = event->x() - lastPos.x();
    int dy = event->y() - lastPos.y();

    if (event->buttons() & Qt::LeftButton)
    {
        rotateBy(1 * dy, 1 * dx, 0);
    }
    else if (event->buttons() & Qt::RightButton)
    {
        rotateBy(1 * dy, 0, 1 * dx);
    }
    else if( event->buttons() & Qt::MidButton)
    {
        left = -dx;
        right = dx;
        bottom = -dy;
        top = dy;
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D( left, right,  bottom, top);
        glMatrixMode(GL_MODELVIEW);
        updateGL();
    }
    lastPos = event->pos();
}
Ejemplo n.º 3
0
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
    int dx = event->x() - lastPos.x();
    int dy = event->y() - lastPos.y();

    if (event->buttons() & Qt::LeftButton) {
        rotateBy(8 * dy, 8 * dx, 0);
    } else if (event->buttons() & Qt::RightButton) {
        rotateBy(8 * dy, 0, 8 * dx);
    }
    lastPos = event->pos();
}
void HeightmapWidget::mouseMoveEvent(QMouseEvent *event)
{
    int dx = event->x() - last_pos.x();
    int dy = event->y() - last_pos.y();

    if (event->buttons() & Qt::RightButton)
    {
        rotateBy(dy*8, 0, 0);
        rotateBy(0, dx*8, 0);
    }
    last_pos = event->pos();
}
Ejemplo n.º 5
0
// Draws 3 leaves around the end of a branch.. once upon a time
void terminatingLeaf(void) {
    if (!drawLeaves) {
        return;
    } // if
    
    if ( (rand() % 100)  < 2) {
        drawFruit();
    } else {
        pushMatrix();
        rotateBy( (rand() % 90), 0, 0, 1);
        rotateBy( -(rand() % 10), 0, 1, 0);
        drawLeaf();
        popMatrix();
    } // if-else
} // terminatingLeaf
bool WheelRotator::handleMouseEvent( const MouseEvent & event, Tool& tool )
{
	if (CurrentRotationProperties::properties().size() == 0)
		return false;


	if (event.dz() != 0)
	{
		timeSinceInput_ = 0.0f;

		// Get the direction only, we don't want the magnitude
		float amnt = (event.dz() > 0) ? -1.0f : 1.0f;

		// Move at 1deg/click with the button down, 5degs/click otherwise
		if (!InputDevices::instance().isKeyDown( KeyEvent::KEY_MIDDLEMOUSE ))
			amnt *= 15.0f;

		rotateBy( amnt, !InputDevices::instance().isShiftDown() );

		return true;
	}
	else
	{
		// commit the rotation now, so we don't have to wait for the timeout
		commitChanges();

		ToolManager::instance().popTool();
	}

	return false;
}
Ejemplo n.º 7
0
void OGLContext::rotateOneStep()
{
    if (qRotate)
    {
        rotateBy(1, 1, 1);
    }
}
Ejemplo n.º 8
0
void drawSkeleton() {
    if (materialsMode) {
        glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_red);
    }
    
    int i, j, k;
    for(i = 0; i < NV; i++) {
        glPushMatrix();
            glTranslatef(vertexes[i][0], vertexes[i][1], vertexes[i][2]);
            glutSolidSphere(0.2, 32, 16);
        glPopMatrix();
    }
    
    float center[3];
    float difference[3];
    
    if (materialsMode) {
        glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_green);
    }
    
    float cylinder[3] = {0, 1, 0};
    float zero[3] = {0, 0, 0};
    for(i = 0; i < NV; i++) {
        for (j = 0; j < 4; j++) {
            int j2 = j < 3 ? j + 1 : 0;
            float distance = 0;
            for (k = 0; k < 3; k++) {
                difference[k] = vertexes[faces[i][j]][k] - vertexes[faces[i][j2]][k];
                distance += difference[k] * difference[k];
                center[k] = (vertexes[faces[i][j]][k] + vertexes[faces[i][j2]][k]) / 2;
            }
            glPushMatrix();
                glTranslatef(center[0], center[1], center[2]);
                
                /* Normalizing */
                difference[0] /= sqrt(distance);
                difference[1] /= sqrt(distance);
                difference[2] /= sqrt(distance);
                
                float nx, ny, nz;
                float normal[3];
                CalculateVectorNormal(zero, cylinder, difference,
                                      &nx, &ny, &nz);
                normal[0] = nx;
                normal[1] = ny;
                normal[2] = nz;
             
                float angle = DEG(getAngle(cylinder, difference));
                rotateBy(normal, angle);
                drawCylinder(0.05, sqrt(distance), 64);
                
                glPopMatrix();
        }
    }
    
    if (materialsMode) {
        glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_gray);
    }
}
Ejemplo n.º 9
0
GLWidget::GLWidget(QWidget *parent) : QWidget(parent)
{
    Q_INIT_RESOURCE(posewidget);

    front = QImage(QString(":/images/side1.png"));
    back = QImage(QString(":/images/side6.png"));
    rotateBy(0, 0, 0);
}
Ejemplo n.º 10
0
/****************************************************************************
**
** Copyright (C) 2015
**
** This file is generated by the Magus toolkit
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/

#include <QtWidgets>
#include <QtOpenGL>
#include <QMessageBox>

#include "tool_glspherewidget.h"

namespace Magus
{
    //****************************************************************************/
    QtGLSphereWidget::QtGLSphereWidget(QWidget *parent, QGLWidget *shareWidget)
        : QGLWidget(parent, shareWidget)
    {
        clearColor = Qt::black;
        xRot = 0;
        yRot = 0;
        zRot = 0;
        program = 0;
    }

    //****************************************************************************/
    QtGLSphereWidget::~QtGLSphereWidget()
    {
    }

    //****************************************************************************/
    QSize QtGLSphereWidget::minimumSizeHint() const
    {
        return QSize(16, 16);
    }

    //****************************************************************************/
    QSize QtGLSphereWidget::sizeHint() const
    {
        return QSize(200, 200);
    }

    //****************************************************************************/
    void QtGLSphereWidget::rotateBy(int xAngle, int yAngle, int zAngle)
    {
        xRot += xAngle;
        yRot += yAngle;
        zRot += zAngle;
        updateGL();
    }

    //****************************************************************************/
    void QtGLSphereWidget::setClearColor(const QColor &color)
    {
        clearColor = color;
        updateGL();
    }

    //****************************************************************************/
    void QtGLSphereWidget::setPixmap(const QPixmap& pixmap, const QString& fullName, const QString& baseName)
    {
        mPixmap = pixmap;
        mFullName = fullName;
        mBaseName = baseName;
    }

    //****************************************************************************/
    const QString& QtGLSphereWidget::getFullName(void) const
    {
        return mFullName;
    }

    //****************************************************************************/
    const QString& QtGLSphereWidget::getBaseName(void) const
    {
        return mBaseName;
    }

    //****************************************************************************/
    void QtGLSphereWidget::initializeGL()
    {
        initializeOpenGLFunctions();
        buildSphere();

        glEnable(GL_DEPTH_TEST);
        glEnable(GL_CULL_FACE);
    #ifdef GL_TEXTURE_2D
        glEnable(GL_TEXTURE_2D);
    #endif

    #define PROGRAM_VERTEX_ATTRIBUTE 0
    #define PROGRAM_TEXCOORD_ATTRIBUTE 1

        QGLShader *vshader = new QGLShader(QGLShader::Vertex, this);
        const char *vsrc =
            "attribute highp vec4 vertex;\n"
            "attribute mediump vec4 texCoord;\n"
            "varying mediump vec4 texc;\n"
            "uniform mediump mat4 matrix;\n"
            "void main(void)\n"
            "{\n"
            "    gl_Position = matrix * vertex;\n"
            "    texc = texCoord;\n"
            "}\n";
        vshader->compileSourceCode(vsrc);

        QGLShader *fshader = new QGLShader(QGLShader::Fragment, this);
        const char *fsrc =
            "uniform sampler2D texture;\n"
            "varying mediump vec4 texc;\n"
            "void main(void)\n"
            "{\n"
            "    gl_FragColor = texture2D(texture, texc.st);\n"
            "}\n";
        fshader->compileSourceCode(fsrc);

        program = new QGLShaderProgram(this);
        program->addShader(vshader);
        program->addShader(fshader);
        program->bindAttributeLocation("vertex", PROGRAM_VERTEX_ATTRIBUTE);
        program->bindAttributeLocation("texCoord", PROGRAM_TEXCOORD_ATTRIBUTE);
        program->link();

        program->bind();
        program->setUniformValue("texture", 0);

        // Set the clear color and rotate the sphere
        QColor clearColor;
        clearColor = Qt::black;
        setClearColor(clearColor);
        rotateBy(0 * 16, -90 * 16, 180 * 16);
    }
Ejemplo n.º 11
0
int main()
{
        node_t head = NULL;
        int a[] = {1, 2, 3, 4, 3, 4, 9};
        int i = 0;
        for(i = 0; i < 7; ++i)
        {
                head = addElement(head,a[i]);
        }
        display(head);
        int n = 11;
        head = rotateBy(head,n);
        display(head);
        return 0;
}
Ejemplo n.º 12
0
void ModelShow::mouseMoveEvent(QMouseEvent *event)
{
    int dx=event->x()-lastPos.x();
    int dy=event->y()-lastPos.y();

    if(event->buttons() & Qt::LeftButton){
        rotateBy(-8*dy,8*dx,0);
    }
    else if(event->buttons() & Qt::RightButton){
        zoomBy(-0.01*dx);
    }
    else if(event->buttons() & Qt::MiddleButton){
        translateBy(0.01*dx,0.01*dy,0);
    }
    lastPos=event->pos();
}
node_t rotateBy(node_t head, int n)
{
        if(head == NULL || n == 0)
        {
                return head;
        }
        node_t cur = head;
        while(cur -> link -> link != NULL)
        {
                cur = cur -> link;
        }
        node_t temp = cur -> link;
        cur -> link = NULL;
        temp -> link = head;
        head = temp;

        return head = rotateBy(head, n - 1);
}
	Path2D GeometricRecognizer::rotateToZero(Path2D points)
	{
		Point2D c = centroid(points);
		double rotation = atan2(c.y - points[0].y, c.x - points[0].x);
		return rotateBy(points, -rotation);
	}
	double GeometricRecognizer::distanceAtAngle(
		Path2D points, GestureTemplate aTemplate, double rotation)
	{
		Path2D newPoints = rotateBy(points, rotation);
		return pathDistance(newPoints, aTemplate.points);
	}	
Ejemplo n.º 16
0
/**
 * Rotates the camera by an angle to the right.  Consolidating this into a 
 * function makes the l-system more readable
 */
void turnRight() {
    rotateBy(-angle, 0, 0, 1);
} // turnRight
Ejemplo n.º 17
0
void Moveable::rotateByZ(float angle) {
	rotateBy(glm::vec3(0.0, 0.0, 1.0), angle);
	mRefresh = true;
}
Ejemplo n.º 18
0
GLWidget::GLWidget(QWidget *parent) : QWidget(parent)
{
    front = QImage(QString(":/images/side1.png"));
    back = QImage(QString(":/images/side6.png"));
    rotateBy(0, 0, 0);
}
Ejemplo n.º 19
0
/**
 * Rotates the camera by an angle to the left.  Consolidating this into a 
 * function makes the l-system more readable
 */
void turnLeft() {
    rotateBy(angle, 0, 0, 1);
} // turnLeft