Exemple #1
0
void Player::intersectedWall(const sf::FloatRect &intersection)
{
    if (intersection.intersects(vert_rect))
    {
        if (intersection.top > boundingBox.top + boundingBox.height / 2)
        {
            boundingBox.top -= intersection.height;
        }
        if (intersection.top < boundingBox.top + boundingBox.height / 2)
        {
            boundingBox.top += intersection.height;
        }
    }

    if (intersection.intersects(horz_rect))
    {
        if (intersection.left < boundingBox.left + boundingBox.width / 2)
        {
            boundingBox.left += intersection.width;
        }
        if (intersection.left > boundingBox.left + boundingBox.width / 2)
        {
            boundingBox.left -= intersection.width;
        }
    }

    updateCross();
}
Exemple #2
0
		/// <summary>
		/// シーンを更新します。
		/// </summary>
		/// <returns>
		/// シーンの更新に成功した場合 true, それ以外の場合は false
		/// </returns>
		bool updateScene()
		{
			if (hasError())
			{
				return false;
			}

			if (!m_current)
			{
				if (!m_first)
				{
					return true;
				}
				else if (!init(m_first.value()))
				{
					return false;
				}
			}

			if (m_crossFade)
			{
				return updateCross();
			}
			else
			{
				return updateSingle();
			}
		}
