Ejemplo n.º 1
0
void Util_Move_Object_Class::changedRotation(){
    if (qAbs(rotateTo.x()) < 5 && qAbs(rotateTo.z()) < 5 && qAbs(rotateTo.y()) < 5){
        emit newRotation(rotateTo.x(), rotateTo.y(),  rotateTo.z());
        rotateTo = QVector3D(0, 0, 0);
        rotateTimer->stop();
        emit rotationOver();
    }
    else{
        emit newRotation(intervalleRotate.first().x(), intervalleRotate.first().y(),  intervalleRotate.first().z());
        rotateTo -= intervalleRotate.first();
        intervalleRotate.removeFirst();

    }

}
Ejemplo n.º 2
0
    hkResult HavokDisplayManager::addGeometry(const hkArrayBase<hkDisplayGeometry*>& geometries, const hkTransform& transform, hkUlong id, int tag, hkUlong shapeIdHint, hkGeometry::GeometryType createDyanamicGeometry /*= hkGeometry::GEOMETRY_STATIC*/)
    {
        auto& a = m_geometries[id];
       
        vec3 newTranslation(DO_NOT_INITIALIZE);
        Quaternion newRotation(DO_NOT_INITIALIZE);
        gep::conversion::hk::fromHkTransform(transform, newTranslation, newRotation);
        mat4 newTransform =  mat4::translationMatrix(newTranslation) * newRotation.toMat4() ;
        m_transformations[id] = newTransform;
        
        for (auto geom : geometries)
        {
           
            geom->buildGeometry();
            auto pGeom = geom->getGeometry();
            auto pDataHolder = GEP_NEW(g_stdAllocator, HavokDataHolder)(geom, pGeom->m_triangles);
            auto vertices = ArrayPtr<vec4>((vec4*)&pGeom->m_vertices[0], pGeom->m_vertices.getSize());
            auto indices = pDataHolder->getIndices();

            auto pModel = g_globalManager.getRenderer()->loadModel(pDataHolder, vertices, indices);
            a.append(pModel);
        }

        return HK_SUCCESS;
    }
Ejemplo n.º 3
0
void Util_Move_Object_Class::RotateObjectTo(double angleX, double angleY, double angleZ, int time, Function::Type easingType){
    rotateTimer->stop();
    intervalleRotate.clear();
    emit newRotation(rotateTo.x(), rotateTo.y(),  rotateTo.z());
    calculIntervalle(angleX, angleY, angleZ, time, easingType);
    rotateTo = QVector3D(angleX, angleY, angleZ);
    rotateTimer->start(16);
}
Ejemplo n.º 4
0
void Friend::newAction(){
    int action = rand() % 4;

    if(action == 0){
        newTarget();
    }else{
        newRotation();
    }
}
Ejemplo n.º 5
0
 hkResult HavokDisplayManager::updateGeometry(const hkTransform& transform, hkUlong id, int tag)
 {
     vec3 newTranslation(DO_NOT_INITIALIZE);
     Quaternion newRotation(DO_NOT_INITIALIZE);
     gep::conversion::hk::fromHkTransform(transform, newTranslation, newRotation);
     mat4 newTransform =  mat4::translationMatrix(newTranslation) * newRotation.toMat4();
     m_transformations[id] = newTransform;
     
     return HK_SUCCESS;
 }
