예제 #1
0
파일: 圣诞.c 프로젝트: Lyrics1/learn_git
float f(Mat m, int n) {
    float z = -1.0f;
    for (float r = 0.0f; r < 0.8f; r += 0.02f) {
        Vec v = { 0.0f, r, 0.0f, 1.0f };
        transformPosition(&v, m, v);
        z = opUnion(z, sphere(v, transformLength(m, 0.05f * (0.95f - r))));
    }

    if (n > 0) {
        Mat ry, rz, s, t, m2, m3;
        rotateZ(&rz, 1.8f);

        for (int p = 0; p < 6; p++) {
            rotateY(&ry, p * (2 * PI / 6));
            mul(&m2, ry, rz);
            float ss = 0.45f;
            for (float r = 0.2f; r < 0.8f; r += 0.1f) {
                scale(&s, ss);
                translate(&t, 0.0f, r, 0.0f);
                mul(&m3, s, m2);
                mul(&m3, t, m3);
                mul(&m3, m, m3);
                z = opUnion(z, f(m3, n - 1));
                ss *= 0.8f;
            }
        }
    }

    return z;
}
예제 #2
0
void GLWidget::mousePressEvent(QMouseEvent *event)
{
    if (event->buttons() & Qt::LeftButton ) {
        const QPointF posF = transformPosition(event->pos());
        points.push_back(posF);
    }

    update();
}
예제 #3
0
void GLWidget::mousePressEvent(QMouseEvent *event)
{
	if (event->buttons() & Qt::LeftButton) {
		QPoint pos = event->pos();
		QPointF posF = transformPosition(pos);
		clickedPoint = points.getClosestPoint(posF.x(),posF.y());
		points.setPointX(clickedPoint,posF.x());
		points.setPointY(clickedPoint,posF.y());
		update();

		return;
	}

	if (event->buttons() & Qt::RightButton) {
		QPoint pos = event->pos();
		QPointF newP = transformPosition(pos);
		newPoint(newP);
	}
}
예제 #4
0
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
	if (event->buttons() & Qt::LeftButton) {
		QPoint pos = event->pos();
		QPointF posF = transformPosition(pos);
		points.setPointX(clickedPoint,posF.x());
		points.setPointY(clickedPoint,posF.y());
		update();
	}
}
예제 #5
0
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
    QPointF clickedPoint = transformPosition(event->pos());

    if (event->buttons() & Qt::RightButton && !getFirstPoint) {
        rq.p2 = clickedPoint;
    }

    update();
}
예제 #6
0
void GLWidget::mousePressEvent(QMouseEvent *event)
{
    QPointF clickedPoint = transformPosition(event->pos());

    if (event->buttons() & Qt::LeftButton ) {
        points.push_back(clickedPoint);
    } else if (event->buttons() & Qt::RightButton) {
        if (getFirstPoint) {
            rq.p1 = clickedPoint;
            rq.p2 = clickedPoint;

            getFirstPoint = false;
        }
    }

    update();
}
예제 #7
0
static void fpsCameraViewMatrix(GLFWwindow *window, float *view)
{
	// initial camera config
	static float position[] = { 0.0f, 0.3f, 1.5f };
	static float rotation[] = { 0.0f, 0.0f };

	// mouse look
	static double lastMouse[] = { 0.0, 0.0 };
	double mouse[2];
	glfwGetCursorPos(window, &mouse[0], &mouse[1]);
	if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
	{
		rotation[0] += (float)(mouse[1] - lastMouse[1]) * -0.2f;
		rotation[1] += (float)(mouse[0] - lastMouse[0]) * -0.2f;
	}
	lastMouse[0] = mouse[0];
	lastMouse[1] = mouse[1];

	float rotationY[16], rotationX[16], rotationYX[16];
	rotationMatrix(rotationX, rotation[0], 1.0f, 0.0f, 0.0f);
	rotationMatrix(rotationY, rotation[1], 0.0f, 1.0f, 0.0f);
	multiplyMatrices(rotationYX, rotationY, rotationX);

	// keyboard movement (WSADEQ)
	float speed = (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) ? 0.1f : 0.01f;
	float movement[3] = {0};
	if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) movement[2] -= speed;
	if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) movement[2] += speed;
	if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) movement[0] -= speed;
	if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) movement[0] += speed;
	if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) movement[1] -= speed;
	if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) movement[1] += speed;

	float worldMovement[3];
	transformPosition(worldMovement, rotationYX, movement);
	position[0] += worldMovement[0];
	position[1] += worldMovement[1];
	position[2] += worldMovement[2];

	// construct view matrix
	float inverseRotation[16], inverseTranslation[16];
	transposeMatrix(inverseRotation, rotationYX);
	translationMatrix(inverseTranslation, -position[0], -position[1], -position[2]);
	multiplyMatrices(view, inverseRotation, inverseTranslation); // = inverse(translation(position) * rotationYX);
}
예제 #8
0
void GLWidget::mousePressEvent(QMouseEvent *event)
{
    if (event->buttons() & Qt::LeftButton ) {
        QPointF clickedPoint = transformPosition(event->pos());

        if (getFirstPoint) {
            getFirstPoint = false;
            lastPoint = clickedPoint;
        } else {
            getFirstPoint = true;

            std::shared_ptr<IsoSegment> isoSeg;

            if (isHorizontalSegment(lastPoint, clickedPoint)) {
                // Horizontal: Gleiche Y-Position an
                clickedPoint.ry() = lastPoint.ry();

                QPointF leftPoint = getLeftPoint(clickedPoint, lastPoint);
                QPointF rightPoint = getRightPoint(clickedPoint, lastPoint);

                // ISO-Segment auf dem Heap-Speicher erstellen
                isoSeg = std::make_shared<IsoSegment>(leftPoint, rightPoint);

                // Start- und End-Event in Vector einfügen
                events.push_back(Event(leftPoint.rx (), START_EVENT, isoSeg));
                events.push_back(Event(rightPoint.rx(), END_EVENT  , isoSeg));
            } else {
                // Vertikal: Gleiche X-Position an
                clickedPoint.rx() = lastPoint.rx();

                // ISO-Segment auf dem Heap-Speicher erstellen
                isoSeg = std::make_shared<IsoSegment>(lastPoint, clickedPoint);
                events.push_back(Event(clickedPoint.rx(), VERTICAL, isoSeg));
            }

            segments.push_back(isoSeg);
        }
        points.push_back(clickedPoint);
    }

    update();
}