Exemple #3
0
bool Optimize::eval_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)
{
    UNUSED(n);
    UNUSED(m);
    UNUSED(new_x);
    if (updateCross(x) == false) return false;
    int i = 0, size = edges.size();
    for (; i < size; i++)
        g[i] = computeEdgeLength(i, x);
    i = size;
    int end = edges.size() + crosses.size();
    for (; i < end; ++i)
    {
        g[i] = computeCrossDiagDistance(i - size, x);
    }
    return true;
}
Exemple #4
0
bool Optimize::eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)
{
    UNUSED(n);
    UNUSED(new_x);
    if (updateCross(x) == false) return false;
    obj_value = 0;
    PointArray px = PointArray(x);
    Ipopt::Number t[3];
    Ipopt::Number r = 0;
    double tmp;
    int i = 0, size = EnergyVertices.size();
    for (; i < size; i++)
    {
        obj_value += computeBeta(i, x) / VerticesWeight[i];
    }
    obj_value *= 2 * pOp->BendingEnergyCoef;
    i = 0;
    size = PositionConstraints.size();
    for (; i < size; i++)
    {
        sub(px(PositionConstraints[i]), positions[i].data(), t);
        r += sqrnorm(t);
    }
    r *= pOp->PositionConstraintsWeight;
    obj_value += r;
    r = 0;
    i = 0;
    size = TangentConstraints.size();
    for (; i < size; ++i)
    {
        computeTangentEdge(i, x, t);
        r += 1 - dot(t, tangents[i].data());
    }
    obj_value += r * pOp->TangentConstraintsCoef;

    r = 0;
    i = 0;
    size = PlaneConstraints.size();
    for (; i < size; ++i)
    {
        tmp = (getPoint(PlaneConstraints[i], x) | PlaneConstraintsInfo[i].first) + PlaneConstraintsInfo[i].second;
        r += tmp * tmp;
    }
    obj_value += r * pOp->PlaneConstraintsCoef;
    return true;
}
Exemple #5
0
void Player::updateMovement(sf::Time elapsedTime)
{
    if (health <= 0)
        return;

    sf::Vector2f movement (0,0);
    float distance = speed * elapsedTime.asSeconds();

    if ((controls & 0x1) && boundingBox.getPosition().y - distance > movementBounds.top)
        movement.y -= speed;
    if ((controls & 0x2) && boundingBox.getPosition().y + distance < movementBounds.top + movementBounds.height)
        movement.y += speed;
    if ((controls & 0x4) && boundingBox.getPosition().x - distance > movementBounds.left)
        movement.x -= speed;
    if ((controls & 0x8) && boundingBox.getPosition().x + distance < movementBounds.top + movementBounds.width)
        movement.x += speed;

    movement *= elapsedTime.asSeconds();
    boundingBox.left += movement.x;
    boundingBox.top += movement.y;
    updateCross();
}
Exemple #6
0
Player::Player(int16_t playerId, sf::Vector2f position, OutputSocket socket, char * nick) :
playerId(playerId),
timeSinceLastShot(sf::Time::Zero),
speed(500),
rotation(0),
cross_thickness(5),
socket(socket),
health(100),
playerInfo(0),
ip(socket.ip),
nick(nick),
ammo(10),
invisibleTime(sf::Time::Zero)
{
    boundingBox = BoundingBox(position.x, position.y, 50, 50);
    updateCross();
    horz_rect.width = boundingBox.width;
    vert_rect.height = boundingBox.height;
    type = EntityType::Player_T;
    setTeam(0);
    setValid(0);
}
bool Plot3DDialog::updatePlot()
{
	int axis=-1;

	if (generalDialog->currentWidget()==(QWidget*)bars)
	{
		emit updateBars(boxBarsRad->text().toDouble());
	}

	if (generalDialog->currentWidget()==(QWidget*)points)
	{
		if (boxPointStyle->currentItem() == 0)
			emit updatePoints(boxSize->text().toDouble(), boxSmooth->isChecked());
		else if (boxPointStyle->currentItem() == 1)
			emit updateCross(boxCrossRad->text().toDouble(), boxCrossLinewidth->text().toDouble(),
					boxCrossSmooth->isChecked(), boxBoxed->isChecked());
		else if (boxPointStyle->currentItem() == 2)
			emit updateCones(boxConesRad->text().toDouble(), boxQuality->value());
	}

	if (generalDialog->currentWidget()==(QWidget*)title)
	{
		emit updateTitle(boxTitle->text(),titleColor,titleFont);
	}

	if (generalDialog->currentWidget()==(QWidget*)colors)
	{
		emit updateTransparency(boxTransparency->value()*0.01);
		emit updateDataColors(fromColor,toColor);
		emit updateColors(meshColor,axesColor,numColor,labelColor,bgColor,gridColor);
	}

	if (generalDialog->currentWidget()==(QWidget*)general)
	{
		emit showColorLegend(boxLegend->isChecked());
		emit updateMeshLineWidth(boxMeshLineWidth->value());
		emit adjustLabels(boxDistance->value());
		emit updateResolution (boxResolution->value());
		emit showColorLegend(boxLegend->isChecked());
		emit setNumbersFont(numbersFont);
		emit updateZoom(boxZoom->value()*0.01);
		emit updateScaling(boxXScale->value()*0.01,boxYScale->value()*0.01,
				boxZScale->value()*0.01);
	}

	if (generalDialog->currentWidget()==(QWidget*)scale)
	{
		axis=axesList->currentRow();
		QString from=boxFrom->text().toLower();
		QString to=boxTo->text().toLower();
		double start,end;
		bool error=false;
		try
		{
			MyParser parser;
			parser.SetExpr(from.toAscii().constData());
			start=parser.Eval();
		}
		catch(mu::ParserError &e)
		{
			QMessageBox::critical(0,tr("Start limit error"),  QString::fromStdString(e.GetMsg()));
			boxFrom->setFocus();
			error=true;
			return false;
		}
		try
		{
			MyParser parser;
			parser.SetExpr(to.toAscii().constData());
			end=parser.Eval();
		}
		catch(mu::ParserError &e)
		{
			QMessageBox::critical(0,tr("End limit error"), QString::fromStdString(e.GetMsg()));
			boxTo->setFocus();
			error=true;
			return false;
		}

		if (start>=end)
		{
			QMessageBox::critical(0,tr("Input error"),
					tr("Please enter scale limits that satisfy: from < to!"));
			boxTo->setFocus();
			return false;
		}

		if (! error)
			emit updateScale(axis,scaleOptions(axis, start, end,
						boxMajors->text(), boxMinors->text()));
	}

	if (generalDialog->currentWidget()==(QWidget*)axes)
	{
		axis=axesList2->currentRow();
		labels[axis] = boxLabel->text();
		emit updateLabel(axis, boxLabel->text(),axisFont(axis));
		emit updateTickLength(axis,boxMajorLength->text().toDouble(),
				boxMinorLength->text().toDouble());
	}

	return true;
}
Exemple #8
0
bool Optimize::eval_h(Ipopt::Index n, const Ipopt::Number *x,
                              bool new_x, Ipopt::Number obj_factor,
                              Ipopt::Index m, const Ipopt::Number *lambda, bool new_lambda,
                              Ipopt::Index nele_hess, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
{
    UNUSED(n);
    UNUSED(m);
    UNUSED(new_lambda);
    UNUSED(new_x);
    int idx_pv, idx_nv, idx_cv;
    Ipopt::Number e[3];
    int idx = 0;
    int i, size;
    int idx_pc;
    if (values == NULL)
    {
        i = 0, size = edges.size();
        for (; i < size; i++)
        {
            idx_pv = idxVertexEdges[i].first;
            idx_nv = idxVertexEdges[i].second;
            if (idx_pv >= 0)
            {
                setHessianPos(idx_pv, idx_pv, iRow, jCol, idx);
                if (idx_nv > idx_pv)
                {
                    setHessianPos(idx_nv, idx_pv, iRow, jCol, idx);
                }
            }
            if (idx_nv >= 0)
            {
                setHessianPos(idx_nv, idx_nv, iRow, jCol, idx);
                if (idx_pv > idx_nv)
                {
                    setHessianPos(idx_pv, idx_nv, iRow, jCol, idx);
                }
            }
        }

        i = 0;
        size = PositionConstraints.size();
        for (; i < size; i++)
        {
            idx_pc = PositionConstraints[i];
            setHessianPos(idx_pc, idx_pc, iRow, jCol, idx);
        }

        //Plane Constraints
        i = 0;
        size = PlaneConstraints.size();
        for (; i < size; ++i)
        {
            idx_pc = PlaneConstraints[i];
            setHessianPos_bending(idx_pc, idx_pc, iRow, jCol, idx);
        }

        //Bending energy
        i = 0;
        size = EnergyVertices.size();
        for (; i < size; ++i)
        {
            idx_pv = idxPrevVertex[i];
            idx_nv = idxNextVertex[i];
            idx_cv = idxTheVertex[i];
            if (idx_pv >= 0)
            {
                setHessianPos_bending(idx_pv, idx_pv, iRow, jCol, idx);
                if (idx_cv > idx_pv)
                {
                    setHessianPos_bending(idx_cv, idx_pv, iRow, jCol, idx);
                }
                if (idx_nv > idx_pv)
                {
                    setHessianPos_bending(idx_nv, idx_pv, iRow, jCol, idx);
                }
            }
            if (idx_nv >= 0)
            {
                setHessianPos_bending(idx_nv, idx_nv, iRow, jCol, idx);
                if (idx_pv > idx_nv)
                {
                    setHessianPos_bending(idx_pv, idx_nv, iRow, jCol, idx);
                }
                if (idx_cv > idx_nv)
                {
                    setHessianPos_bending(idx_cv, idx_nv, iRow, jCol, idx);
                }
            }
            if (idx_cv >= 0)
            {
                setHessianPos_bending(idx_cv, idx_cv, iRow, jCol, idx);
                if (idx_pv > idx_cv)
                {
                    setHessianPos_bending(idx_pv, idx_cv, iRow, jCol, idx);
                }
                if (idx_nv > idx_cv)
                {
                    setHessianPos_bending(idx_nv, idx_cv, iRow, jCol, idx);
                }
            }
        }
        int ref_E, ref_F, p, q;
        i = 0;
        size = crosses.size();
        for (; i < size; ++i)
        {
            for (ref_E = 1; ref_E < refSize - 1; ++ref_E)
            {
                if (crossE[i][ref_E] >= 0 && crossE[i][ref_E + 1] >= 0)
                {
                    setHessianPos_SkewSym(
                            crossE[i][ref_E],
                            crossE[i][ref_E + 1],
                            iRow, jCol, idx);
                }
            }
            for (ref_F = 1; ref_F < refSize - 1; ++ref_F)
            {
                if (crossF[i][ref_F] >= 0 && crossF[i][ref_F + 1] >= 0)
                {
                    setHessianPos_SkewSym(
                            crossF[i][ref_F],
                            crossF[i][ref_F + 1],
                            iRow, jCol, idx);
                }
            }
            for (ref_E = 1; ref_E < refSize; ++ref_E)
            {
                p = crossE[i][ref_E];
                if (p < 0) continue;
                for (ref_F = 1; ref_F < refSize; ++ref_F)
                {
                    q = crossF[i][ref_F];
                    if (q >= 0)
                    {
                        setHessianPos_SkewSym(p, q, iRow, jCol, idx);
                    }
                }
            }
        }
        for (; idx < nele_hess; idx++)
        {
            iRow[idx] = 0;
            jCol[idx] = 0;
        }
    }
    else
    {
        if (updateCross(x) == false) return false;
        double tmp = 0;
        setZeros(values, nele_hess);
        i = 0, size = edges.size();
        for (; i < size; i++)
        {
            computeEdge(i, x, e);
            idx_pv = idxVertexEdges[i].first;
            idx_nv = idxVertexEdges[i].second;
            if (idx_pv >= 0)
            {
                setHessianValues(idx, values, 2 * lambda[i]);
                if (idx_nv > idx_pv)
                {
                    setHessianValues(idx, values, -2 * lambda[i]);
                }
            }
            if (idx_nv >= 0)
            {
                setHessianValues(idx, values, 2 * lambda[i]);
                if (idx_pv > idx_nv)
                {
                    setHessianValues(idx, values, -2 * lambda[i]);
                }
            }
        }

        i = 0;
        size = PositionConstraints.size();
        tmp = 2 * pOp->PositionConstraintsWeight * obj_factor;
        for (; i < size; i++)
        {
            setHessianValues(idx, values, tmp);
        }

        //Plane constraints
        Point P;
        i = 0;
        size = PlaneConstraints.size();
        for (; i < size; ++i)
        {
            P = PlaneConstraintsInfo[i].first;
            setHessianVal_bending_helper(P * 2 * obj_factor * pOp->PlaneConstraintsCoef, P, values + idx, 0);
            idx += 6;
        }

        //Bending energy
        i = 0;
        size = EnergyVertices.size();
        for (; i < size; i++)
        {
            tmp = 2 * obj_factor * pOp->BendingEnergyCoef / VerticesWeight[i];
            idx_pv = idxPrevVertex[i];
            idx_nv = idxNextVertex[i];
            idx_cv = idxTheVertex[i];
            if (idx_pv >= 0)
            {
                setHessianValues_bending(i, idx_pv, idx_pv, idx, values, x, tmp);
                if (idx_cv > idx_pv)
                {
                    setHessianValues_bending(i, idx_cv, idx_pv, idx, values, x, tmp);
                }
                if (idx_nv > idx_pv)
                {
                    setHessianValues_bending(i, idx_nv, idx_pv, idx, values, x, tmp);
                }
            }
            if (idx_nv >= 0)
            {
                setHessianValues_bending(i, idx_nv, idx_nv, idx, values, x, tmp);
                if (idx_pv > idx_nv)
                {
                    setHessianValues_bending(i, idx_pv, idx_nv, idx, values, x, tmp);
                }
                if (idx_cv > idx_nv)
                {
                    setHessianValues_bending(i, idx_cv, idx_nv, idx, values, x, tmp);
                }
            }
            if (idx_cv >= 0)
            {
                setHessianValues_bending(i, idx_cv, idx_cv, idx, values, x, tmp);
                if (idx_pv > idx_cv)
                {
                    setHessianValues_bending(i, idx_pv, idx_cv, idx, values, x, tmp);
                }
                if (idx_nv > idx_cv)
                {
                    setHessianValues_bending(i, idx_nv, idx_cv, idx, values, x, tmp);
                }
            }
        }

        //crossing constraints
        int ref_E, ref_F, p, q;
        int base = edges.size();
        i = 0;
        size = crosses.size();
        for (; i < size; ++i)
        {
            for (ref_E = 1; ref_E < refSize - 1; ++ref_E)
            {
                if (crossE[i][ref_E] >= 0 && crossE[i][ref_E + 1] >= 0)
                {
                    setHessianValues_SkewSym(i, crossE[i][ref_E], crossE[i][ref_E + 1], values, idx, x, lambda[base + i]);
                }
            }
            for (ref_F = 1; ref_F < refSize - 1; ++ref_F)
            {
                if (crossF[i][ref_F] >= 0 && crossF[i][ref_F + 1] >= 0)
                {
                    setHessianValues_SkewSym(i, crossF[i][ref_F], crossF[i][ref_F + 1], values, idx, x, lambda[base + i]);
                }
            }
            for (ref_E = 1; ref_E < refSize; ++ref_E)
            {
                p = crossE[i][ref_E];
                if (p < 0) continue;
                for (ref_F = 1; ref_F < refSize; ++ref_F)
                {
                    q = crossF[i][ref_F];
                    if (q >= 0)
                    {
                        setHessianValues_SkewSym(i, p, q, values, idx, x, lambda[base + i]);
                    }
                }
            }
        }

    }
    assert(idx <= nele_hess);

    return true;
}
Exemple #9
0
bool Optimize::eval_jac_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x,
                        Ipopt::Index m, Ipopt::Index nele_jac,
                        Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
{
    UNUSED(n);
    UNUSED(m);
    UNUSED(new_x);

    Ipopt::Number e[3];
    int idx_nv, idx_pv;
    int idx = 0;
    if (values == NULL)
    {

        int i = 0, size = edges.size();
        for (; i < size; i++)
        {
            idx_pv = idxVertexEdges[i].first;
            idx_nv = idxVertexEdges[i].second;
            if (idx_pv >= 0)
            {
                iRow[idx] = i;
                iRow[idx + 1] = i;
                iRow[idx + 2] = i;
                jCol[idx] = 3 * idx_pv;
                jCol[idx + 1] = 3 * idx_pv + 1;
                jCol[idx + 2] = 3 * idx_pv + 2;
                idx += 3;
            }
            if (idx_nv >= 0)
            {
                iRow[idx] = i;
                iRow[idx + 1] = i;
                iRow[idx + 2] = i;
                jCol[idx] = 3 * idx_nv;
                jCol[idx + 1] = 3 * idx_nv + 1;
                jCol[idx + 2] = 3 * idx_nv + 2;
                idx += 3;
            }
        }
        int ref;
        int end = crosses.size();
        i = 0;
        for (; i < end; ++i)
        {
            for (ref = 1; ref < refSize; ++ref)
            {
                setJacGPos_cross(ref, size, i, idx, iRow, jCol);
            }
        }
        for (; idx < nele_jac; idx++)
        {
            iRow[idx] = 0;
            jCol[idx] = 0;
        }
    }
    else
    {
        if (updateCross(x) == false) return false;
        setZeros(values, nele_jac);
        int i = 0, size = edges.size();
        for (; i < size; i++)
        {
            computeEdge(i, x, e);
            idx_pv = idxVertexEdges[i].first;
            idx_nv = idxVertexEdges[i].second;
            if (idx_pv >= 0)
            {
                multiplyByScale(e, -2, values + idx);
                idx += 3;
            }
            if (idx_nv >= 0)
            {
                multiplyByScale(e, 2, values + idx);
                idx += 3;
            }
        }
        int ref;
        int end = crosses.size();
        i = 0;
        for (; i < end; ++i)
        {
            for (ref = 1; ref < refSize; ++ref)
            {
                setJacGVal_cross(ref, i, idx, values, x);
            }
        }
    }
    assert(idx <= nele_jac);

    return true;
}
Exemple #10
0
bool Optimize::eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)
{
    assert(n == n_variables);
    UNUSED(new_x);
    if (updateCross(x) == false) return false;
    Ipopt::Number t1[3], t2[3], t[3], e[3], f[3], tmp;
    Ipopt::Number* pV;
    PointArrayEdit pf = grad_f;
    PointArray px = x;
    setZeros(grad_f, n);
    int idx;
    int i = 0, size = EnergyVertices.size();
    for (; i < size; i++)
    {
        computeEF(i, x, e, f);
        tmp = EdgesLengthProduct[i] + dot(e,f);
        tmp *= tmp;
        tmp = 4 * pOp->BendingEnergyCoef * EdgesLengthProduct[i]/ VerticesWeight[i] / tmp;
        idx = idxPrevVertex[i];
        multiplyByScale(f, tmp, t1);
        if (idx >= 0)
            addTo(t1, pf(idx));
        multiplyByScale(e, -tmp, t2);
        idx = idxNextVertex[i];
        if (idx >= 0)
            addTo(t2, pf(idx));
        idx = idxTheVertex[i];
        if (idx >= 0)
        {
            add(t1, t2, t);
            multiplyByScaleTo(t, -1, pf(idx));
        }
    }
    i = 0;
    size = PositionConstraints.size();
    for (; i < size; i++)
    {
        idx = PositionConstraints[i];
        pV = positions[i].data();
        sub(px(idx), pV, t);
        multiplyByScaleTo(t, 2 * pOp->PositionConstraintsWeight, pf(idx));
    }
    i = 0;
    size = TangentConstraints.size();
    for (; i < size; ++i)
    {
        pV = tangents[i].data();
        idx = TangentConstraints[i].first;
        if (idx >= 0)
            multiplyByScaleTo(pV, pOp->TangentConstraintsCoef, pf(idx));
        idx = TangentConstraints[i].second;
        if (idx >= 0)
            multiplyByScaleTo(pV, -pOp->TangentConstraintsCoef, pf(idx));
    }

    Point P;
    i = 0;
    size = PlaneConstraints.size();
    for (; i < size; ++i)
    {
        idx = PlaneConstraints[i];
        P = PlaneConstraintsInfo[i].first;
        tmp = 2 * ((P | getPoint(idx, x)) + PlaneConstraintsInfo[i].second);
        multiplyByScaleTo(P.data(), tmp * pOp->PlaneConstraintsCoef, pf(idx));
    }
    return true;
}