Ejemplo n.º 6
0
void Util_Move_Object_Class::changedCameraRotation(){
    if (!intervalleRotate.isEmpty()){
        emit newRotation(intervalleRotate.first().x(), intervalleRotate.first().y(),  intervalleRotate.first().z());
        rotateTo -= intervalleRotate.first();
        intervalleRotate.removeFirst();
        emit rotationCameraOver();
    }
    else {
        rotateCameraTimer->stop();
    }

}
void DynamicsMotionState::setWorldTransform(const btTransform& transform)
{
//  DALI_LOG_INFO(Debug::Filter::gDynamics, Debug::Verbose, "%s\n", __PRETTY_FUNCTION__);

  // get updated parameters
  const btVector3& origin( transform.getOrigin() );
  const btQuaternion rotation( transform.getRotation() );
  const btVector3& axis( rotation.getAxis() );
  const btScalar& angle( rotation.getAngle() );

  Vector3 newPosition( origin.x(), origin.y(), origin.z() );
  const Vector3 newAxis( axis.x(), axis.y(), axis.z() );
  Quaternion newRotation( float(angle), newAxis );

  // set the nodes updated params
  mDynamicsBody.SetNodePositionAndRotation( newPosition, newRotation );
}
Ejemplo n.º 8
0
TransformDialog::TransformDialog(QWidget* parent, ScribusDoc *doc) : QDialog(parent)
{
	setupUi(this);
	setModal(true);
	setWindowIcon(QIcon(loadIcon ( "AppIcon.png" )));
	transformStack->setCurrentIndex(0);
	newTransformMenu = new QMenu(buttonAdd);
	newTransformMenu->addAction( tr("Scaling"), this, SLOT(newScaling()));
	newTransformMenu->addAction( tr("Translation"), this, SLOT(newTranslation()));
	newTransformMenu->addAction( tr("Rotation"), this, SLOT(newRotation()));
	newTransformMenu->addAction( tr("Skewing"), this, SLOT(newSkewing()));
	buttonAdd->setMenu(newTransformMenu);
	scaleLink->setChecked(true);
	buttonUp->setText( "" );
	buttonUp->setIcon(loadIcon("16/go-up.png"));
	buttonDown->setText( "" );
	buttonDown->setIcon(loadIcon("16/go-down.png"));
	buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
	m_doc = doc;
	m_unitRatio = unitGetRatioFromIndex(m_doc->unitIndex());
	m_suffix = unitGetSuffixFromIndex(m_doc->unitIndex());
	translateHorizontal->setSuffix(m_suffix);
	translateVertical->setSuffix(m_suffix);
	rotationValue->setWrapping( true );
	rotationValue->setValues( -180.0, 180.0, 1, 0);
	rotationValue->setSuffix(unitGetSuffixFromIndex(6));
	horizontalSkew->setSuffix(unitGetSuffixFromIndex(6));
	verticalSkew->setSuffix(unitGetSuffixFromIndex(6));
	linkSkew->setChecked(true);
	numberOfCopies->setValue(0);
	basePoint->setCheckedId(m_doc->RotMode);
	connect(transformSelector, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(setCurrentTransform(QListWidgetItem*)));
	connect(horizontalScale, SIGNAL(valueChanged(double)), this, SLOT(changeHScale(double)));
	connect(verticalScale, SIGNAL(valueChanged(double)), this, SLOT(changeVScale(double)));
	connect(scaleLink, SIGNAL(clicked()), this, SLOT(toggleLink()));
	connect(translateHorizontal, SIGNAL(valueChanged(double)), this, SLOT(changeHTranslation(double)));
	connect(translateVertical, SIGNAL(valueChanged(double)), this, SLOT(changeVTranslation(double)));
	connect(rotationValue, SIGNAL(valueChanged(double)), this, SLOT(changeRotation(double)));
	connect(horizontalSkew, SIGNAL(valueChanged(double)), this, SLOT(changeHSkew(double)));
	connect(verticalSkew, SIGNAL(valueChanged(double)), this, SLOT(changeVSkew(double)));
	connect(linkSkew, SIGNAL(clicked()), this, SLOT(toggleLinkSkew()));
	connect(buttonUp, SIGNAL(clicked()), this, SLOT(moveTransformUp()));
	connect(buttonDown, SIGNAL(clicked()), this, SLOT(moveTransformDown()));
	connect(buttonRemove, SIGNAL(clicked()), this, SLOT(removeTransform()));
}
Ejemplo n.º 9
0
void handleUpdate(UpdateEventDetails* const details,
                  PhysicsBody* const CharacterPhysicsBody,
                  PhysicsLMotorJoint* const CharacterMover)
{
    ForceOnCharacter.setValues(0.0,0.0,0.0);
    Real32 PushForce(55000.0);
    Real32 Speed(10.0);
    if(_IsUpKeyDown)
    {
        ForceOnCharacter += Vec3f(0.0, PushForce, 0.0);
    }
    if(_IsDownKeyDown)
    {
        ForceOnCharacter += Vec3f(0.0, -PushForce, 0.0);
    }
    if(_IsLeftKeyDown)
    {
        ForceOnCharacter += Vec3f(-PushForce, 0.0, 0.0);
    }
    if(_IsRightKeyDown)
    {
        ForceOnCharacter += Vec3f(PushForce, 0.0, 0.0);
    }
    if(_ShouldJump)
    {
        ForceOnCharacter += Vec3f(0.0, 0.0, 50000.0);
        _ShouldJump = false;
    }
    if(ForceOnCharacter != Vec3f(0.0,0.0,0.0))
    {
        CharacterPhysicsBody->setEnable(true);
    }
    if(ForceOnCharacter.x() !=0.0)
    {
        CharacterMover->setFMax(osgAbs(ForceOnCharacter.x()));
        CharacterMover->setVel(osgSgn(ForceOnCharacter.x())*Speed);
    }
    else
    {
        CharacterMover->setFMax(0.0);
        CharacterMover->setVel(0.0);
    }
    if(ForceOnCharacter.y() !=0.0)
    {
        CharacterMover->setFMax2(osgAbs(ForceOnCharacter.y()));
        CharacterMover->setVel2(osgSgn(ForceOnCharacter.y())*Speed);
    }
    else
    {
        CharacterMover->setFMax2(0.0);
        CharacterMover->setVel2(0.0);
    }
    if(ForceOnCharacter.z() !=0.0)
    {
        CharacterMover->setFMax3(osgAbs(ForceOnCharacter.z()));
        CharacterMover->setVel3(osgSgn(ForceOnCharacter.z())*Speed);
    }
    else
    {
        CharacterMover->setFMax3(0.0);
        CharacterMover->setVel3(0.0);
    }

    Real32 RotationRate(1.57);
    if(_IsAKeyDown)
    {
        Quaternion newRotation(CharacterPhysicsBody->getQuaternion());
        newRotation.mult(Quaternion(Vec3f(0.0,0.0,1.0),RotationRate*details->getElapsedTime()));
        CharacterPhysicsBody->setQuaternion( newRotation );
    }
    if(_IsDKeyDown)
    {
        Quaternion newRotation(CharacterPhysicsBody->getQuaternion());
        newRotation.mult(Quaternion(Vec3f(0.0,0.0,1.0),-RotationRate*details->getElapsedTime()));
        CharacterPhysicsBody->setQuaternion( newRotation );
    }
}
void CreatureEvolver::Mutate(CreatureGenes* pGenes)
{
	// Change limb count
	if(Randf() < m_limbCountMutationRate)
	{
		int dCount = Round_Nearest(Randf(-m_maxLimbPerturbation, m_maxLimbPerturbation));

		const int newSize = pGenes->m_pLimbGenes.size() + dCount;

		if(newSize < m_minNumLimbs)
			dCount = m_minNumLimbs - pGenes->m_pLimbGenes.size();
		else if(newSize > m_maxNumLimbs)
			dCount = m_maxNumLimbs - pGenes->m_pLimbGenes.size();

		if(dCount > 0)
		{
			for(int i = 0; i < dCount; i++)
			{
				LimbGenes* pNewLimbGenes = new LimbGenes();

				InitGenes(pNewLimbGenes, pGenes->m_pLimbGenes.size() + 1);

				pGenes->m_pLimbGenes.push_back(pNewLimbGenes);
			}
		}
		else if(dCount < 0) // Remove random limbs
		{
			dCount = -dCount;

			for(int i = 0; i < dCount && static_cast<signed>(pGenes->m_pLimbGenes.size()) > m_minNumLimbs; i++)
			{
				unsigned int index = rand() % pGenes->m_pLimbGenes.size();
				delete pGenes->m_pLimbGenes[index];
				pGenes->m_pLimbGenes[index] = NULL;
				pGenes->m_pLimbGenes.erase(pGenes->m_pLimbGenes.begin() + index);
			}
		}

		assert(pGenes->m_pLimbGenes.size() >= static_cast<unsigned>(m_minNumLimbs));
	}

	for(unsigned int i = 0, size = pGenes->m_pLimbGenes.size(); i < size; i++)
	{
		LimbGenes* pLG = pGenes->m_pLimbGenes[i];

		if(i != 0 && Randf() < m_limbParentMutationRate)
		{
			pLG->m_parentIndexOffset = pLG->m_parentIndexOffset + rand() % 3 - 1;

			if(pLG->m_parentIndexOffset < 1)
				pLG->m_parentIndexOffset = 1;
			else if(pLG->m_parentIndexOffset > static_cast<signed>(i))
				pLG->m_parentIndexOffset = static_cast<signed>(i);
		}

		if(pLG->m_recursiveUnits != 0 && Randf() < m_recursiveLimbMutationRate_whenRecursive)
			pLG->m_recursiveUnits = 0;
		else if(Randf() < m_recursiveLimbMutationRate_whenNotRecursive)
			pLG->m_recursiveUnits = rand() % (m_maxInitRecursiveUnits - m_minInitRecursiveUnits) + m_minInitRecursiveUnits;
		else if(Randf() < m_recursiveLimbUnitCountChangeRate)
			pLG->m_recursiveUnits = Clamp(pLG->m_recursiveUnits + rand() % 3 - 1, 0, m_maxInitRecursiveUnits);

		if(pLG->m_symmetrical && Randf() < m_symmetricalLimbMutationRate_whenSymmetrical)
			pLG->m_symmetrical = false;
		else if(Randf() < m_symmetricalLimbMutationRate_whenNotSymmetrical)
			pLG->m_symmetrical = true;

		if(Randf() < m_numBranchesMutationRate)
			pLG->m_numBranches = Clamp(pLG->m_numBranches + rand() % 3 - 1, 0, m_maxNumBranches);

		if(Randf() < m_inheritRecursionMutationRate)
			pLG->m_inheritsRecursion = Randf() < m_initInheritRecursionChance;

		if(Randf() < m_inheritSymmetryMutationRate)
			pLG->m_inheritsSymmetry = Randf() < m_initInheritSymmetryChance;

		if(Randf() < m_dimensionalMutationRate)
		{
			pLG->m_dims.x = Clamp(pLG->m_dims.x + Randf(-m_maxLimbDimensionPerturbation, m_maxLimbDimensionPerturbation), m_minLimbDimension, m_maxLimbDimension);
			pLG->m_dims.y = Clamp(pLG->m_dims.y + Randf(-m_maxLimbDimensionPerturbation, m_maxLimbDimensionPerturbation), m_minLimbDimension, m_maxLimbDimension);
			pLG->m_dims.z = Clamp(pLG->m_dims.z + Randf(-m_maxLimbDimensionPerturbation, m_maxLimbDimensionPerturbation), m_minLimbDimension, m_maxLimbDimension);
		}

		if(Randf() < m_relativeOffsetRatioMutationRate)
			AttachmentPositionMutate_Parent(pLG->m_relativeAttachmentPositionOnParent);

		if(Randf() < m_relativeOffsetRatioMutationRate)
			AttachmentPositionMutate_This(pLG->m_relativeAttachmentPositionOnThis);

		if(Randf() < m_limbAngleMutationRate)
		{
			Quaternion newRotation(pLG->m_relativeRotation);

			newRotation.x += Randf(-m_maxLimbAnglePerturbation, m_maxLimbAnglePerturbation);
			newRotation.y += Randf(-m_maxLimbAnglePerturbation, m_maxLimbAnglePerturbation);
			newRotation.z += Randf(-m_maxLimbAnglePerturbation, m_maxLimbAnglePerturbation);
			newRotation.w += Randf(-m_maxLimbAnglePerturbation, m_maxLimbAnglePerturbation);

			newRotation.NormalizeThis();

			Vec3f normal(NormalFromPosition(pLG->m_relativeAttachmentPositionOnParent));

			// If perturbed angle is legal, set it
			if((newRotation * Vec3f(1.0f, 0.0f, 0.0f)).Dot(normal) > 0.0f)
				pLG->m_relativeRotation = newRotation;
			else
			{
				// Not legal, get one that is for sure
				float currentAngle = acosf(normal.Dot(pLG->m_relativeRotation * Vec3f(1.0f, 0.0f, 0.0f)));
				float maxAdditionalAngle = pLG->m_bendLimit - currentAngle;

				newRotation.Reset();

				// Random axis
				Vec3f axis(Randf(-1.0f, 1.0f), Randf(-1.0f, 1.0f), Randf(-1.0f, 1.0f));
				axis.NormalizeThis();

				newRotation.Rotate(Randf() * maxAdditionalAngle, axis);

				pLG->m_relativeRotation *= newRotation;
			}
		}

		if(Randf() < m_limbBendAndTwistMutationRate)
			pLG->m_bendLimit = Clamp(pLG->m_bendLimit + Randf(-m_maxLimbBendAndTwistPerturbation, m_maxLimbBendAndTwistPerturbation), m_minLimbBend, m_maxLimbBend);

		if(Randf() < m_limbBendAndTwistMutationRate)
			pLG->m_twistLimit = Clamp(pLG->m_twistLimit + Randf(-m_maxLimbBendAndTwistPerturbation, m_maxLimbBendAndTwistPerturbation), m_minLimbTwist, m_maxLimbTwist);

		if(Randf() < m_limbStrengthMutationRate)
			pLG->m_strength = Clamp(pLG->m_strength + Randf(-m_maxLimbStrengthPerturbation, m_maxLimbStrengthPerturbation), m_minLimbStrength, m_maxLimbStrength);

		if(Randf() < m_densityMutationRate)
			pLG->m_density = Clamp(pLG->m_density + Randf(-m_maxDensityPerturbation, m_maxDensityPerturbation), m_minDensity, m_maxDensity);

		if(Randf() < m_frictionMutationRate)
			pLG->m_friction = Clamp(pLG->m_friction + Randf(-m_maxFrictionPerturbation, m_maxFrictionPerturbation), m_minFriction, m_maxFriction);

		if(Randf() < m_contactSensorMutationRate)
			pLG->m_hasContactSensor = !pLG->m_hasContactSensor;

		if(Randf() < m_mainBrainInputNeuronsMutationRate)
		{
			int choice = rand() % 2;

			if(choice == 1)
				pLG->m_mainBrainInputNeurons.push_back(rand() % (m_maxNumMainBrainInputNeurons + 1));
			else if(!pLG->m_mainBrainInputNeurons.empty())
				pLG->m_mainBrainInputNeurons.erase(pLG->m_mainBrainInputNeurons.begin() + rand() % pLG->m_mainBrainInputNeurons.size());
		}

		if(Randf() < m_parentLimbInputNeuronsMutationRate)
		{
			int choice = rand() % 2;

			if(choice == 1)
				pLG->m_parentLimbInputNeurons.push_back(rand() % (m_maxNumParentLimbInputNeurons + 1));
			else if(!pLG->m_parentLimbInputNeurons.empty())
				pLG->m_parentLimbInputNeurons.erase(pLG->m_parentLimbInputNeurons.begin() + rand() % pLG->m_parentLimbInputNeurons.size());
		}

		if(Randf() < m_childLimbInputNeuronsMutationRate)
		{
			int choice = rand() % 2;

			if(choice == 1)
			{
				LimbGenes::ChildAndOutputIndex coai;
				coai.m_childIndex = rand() % m_maxNumBranches;
				coai.m_outputIndex = rand() % m_maxNumChildLimbInputNeurons;

				pLG->m_childLimbInputNeurons.push_back(coai);
			}
			else if(!pLG->m_childLimbInputNeurons.empty())
				pLG->m_childLimbInputNeurons.erase(pLG->m_childLimbInputNeurons.begin() + rand() % pLG->m_childLimbInputNeurons.size());
		}

		// Mutate weights before changing structure randomly
		for(unsigned int j = 0, numNeurons = pLG->m_neuronData.size(); j < numNeurons; j++)
		{
			//if(Randf() < m_neuralWeightMutationRate)
			//	pLG->m_neuronData[j].m_threshold = Clamp(pLG->m_neuronData[j].m_threshold + Randf(-m_neuralWeightPerturbation, m_neuralWeightPerturbation), -1.0f, 1.0f);

			for(unsigned int k = 0, numWeights = pLG->m_neuronData[j].m_weights.size(); k < numWeights; k++)
				if(Randf() < m_neuralWeightMutationRate)
					pLG->m_neuronData[j].m_weights[k] = Clamp(pLG->m_neuronData[j].m_weights[k] + Randf(-m_neuralWeightPerturbation, m_neuralWeightPerturbation), m_minPossibleNeuronWeight, m_maxPossibleNeuronWeight);
		}

		// Mutate timers before changing structure randomly
		for(unsigned int j = 0, numTimers = pLG->m_timerSensorData.size(); j < numTimers; j++)
		{
			if(Randf() < m_timerRateMutationRate)
				pLG->m_timerSensorData[j].m_rate = Clamp(pLG->m_timerSensorData[j].m_rate + Randf(-m_maxTimerRatePerturbation, m_maxTimerRatePerturbation), m_minTimerRate, m_maxTimerRate);

			if(Randf() < m_timerTimeMutationRate)
				pLG->m_timerSensorData[j].m_initTime = Clamp(pLG->m_timerSensorData[j].m_initTime + Randf(-m_maxTimerTimePerturbation, m_maxTimerTimePerturbation), 0.0f, 1.0f);
		}

		// Mutate neuron structure
		if(Randf() < m_neuralStructureMutationRate_numLayers)
			pLG->m_numHiddenLayers = Clamp(pLG->m_numHiddenLayers + rand() % 3 - 1, m_minHiddenLayers, m_maxHiddenLayers);

		if(Randf() < m_neuralStructureMutationRate_numNeuronsPerHiddenLayer)
		{
			int pert = static_cast<int>(Randf(-m_maxNeuronsPerHiddenLayerPerturbation, m_maxNeuronsPerHiddenLayerPerturbation));
			int nphl = Clamp(static_cast<signed>(pLG->m_numNeuronsPerHiddenLayer) + pert, static_cast<signed>(m_minNeuronsPerHiddenLayer), static_cast<signed>(m_maxNeuronsPerHiddenLayer));

			pLG->m_numNeuronsPerHiddenLayer = static_cast<unsigned>(nphl);
		}

		// Mutate number of timers
		if(Randf() < m_timerCountMutationRate)
			pLG->m_numTimerSensors = Clamp(pLG->m_numTimerSensors + rand() % 3 - 1, m_minTimerCount, m_maxTimerCount);
	}
}
Transformation Transformation::newRotationAroundPoint(double graus, const Coordinate& p){
    return newTranslation(-p.x, -p.y) * newRotation(graus) * newTranslation(p.x, p.y);
}