コード例 #1
0
ファイル: Terrain.cpp プロジェクト: weimingtom/fdux-slg-game
int Terrain::createMapObj(int x, int y, std::string meshname, int dir)
{
	stTileEntityData* entitydata = new stTileEntityData;
	entitydata->mTileEntity = Core::getSingleton().mSceneMgr->createEntity(meshname);
	entitydata->mTileNode = mTerrainNode->createChildSceneNode();
	entitydata->mTileNode->attachObject(entitydata->mTileEntity);
	float xx,yy;
	getWorldCoords(x,y,xx,yy);
	entitydata->mTileNode->setPosition(xx ,getHeight(xx,yy),yy);

	Ogre::Quaternion q;
	switch(dir)
	{
	case North:
		q.FromAngleAxis(Ogre::Degree(180),Ogre::Vector3(0,1,0));
		break;
	case South:
		q.FromAngleAxis(Ogre::Degree(360),Ogre::Vector3(0,1,0));
		break;
	case West:
		q.FromAngleAxis(Ogre::Degree(270),Ogre::Vector3(0,1,0));
		break;
	case East:
		q.FromAngleAxis(Ogre::Degree(90),Ogre::Vector3(0,1,0));
		break;
	}
	entitydata->mTileNode->setOrientation(q);
	mObjId ++;
	mMapObjMap.insert(std::map<int, stTileEntityData*>::value_type(mObjId,entitydata ));
	return mObjId;
}
コード例 #2
0
ファイル: AACamera.cpp プロジェクト: beorc/flare_star
void AACamera::ProcessKeyInput(OIS::Keyboard *mKeyboard)
{
    static unsigned RollSpeed = 5;
    if (mKeyboard->isKeyDown(OIS::KC_RIGHT))
    {		
        if (abs(RelativeOrientation.getRoll().valueDegrees())<10)
        {
            Ogre::Quaternion q;
            q.FromAngleAxis(-Ogre::Degree(RollSpeed),Ogre::Vector3::UNIT_Z);
            CameraAdditionalRotation.StartRotation(RelativeOrientation, RelativeOrientation*q, CommonDeclarations::GetFPS());			
        }		
    }
    else
        if(mKeyboard->isKeyDown(OIS::KC_LEFT))
        {
            if (abs(RelativeOrientation.getRoll().valueDegrees())<10)
            {
                Ogre::Quaternion q;
                q.FromAngleAxis(Ogre::Degree(RollSpeed),Ogre::Vector3::UNIT_Z);
                CameraAdditionalRotation.StartRotation(RelativeOrientation, RelativeOrientation*q, CommonDeclarations::GetFPS());				
            }			
        }
        else
        {
            if (RelativeOrientation!=Ogre::Quaternion::IDENTITY)			
            {
                Ogre::Quaternion q = Ogre::Quaternion::IDENTITY;
                CameraAdditionalRotation.StartRotation(RelativeOrientation, q, CommonDeclarations::GetFPS());				
            }
        }
}
コード例 #3
0
ファイル: OgreMacro.cpp プロジェクト: Nobu19800/OgreRTC
/**
*@brief 角度からクオータニオンを取得する関数
* @param path 角度(ロール)
* @param path 角度(ピッチ)
* @param path 角度(ヨー)
* @return クォータニオン
*/
Ogre::Quaternion GetRotQuat(float roll, float pitch, float yaw)
{
	Ogre::Quaternion tRoll; 
	tRoll.FromAngleAxis(Ogre::Degree(roll),Ogre::Vector3(1,0,0));
	Ogre::Quaternion tPitch;
	tPitch.FromAngleAxis(Ogre::Degree(pitch),Ogre::Vector3(0,1,0));
	Ogre::Quaternion tYaw;
	tYaw.FromAngleAxis(Ogre::Degree(yaw),Ogre::Vector3(0,0,1));
	tRoll = tRoll * tPitch;
	tRoll = tRoll * tYaw;

	return tRoll;
}
コード例 #4
0
ファイル: GameState.cpp プロジェクト: firbaOne/My-first-game
void GameState::generateEnvironment()
{
	
	Ogre::StaticGeometry *sg = mSceneMgr->createStaticGeometry("Asteroids");
	const int size = 7000;
    const int amount = 5;
	sg->setRegionDimensions(Ogre::Vector3(size, size, size));
	//sg->setOrigin(Ogre::Vector3(-size/2, 0, -size/2));
	sg->setOrigin(Vector3(-size/2, -size/2, -size/2) + Vector3(0, 0, 0)); // this will center the staticgeometry around the point in 3D space
	for (int x = -size/2; x < size/2; x += (size/amount))
	{
		for (int y = -size/2; y < size/2; y += (size/amount))
		{
			for (int z = -size/2; z < size/2; z += (size/amount))
			{
					Ogre::Real r = size / (float)amount / 2;
					Ogre::Vector3 pos(x + Ogre::Math::RangeRandom(-r, r), y + Ogre::Math::RangeRandom(-r, r), z + Ogre::Math::RangeRandom(-r, r));
					Ogre::Vector3 scale(Ogre::Math::RangeRandom(0.7, 20), Ogre::Math::RangeRandom(0.7, 20), Ogre::Math::RangeRandom(0.7, 20));
					Ogre::Quaternion orientation;
					orientation.FromAngleAxis(Ogre::Degree(Ogre::Math::RangeRandom(0, 359)), Ogre::Vector3::UNIT_Y);
					MyEntity * ent = new MyEntity("asteroid1.mesh", mSceneMgr, mWorld, pos);
					ent->transform(orientation, Ogre::Vector3::ZERO);
					//ent->setScale(scale);
					sg->addEntity(ent->getEntity(), pos, orientation/*, scale*/);
			}
		}
	}
	sg->build();

	

}
コード例 #5
0
ファイル: Util.cpp プロジェクト: agudpp/CordobaZombie
Ogre::Quaternion Util::parseQuaternion(TiXmlElement *XMLNode)
{
	Ogre::Quaternion orientation;

	if(XMLNode->Attribute("qx"))
	{
		orientation.x = Ogre::StringConverter::parseReal(XMLNode->Attribute("qx"));
		orientation.y = Ogre::StringConverter::parseReal(XMLNode->Attribute("qy"));
		orientation.z = Ogre::StringConverter::parseReal(XMLNode->Attribute("qz"));
		orientation.w = Ogre::StringConverter::parseReal(XMLNode->Attribute("qw"));
	}
	else if(XMLNode->Attribute("axisX"))
	{
		Ogre::Vector3 axis;
		axis.x = Ogre::StringConverter::parseReal(XMLNode->Attribute("axisX"));
		axis.y = Ogre::StringConverter::parseReal(XMLNode->Attribute("axisY"));
		axis.z = Ogre::StringConverter::parseReal(XMLNode->Attribute("axisZ"));
		Ogre::Real angle = Ogre::StringConverter::parseReal(XMLNode->Attribute("angle"));;
		orientation.FromAngleAxis(Ogre::Angle(angle), axis);
	}
	else if(XMLNode->Attribute("angleX"))
	{
		Ogre::Vector3 axis;
		axis.x = Ogre::StringConverter::parseReal(XMLNode->Attribute("angleX"));
		axis.y = Ogre::StringConverter::parseReal(XMLNode->Attribute("angleY"));
		axis.z = Ogre::StringConverter::parseReal(XMLNode->Attribute("angleZ"));
		//orientation.FromAxes(&axis);
		//orientation.F
	}

	return orientation;
}
コード例 #6
0
ファイル: OgreAllVehicle.cpp プロジェクト: landys/cute-car
void OgreWheel::updateWheel(const float angle)
{
	// Render change angle
	Ogre::Quaternion qq;
	qq.FromAngleAxis(Ogre::Radian(-angle)*5, Ogre::Vector3(0, 1, 0));
	mNode->setOrientation(qq);
}
コード例 #7
0
void OgreApplication::SetupAnimation(Ogre::String object_name){

	/* Retrieve scene manager and root scene node */
    Ogre::SceneManager* scene_manager = ogre_root_->getSceneManager("MySceneManager");
	Ogre::SceneNode* root_scene_node = scene_manager->getRootSceneNode();

	/* Set up animation */
	Ogre::Real duration = Ogre::Math::TWO_PI;
	Ogre::Real num_steps = 36;
	Ogre::Real step = duration/num_steps;
	Ogre::Animation* animation = scene_manager->createAnimation("Animation", duration);
	animation->setInterpolationMode(Ogre::Animation::IM_LINEAR);
	Ogre::Node *object_scene_node = root_scene_node->getChild(object_name);
	Ogre::NodeAnimationTrack* track = animation->createNodeTrack(0, object_scene_node);

	/* Set up frames for animation */
	Ogre::TransformKeyFrame* key;
	Ogre::Quaternion quat;
	for (int i = 0; i < num_steps; i++){
		Ogre::Real current = ((float) i) * step;
		key = track->createNodeKeyFrame(current);
		quat.FromAngleAxis(Ogre::Radian(-current), Ogre::Vector3(0, 1, 0));
		key->setRotation(quat);
		key->setScale(Ogre::Vector3(0.5, 0.5, 0.5));
	}

	/* Create animation state */
	animation_state_ = scene_manager->createAnimationState("Animation");
	animation_state_->setEnabled(true);
	animation_state_->setLoop(true);

	/* Turn on animating flag */
	animating_ = true;
}
コード例 #8
0
ファイル: SceneEntity.cpp プロジェクト: dtbinh/AncelApp
void SceneEntity::setRotation(float angel)
{
	mRotateAngel = angel;
	Ogre::Quaternion ori;
	ori.FromAngleAxis(Ogre::Radian(Ogre::Math::PI/180*mRotateAngel),Ogre::Vector3(0,1,0));
	mSceneNode->setOrientation(ori);
}
コード例 #9
0
void OgrePointSpecification::setLocalRotation(const VEHA::RotationVector& orientation)
{
	Ogre::Quaternion q;
	Ogre::Vector3 v(orientation.x,orientation.y,orientation.z);
	q.FromAngleAxis(Ogre::Radian(orientation.angle),v);
	_node->setOrientation(q);
	_node->_update(true,true);
}
コード例 #10
0
void PlayerCameraOgre::onRightButtonPressed()
{
	if (!mRightButtonPressedLastFrame)
		mMousePosLastFrame = mMouse->getPosition();

	mp::Vector2i diff = mMouse->getPosition() - mMousePosLastFrame;
	const mp::Vector3f &playerPos = mPlayer->model()->getPosition();
	Ogre::Vector3 pivotPoint(playerPos.getX(), playerPos.getY() + mPivotHeight, playerPos.getZ());
	float yaw = (float)diff.getX() * CAMERA_SPEED;
	float pitch = (float)-diff.getY() * CAMERA_SPEED;

	Ogre::Quaternion yawQuat;
	yawQuat.FromAngleAxis(Ogre::Radian(yaw), Ogre::Vector3::UNIT_Y);
	Ogre::Matrix3 yawMat;
	yawQuat.ToRotationMatrix(yawMat);

	Ogre::Vector3 pivotToPos = Ogre::Vector3(mRealPosition.getX(), mRealPosition.getY(), mRealPosition.getZ()) - pivotPoint;
	Ogre::Matrix4 pos(1, 0, 0, pivotToPos.x,
		0, 1, 0, pivotToPos.y,
		0, 0, 1, pivotToPos.z,
		0, 0, 0, 1);

	Ogre::Vector3 xz(pivotToPos.x, 0, pivotToPos.z);
	Ogre::Vector3 norm(-xz.z, 0, xz.x);
	Ogre::Quaternion pitchQuat;
	pitchQuat.FromAngleAxis(Ogre::Radian(pitch), norm);
	Ogre::Matrix3 pitchMat;
	pitchQuat.ToRotationMatrix(pitchMat);

	Ogre::Matrix4 toPivot(1, 0, 0, pivotPoint.x,
		0, 1, 0, pivotPoint.y,
		0, 0, 1, pivotPoint.z,
		0, 0, 0, 1);

	Ogre::Matrix4 newPosMat = pos * pitchMat * yawMat * toPivot;
	newPosMat = newPosMat.inverse();
	Ogre::Vector3 newPos = newPosMat.getTrans();
	mRealPosition.set(-newPos.x, -newPos.y, -newPos.z);
	setPosition(mRealPosition);
	lookAt(pivotPoint.x, pivotPoint.y, pivotPoint.z);

	adjustDistance();

	mMousePosLastFrame = mMouse->getPosition();
	mRightButtonPressedLastFrame = true;
}
コード例 #11
0
//-----------------------------------------------------------------------------------------
void CCameraEditor::roll(const Ogre::Radian &value)
{
    Ogre::Quaternion q;
    Ogre::Vector3 axis = mOrientation->get() * Ogre::Vector3::UNIT_Z;
    q.FromAngleAxis(value, axis);
    q.normalise();
    
    mOrientation->set(q * mOrientation->get());
}
コード例 #12
0
//-----------------------------------------------------------------------------------------
void CCameraEditor::yaw(const Ogre::Radian &value)
{
    Ogre::Quaternion q;

    q.FromAngleAxis(value, Ogre::Vector3::UNIT_Y);
    q.normalise();
    
    mOrientation->set(q * mOrientation->get());
}
コード例 #13
0
void OgrePointSpecification::setGlobalRotation(const VEHA::RotationVector& orientation)
{
	Ogre::Quaternion q;
	Ogre::Vector3 v(orientation.x,orientation.y,orientation.z);
	q.FromAngleAxis(Ogre::Radian(orientation.angle),v);
	if(getParent())
		q=shared_dynamic_cast<OgrePointSpecification>(_parent)->_node->convertWorldToLocalOrientation(q);
	_node->setOrientation(q);
	_node->_update(true,true);
}
コード例 #14
0
ファイル: World.cpp プロジェクト: EvilWar/prj-reboot
void fix_gta_coord(Ogre::Quaternion& quat)
{
    swap(quat.y, quat.z);
    Ogre::Radian angle;
    Ogre::Vector3 axis;
    quat.ToAngleAxis(angle, axis);
    //swap(axis.y, axis.z);
    axis = Ogre::Quaternion(Ogre::Degree(-90), Ogre::Vector3::UNIT_X) * axis;
    quat.FromAngleAxis(angle, axis);
}
コード例 #15
0
ファイル: TestScene12.cpp プロジェクト: soulmerge/PURGE
		bool frameEnded(const Ogre::FrameEvent &evt)
		{
			Ogre::Quaternion q;
			q.FromAngleAxis(Ogre::Degree(360 * ((float) timer.getMilliseconds()) / 5000), Ogre::Vector3(0, 1, 0));
			for (auto node = nodes.begin(); node != nodes.end(); node++)
			{
				(*node)->setOrientation(q);
			}
			return true;
		}
コード例 #16
0
Ogre::Quaternion DotSceneLoader::parseQuaternion(rapidxml::xml_node<>* XMLNode)
{
	//! @todo Fix this crap!

	Ogre::Quaternion orientation;

	if (XMLNode->first_attribute("qx"))
	{
		orientation.x = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qx")->value());
		orientation.y = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qy")->value());
		orientation.z = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qz")->value());
		orientation.w = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qw")->value());
	}
	if (XMLNode->first_attribute("qw"))
	{
		orientation.w = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qw")->value());
		orientation.x = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qx")->value());
		orientation.y = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qy")->value());
		orientation.z = Ogre::StringConverter::parseReal(XMLNode->first_attribute("qz")->value());
	}
	else if (XMLNode->first_attribute("axisX"))
	{
		Ogre::Vector3 axis;
		axis.x = Ogre::StringConverter::parseReal(XMLNode->first_attribute("axisX")->value());
		axis.y = Ogre::StringConverter::parseReal(XMLNode->first_attribute("axisY")->value());
		axis.z = Ogre::StringConverter::parseReal(XMLNode->first_attribute("axisZ")->value());
		Ogre::Real angle = Ogre::StringConverter::parseReal(XMLNode->first_attribute("angle")->value());;
		orientation.FromAngleAxis(Ogre::Angle(angle), axis);
	}
	else if (XMLNode->first_attribute("angleX"))
	{
		Ogre::Vector3 axis;
		axis.x = Ogre::StringConverter::parseReal(XMLNode->first_attribute("angleX")->value());
		axis.y = Ogre::StringConverter::parseReal(XMLNode->first_attribute("angleY")->value());
		axis.z = Ogre::StringConverter::parseReal(XMLNode->first_attribute("angleZ")->value());
		//orientation.FromAxes(&axis);
		//orientation.F
	}
	else if (XMLNode->first_attribute("x"))
	{
		orientation.x = Ogre::StringConverter::parseReal(XMLNode->first_attribute("x")->value());
		orientation.y = Ogre::StringConverter::parseReal(XMLNode->first_attribute("y")->value());
		orientation.z = Ogre::StringConverter::parseReal(XMLNode->first_attribute("z")->value());
		orientation.w = Ogre::StringConverter::parseReal(XMLNode->first_attribute("w")->value());
	}
	else if (XMLNode->first_attribute("w"))
	{
		orientation.w = Ogre::StringConverter::parseReal(XMLNode->first_attribute("w")->value());
		orientation.x = Ogre::StringConverter::parseReal(XMLNode->first_attribute("x")->value());
		orientation.y = Ogre::StringConverter::parseReal(XMLNode->first_attribute("y")->value());
		orientation.z = Ogre::StringConverter::parseReal(XMLNode->first_attribute("z")->value());
	}

	return orientation;
}
コード例 #17
0
ファイル: SceneEntity.cpp プロジェクト: dtbinh/AncelApp
bool  SceneEntity::applyOperation(int operation)
{
	if(operation == 0)
	{
		mSceneNode->setScale(mScale.x,mScale.y,mScale.z);
	}
	if(operation == 1)
	{
		Ogre::Quaternion ori;
		ori.FromAngleAxis(Ogre::Radian(Ogre::Math::PI/180*mRotateAngel),Ogre::Vector3(0,1,0));
		mSceneNode->setOrientation(ori);
	}
	return true;
}
コード例 #18
0
Ogre::Quaternion XMLHelper::fillQuaternionFromElement(TiXmlElement* elem) {
	Ogre::Vector3 vector = fillVector3FromElement(elem);
	Ogre::Degree degrees;
	//first check if degrees is specified, but also allow for radians to be specified
	if (elem->Attribute("degrees")) {
		degrees = std::stof(elem->Attribute("degrees"));
	} else if (elem->Attribute("radians")) {
		degrees = Ogre::Radian(std::stof(elem->Attribute("radians")));
	}
	Ogre::Quaternion q;
	q.FromAngleAxis(degrees, vector);
	return q;

}
コード例 #19
0
    //-----------------------------------------------------------------------
    void TerrainCircleLineList::build( TerrainManager* terrainMgr , Vec3 center, Flt radius, Flt gap )
    {
        Flt     girth           = 2 * 3.14 * radius;
        UInt    sectorCount     = girth / gap;
        UInt    maxSectorCount  = 100;
        if ( sectorCount > maxSectorCount )
            sectorCount = maxSectorCount;
        if ( sectorCount < 6 )
            sectorCount = 6;

        Vector3 dir         = Vector3( 0, 0, radius );
        Flt onceRadianValue = 2 * 3.14 / sectorCount;
        Radian onceRadian   = Radian( onceRadianValue );

        //////////////////////////////////////////////////////

        Ogre::Quaternion baseQua;

        Flt delta       = MGTimeOp::getCurrTick() - mLastBuildTime;
        mLastBuildTime  = MGTimeOp::getCurrTick();
        Flt speed       = 0.003;
        mBaseRadian += delta * speed * onceRadianValue;
        if ( mBaseRadian > 2 * 3.14 )
            mBaseRadian = 0;

        baseQua.FromAngleAxis( Radian(mBaseRadian), Vector3::UNIT_Y);
        dir = baseQua * dir;

        //////////////////////////////////////////////////////

        Quaternion q;
        q.FromAngleAxis( onceRadian, Vector3::UNIT_Y);

        //////////////////////////////////////////////////////
        mCircleLine.clear();
        Vec3 pos;
        for ( UInt i=0; i<sectorCount; i++ )
        {
            pos = center + Vec3(dir.x,dir.y,dir.z);

            //////////////////////////////////////////////////////////////////
            
            terrainMgr->getStickHeight( Vec2(pos.x, pos.z), pos.y );
            
            //////////////////////////////////////////////////////////////////
            mCircleLine.push_back( pos );
            dir = q * dir;
        }
    }
コード例 #20
0
ファイル: ogrewidget.cpp プロジェクト: wpfhtl/octocopter
void OgreWidget::placeObjectOnTerrain(const QString meshName, const Ogre::Vector3 position, const float rotationY, const Ogre::Vector3 scale)
{
    Ogre::Quaternion rotation;
    QString name(meshName);
    name.replace(".mesh", "");

    Ogre::Entity* entity = mSceneManager->createEntity(name.toStdString(), meshName.toStdString());
    entity->setQueryFlags(0xFFFFFFFF);
    rotation.FromAngleAxis(Ogre::Degree(rotationY), Ogre::Vector3::UNIT_Y);
    Ogre::SceneNode* sceneNode = mSceneManager->getRootSceneNode()->createChildSceneNode(
                position + Ogre::Vector3(0, mTerrainGroup->getHeightAtWorldPosition(position) + mTerrainPos.y - 0.2, 0),
                rotation);
    sceneNode->setScale(scale);
    sceneNode->attachObject(entity);
    addMeshInformation(entity, sceneNode);
}
コード例 #21
0
ファイル: Entity.cpp プロジェクト: DeejStar/q-gears
void
Entity::SetRotation( const Ogre::Degree& rotation )
{
    assert( m_model_root_node );
    float angle = rotation.valueDegrees() - Ogre::Math::Floor( rotation.valueDegrees() / 360.0f ) * 360.0f;

    if( angle < 0 )
    {
        angle = 360 + angle;
    }

    Ogre::Quaternion q;
    Ogre::Vector3 vec = Ogre::Vector3::UNIT_Z;
    q.FromAngleAxis( Ogre::Radian( Ogre::Degree( angle ) ), vec );
    m_model_root_node->setOrientation( q );
    m_DirectionNode->setOrientation( q );
}
コード例 #22
0
//----------------------------------------------------------------------------
OgitorsPropertyValue parseQuaternion(TiXmlElement *XMLNode)
{
    OgitorsPropertyValue value;
    Ogre::Quaternion orientation;
    
    value.propType = PROP_QUATERNION;

    if(XMLNode->Attribute("qx"))
    {
        orientation.x = Ogre::StringConverter::parseReal(XMLNode->Attribute("qx"));
        orientation.y = Ogre::StringConverter::parseReal(XMLNode->Attribute("qy"));
        orientation.z = Ogre::StringConverter::parseReal(XMLNode->Attribute("qz"));
        orientation.w = Ogre::StringConverter::parseReal(XMLNode->Attribute("qw"));
    }
    else if(XMLNode->Attribute("axisX"))
    {
        Ogre::Vector3 axis;
        axis.x = Ogre::StringConverter::parseReal(XMLNode->Attribute("axisX"));
        axis.y = Ogre::StringConverter::parseReal(XMLNode->Attribute("axisY"));
        axis.z = Ogre::StringConverter::parseReal(XMLNode->Attribute("axisZ"));
        Ogre::Real angle = Ogre::StringConverter::parseReal(XMLNode->Attribute("angle"));;
        orientation.FromAngleAxis(Ogre::Angle(angle), axis);
    }
    else if(XMLNode->Attribute("angleX"))
    {
        Ogre::Vector3 axis;
        axis.x = Ogre::StringConverter::parseReal(XMLNode->Attribute("angleX"));
        axis.y = Ogre::StringConverter::parseReal(XMLNode->Attribute("angleY"));
        axis.z = Ogre::StringConverter::parseReal(XMLNode->Attribute("angleZ"));
        
        Ogre::Quaternion q1(Ogre::Radian(axis.x),Ogre::Vector3(1,0,0));
        Ogre::Quaternion q2(Ogre::Radian(axis.y),Ogre::Vector3(0,1,0));
        Ogre::Quaternion q3(Ogre::Radian(axis.z),Ogre::Vector3(0,0,1));
        orientation = q1 * q2 * q3;
    }

    value.val = Ogre::Any(orientation);
    
    return value;
}
コード例 #23
0
void DefaultDrone::show(){
	Parent::show();

	float f = timeAlive();
	Coordinator::Transform base;
	if (mTransformCoordinator){
		base = mTransformCoordinator->getValue(timeAlive());
	}else{
		base.mPos = Ogre::Vector3::ZERO;
		base.mRot = Ogre::Quaternion::IDENTITY;
		base.mScl = Ogre::Vector3::UNIT_SCALE;
	}
	getNode()->setPosition(base.mPos);
	getNode()->setOrientation(base.mRot);

	Ogre::TransformKeyFrame key(NULL, 0);
	key = dynamic_cast<DefaultDroneDBE*>(mDbe)->getKeyFrame(f);
	Ogre::Vector3 v = key.getTranslate();
	v=v*base.mScl;

	getNode()->translate(v);

	Ogre::Radian angle;
	Ogre::Vector3 axis;

	Ogre::Quaternion r = key.getRotation();

	if ( base.mScl.x == -1){
		r.ToAngleAxis(angle, axis);
		axis.x *= -1;
		angle = (Ogre::Radian)0-angle;
		r.FromAngleAxis(angle, axis);
	}
	mSceneNode->rotate(r);

	/*Ogre::Node* n = getNode();
	n->setPosition(mDelta+mTransformCoordinator->getValue(timeAlive()).mPos);*/
}
コード例 #24
0
void ObjcetControl::addObject( QString name,QString groupName,QString entityType,Ogre::SceneNode* objcetNode,Ogre::Entity* objectEntity,const QMap<QString, QString>& attrMap)
{
	EntityTreeItem* groupItem=mObjectModel->getRootItem()->findItem(groupName);//得到组节点
	if (groupItem!=NULL)
	{
		//这里传入的是实体的名称,由于场景可能有多个来自于同一个实体的对象,所以名字要特殊处理
		QVector<EntityTreeItem*> result;
		QVector<EntityTreeItem*>::Iterator it;
		QString objectName = name.indexOf('_') == -1 ? name : name.split('_').at(0);
		mObjectModel->getRootItem()->findItemAsSimpleName(objectName,&result);//先从列表中查找具有相同部分的项
		
		if (result.size()!=0)
		{
			int max=0;
			QStringList sl;
			for (it=result.begin();it!=result.end();it++)//遍历结果,查找后缀最大的值
			{
				sl=(*it)->data(0)->name.split("_");
				int value=sl.at(1).toInt();
				if (value>max)
				{
					max=value;
				}
				sl.clear();
			}
			objectName+=QString("_")+QString().setNum(max+1);
		}
		else
		{
			objectName+="_0";//如果没的话,从0开始计数
		}
			
		ObjectData* objectData=new ObjectData(objectName);
		objectData->mNode=objcetNode;
		objectData->mEntity=objectEntity;
		objectData->EntityType = entityType;
		objectData->GroupName = groupName;
		if (groupName.startsWith(QString::fromStdString("势力")) && attrMap.isEmpty())
		{
			objectData->map["direction"] = "1";
			objectData->map["numunit"] = "0";
			objectData->map["morale"] = "0";
		}
		if (groupName.startsWith(QString::fromStdString("势力")) && !attrMap.isEmpty())
		{
			objectData->map["direction"] = attrMap.value("direction");
			objectData->map["numunit"] = attrMap.value("numunit");
			objectData->map["morale"] = attrMap.value("morale");
		}

		int GX,GY;
		IIRoot::getSingletonPtr()->mTerrain->calculateGrid(objcetNode->getPosition().x,objcetNode->getPosition().z,&GX,&GY);
		objectData->GridX=GX;
		objectData->GridY=GY;

		QString value=attrMap.value("ObjectDirection");
		Ogre::Quaternion q;

		if(value=="North")
		{
			q.FromAngleAxis(Ogre::Degree(180),Ogre::Vector3(0,1,0));
		}
		else if(value=="South")
		{
			q.FromAngleAxis(Ogre::Degree(360),Ogre::Vector3(0,1,0));
		}
		else if(value=="West")
		{
			q.FromAngleAxis(Ogre::Degree(270),Ogre::Vector3(0,1,0));
		}
		else if(value=="East")
		{
			q.FromAngleAxis(Ogre::Degree(90),Ogre::Vector3(0,1,0));
		}

		objectData->mNode->setOrientation(q);

		objectData->map["ObjectDirection"]=attrMap.value("ObjectDirection");

		groupItem->appendChild(new EntityTreeItem(objectData,groupItem,EntityItemType::Entity));
		mTreeView->reset();//改变数据后,记得通知view刷新
		mTreeView->expand(mObjectModel->index(groupItem->row(),0));//展开对应的组
	}
}
コード例 #25
0
void ObjcetControl::attributeChangle( QString name,QString value )
{
	if (mSelectObject!=NULL)
	{
		Ogre::Vector3 p=mSelectObject->mNode->getPosition();
		Ogre::Vector3 s=mSelectObject->mNode->getScale();
		Ogre::Quaternion q=mSelectObject->mNode->getOrientation();
		if (name=="X")
		{






			p.x=value.toFloat();
			mSelectObject->mNode->setPosition(p);

		}
		else if (name=="Y")
		{




			p.y=value.toFloat();
			mSelectObject->mNode->setPosition(p);

		}
		else if (name=="Z")
		{




			p.z=value.toFloat();
			mSelectObject->mNode->setPosition(p);

		}
		else if (name=="OffsetX")
		{
			Ogre::Vector2 gridPosition=IIRoot::getSingletonPtr()->mTerrain->getRealXY(mSelectObject->GridX,mSelectObject->GridY,SecGrid); 

			p.x=gridPosition.x+value.toFloat();
			mSelectObject->mNode->setPosition(p);
		}
		else if (name=="OffsetY")
		{
			float height=IIRoot::getSingletonPtr()->mTerrain->getHeight(mSelectObject->GridX,mSelectObject->GridY);

			p.y=height+value.toFloat();
			mSelectObject->mNode->setPosition(p);
		}
		else if (name=="OffsetZ")
		{
			Ogre::Vector2 gridPosition=IIRoot::getSingletonPtr()->mTerrain->getRealXY(mSelectObject->GridX,mSelectObject->GridY,SecGrid); 

			p.z=gridPosition.y+value.toFloat();
			mSelectObject->mNode->setPosition(p);
		}
		else if (name=="GridX")
		{
			Ogre::Vector2 v1=IIRoot::getSingletonPtr()->mTerrain->getRealXY(value.toInt(),mSelectObject->GridY,SecGrid); 
			float height=IIRoot::getSingletonPtr()->mTerrain->getHeight(value.toInt(),mSelectObject->GridY);
			mSelectObject->mNode->setPosition(Ogre::Vector3(v1.x,height,v1.y));
		}
		else if (name=="GridY")
		{
			Ogre::Vector2 v1=IIRoot::getSingletonPtr()->mTerrain->getRealXY(mSelectObject->GridX,value.toInt(),SecGrid); 
			float height=IIRoot::getSingletonPtr()->mTerrain->getHeight(mSelectObject->GridX,value.toInt());
			mSelectObject->mNode->setPosition(Ogre::Vector3(v1.x,height,v1.y));
		}
		//else if (name=="Roll")
		//{
		//	q.FromAngleAxis(Ogre::Radian(value.toFloat()))  ;
		//	mSelectObject->mNode->setPosition(p);
		//}
		//else if (name=="Pitch")
		//{
		//	p.z=value.toFloat();
		//	mSelectObject->mNode->setPosition(p);
		//}
		//else if (name=="Yaw")
		//{
		//	p.z=value.toFloat();
		//	mSelectObject->mNode->setPosition(p);
		//}
		else if (name=="ScaleX")
		{
			s.x=value.toFloat();
			mSelectObject->mNode->setScale(s);
		}
		else if (name=="ScaleY")
		{
			s.y=value.toFloat();
			mSelectObject->mNode->setScale(s);
		}
		else if (name=="ScaleZ")
		{
			s.z=value.toFloat();
			mSelectObject->mNode->setScale(s);
		}
		else if (name == "Type")
		{
			mSelectObject->EntityType = value;
		}
		else if (name == "Direction")
		{
			mSelectObject->map["direction"] = value;
		}
		else if (name == "NumUnit")
		{
			mSelectObject->map["numunit"] = value;
		}
		else if (name == "Morale")
		{
			mSelectObject->map["morale"] = value;
		}
		else if (name == "ObjectDirection")
		{
			mSelectObject->map["ObjectDirection"] = value;
			Ogre::Quaternion q;

			if(value=="North")
			{
				q.FromAngleAxis(Ogre::Degree(180),Ogre::Vector3(0,1,0));
			}
			else if(value=="South")
			{
				q.FromAngleAxis(Ogre::Degree(360),Ogre::Vector3(0,1,0));
			}
			else if(value=="West")
			{
				q.FromAngleAxis(Ogre::Degree(270),Ogre::Vector3(0,1,0));
			}
			else if(value=="East")
			{
				q.FromAngleAxis(Ogre::Degree(90),Ogre::Vector3(0,1,0));
			}

			mSelectObject->mNode->setOrientation(q);
		}
	}
}
Ogre::ManualObject * CCone::CreateCone(Ogre::Real Intensity)
{
	Ogre::ManualObject *Cone = NULL;
	Ogre::SceneManager *SceneManager = Ogre::Root::getSingleton().getSceneManager("DynamicEffects");
	Cone = SceneManager->createManualObject("Cone");
	Cone->setDynamic(false);
    Cone->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);

	Ogre::Real deltaAngle = (Ogre::Math::TWO_PI / m_BaseSegments);
	Ogre::Real deltaHeight = m_Height/(Ogre::Real)m_HeightSegments;
	
	Ogre::Vector3 Normal = Ogre::Vector3(m_Radius, m_Height, 0.f).normalisedCopy();
	Ogre::Quaternion Quaternion;
	
	int Offset = 0;

	for (int HeightSegmentIndex = 0; HeightSegmentIndex <= m_HeightSegments; HeightSegmentIndex++)
	{
		Ogre::Real Radius = m_Radius * (1 - HeightSegmentIndex / (Ogre::Real)m_HeightSegments);
		
		for (int BaseSegmentIndex = 0; BaseSegmentIndex <= m_BaseSegments; BaseSegmentIndex++)
		{
			Ogre::Real x = Radius* cosf(BaseSegmentIndex * deltaAngle);
			Ogre::Real z = Radius * sinf(BaseSegmentIndex * deltaAngle);
			Cone->position(x, HeightSegmentIndex * deltaHeight, z);
			
			Cone->colour(Intensity, Intensity, 0.0, 1.0);
			Quaternion.FromAngleAxis(Ogre::Radian(-BaseSegmentIndex*deltaAngle), Ogre::Vector3::NEGATIVE_UNIT_Y);
			Cone->normal(Quaternion * Normal);
			Cone->textureCoord(BaseSegmentIndex / (Ogre::Real)m_BaseSegments, HeightSegmentIndex / (Ogre::Real)m_HeightSegments);

			if (HeightSegmentIndex != m_HeightSegments && BaseSegmentIndex != m_BaseSegments)
			{
				Cone->index(Offset + m_BaseSegments + 2);
				Cone->index(Offset);
				Cone->index(Offset + m_BaseSegments + 1);
				Cone->index(Offset + m_BaseSegments + 2);
				Cone->index(Offset + 1);
				Cone->index(Offset);
			}

			Offset++;
		}
	}

	int centerIndex = Offset;
	
	Cone->position(0,0,0);
	Cone->normal(Ogre::Vector3::NEGATIVE_UNIT_Y);
	Cone->textureCoord(0.0,1);
	Offset++;
	
	for (int BaseSegmentIndex=0; BaseSegmentIndex <= m_BaseSegments; BaseSegmentIndex++)
	{
		Ogre::Real x = m_Radius * cosf(BaseSegmentIndex*deltaAngle);
		Ogre::Real z = m_Radius * sinf(BaseSegmentIndex*deltaAngle);

		Cone->position(x, 0.0f, z);
		Cone->colour(Intensity, Intensity, 0.0, 0.0);
		Cone->normal(Ogre::Vector3::NEGATIVE_UNIT_Y);
		Cone->textureCoord(BaseSegmentIndex/(Ogre::Real)m_BaseSegments,0.0);
		if (BaseSegmentIndex != m_BaseSegments)
		{
			Cone->index(centerIndex);
			Cone->index(Offset);
			Cone->index(Offset+1);
		}
		Offset++;
	}

	Cone->end();

	return Cone;
}
コード例 #27
0
ファイル: oculus_display.cpp プロジェクト: rahulraw/adVentuRe
void OculusDisplay::updateCamera()
{
  if (!oculus_ || !oculus_->isOculusReady())
  {
    return;
  }

  Ogre::Vector3 pos;
  Ogre::Quaternion ori;

  if ( follow_cam_property_->getBool() )
  {
    const Ogre::Camera *cam = context_->getViewManager()->getCurrent()->getCamera();
    pos = cam->getDerivedPosition();
    ori = cam->getDerivedOrientation();
  }
  else
  {
    context_->getFrameManager()->getTransform( tf_frame_property_->getStdString(), ros::Time(), pos, ori );

    Ogre::Quaternion r;
    r.FromAngleAxis( Ogre::Radian(M_PI*0.5), Ogre::Vector3::UNIT_X );
    ori = ori * r;
    r.FromAngleAxis( Ogre::Radian(-M_PI*0.5), Ogre::Vector3::UNIT_Y );
    ori = ori * r;
  }

  pos += offset_property_->getVector();
  scene_node_->setPosition( pos ); //  -> position of oculus_nav

  if ( horizontal_property_->getBool() )
  {
    Ogre::Vector3 x_axis = ori * Ogre::Vector3(1,0,0);
    float yaw = atan2( x_axis.y, x_axis.x );// - M_PI*0.5;

    // we're working in OpenGL coordinates now
    ori.FromAngleAxis( Ogre::Radian(yaw), Ogre::Vector3::UNIT_Z );

    Ogre::Quaternion r;
    r.FromAngleAxis( Ogre::Radian(M_PI*0.5), Ogre::Vector3::UNIT_X );
    ori = ori * r;
  }

  scene_node_->setOrientation( ori );

  Ogre::ColourValue bg_color = context_->getViewManager()->getRenderPanel()->getViewport()->getBackgroundColour();

  for ( int i =0; i<2; i++ )
  {
    oculus_->getViewport(i)->setBackgroundColour( bg_color );
    oculus_->getCamera(i)->setNearClipDistance( near_clip_property_->getFloat() );

    // this is a hack to circumvent a bug in Ogre 1.8
    // otherwise one of the viewports will not update it's background color
    bg_color.g += 0.0001;
  }

  oculus_->updateProjectionMatrices();
  oculus_->update();

  if ( pub_tf_property_->getBool() )
  {
    tf::StampedTransform pose;
    pose.frame_id_ = context_->getFixedFrame().toStdString();
    pose.child_frame_id_ = pub_tf_frame_property_->getStdString();
    pose.stamp_ = ros::Time::now();

    Ogre::Vector3 test_pos;
    Ogre::Quaternion test_ori;

    const Ogre::Camera *caml = oculus_->getCamera(0); // left eye position
    const Ogre::Camera *camr = oculus_->getCamera(1); // right eye position

    test_pos = (caml->getDerivedPosition() + camr->getDerivedPosition()) / 2; // eye position average
    test_ori = caml->getDerivedOrientation(); 

    Ogre::Quaternion r;
    r.FromAngleAxis( Ogre::Radian(M_PI*0.5), Ogre::Vector3::UNIT_Y );
    test_ori = test_ori * r;
    r.FromAngleAxis( Ogre::Radian(-M_PI*0.5), Ogre::Vector3::UNIT_X );
    test_ori = test_ori * r;   
    
    pose.setRotation( tf::Quaternion( test_ori.x, test_ori.y, test_ori.z, test_ori.w ) );
    pose.setOrigin( tf::Vector3( test_pos.x, test_pos.y, test_pos.z ) );
    
    tf_pub_.sendTransform( pose );
    
  }
}
コード例 #28
0
void ObjectEditHandler::Roaming(CPoint Point, Ogre::TerrainGroup::RayResult rayResult, float Elapsed)
{
	if(mMode == OEM_NONE)
		return;

	if(mFreeTransform)
	{
		Ogre::Vector3 newPosition;
		if(!(GetKeyState(VK_LCONTROL) & 0x8000))
		{
			newPosition = Ogre::Vector3(rayResult.position.x, mTarget->getSceneNode()->getPosition().y, rayResult.position.z);
			if(mOwner->isPaste())
				newPosition.y = rayResult.position.y;
			mTarget->getSceneNode()->setPosition(newPosition);
			PropertyWnd::current->firePropertyChanged();
		}
		mObjectEditNode->setPosition(newPosition);
	} else

	if(GetKeyState(VK_LBUTTON) & 0x8000)
	{
		if(Point == mLastPoint)
			return;

		CPoint Move = Point - mLastPoint;
		mLastPoint = Point;

		if(mMode == OEM_TRANS)
		{
			Ogre::Vector3 vCamXAxis, vCamYAxis, vCamZAxis;
			mOwner->getCamera()->getDerivedOrientation().ToAxes(vCamXAxis, vCamYAxis, vCamZAxis);
			Ogre::Vector3 vTrans(0,0,0);
			switch(mAxisMode)
			{
			case AM_TRANS_SCALE_X:
				{
					float xyPlane = (vCamZAxis.y < 0 ? -1 : 1);
					float yAxis = (vCamXAxis.z < 0 ? 1 : -1);
					vTrans.x = Move.x * vCamXAxis.x + Move.y * (1 - vCamXAxis.x) * xyPlane * yAxis;
				}
				break;

			case AM_TRANS_SCALE_Y:
				{
					vTrans.y = -Move.y * (vCamYAxis.y > 0 ? 1 : -1);
				}
				break;

			case AM_TRANS_SCALE_Z:
				{
					float yAxis = (vCamZAxis.z < 0 ? -1 : 1);
					vTrans.z = Move.x * vCamXAxis.z + Move.y * (1.0f - vCamXAxis.z) * yAxis;
				}
				break;

			case AM_TRANS_SCALE_ALL:
				{
					float xyPlane = (vCamZAxis.y < 0 ? -1 : 1);
					float yAxis = (vCamXAxis.z < 0 ? 1 : -1);
					vTrans.x = Move.x * vCamXAxis.x + Move.y * (1 - vCamXAxis.x) * xyPlane * yAxis;
					vTrans.z = Move.x * vCamXAxis.z + Move.y * (1.0f - vCamXAxis.z) * (vCamZAxis.z < 0 ? -1 : 1);
					vTrans.y = -Move.y * (vCamYAxis.y > 0 ? 1 : -1);
				}
			}
			if(!(GetKeyState(VK_LCONTROL) & 0x8000))
			{
				mTarget->getSceneNode()->translate(vTrans);
				PropertyWnd::current->firePropertyChanged();
			}
			mObjectEditNode->translate(vTrans);
		} else 
			
		if(mMode == OEM_SCALE)
		{
			Ogre::Vector3 vScaleInc(0, 0, 0);
			if(mAxisMode == AM_TRANS_SCALE_ALL)
			{
				vScaleInc.x = Move.x * 0.01f;
				vScaleInc.y = vScaleInc.x;
				vScaleInc.z = vScaleInc.x;
			}
			else
			{
				Ogre::Vector3 vNodeXAxis, vNodeYAxis, vNodeZAxis;
				mObjectEditNode->getOrientation().ToAxes(vNodeXAxis, vNodeYAxis, vNodeZAxis);
				const Ogre::Matrix4 &ViewMatrix = mOwner->getCamera()->getViewMatrix();
				switch(mAxisMode)
				{
				case AM_TRANS_SCALE_X:
					{
						vNodeXAxis = ViewMatrix * vNodeXAxis;
						vScaleInc.x = (Move.x * vNodeXAxis.x - Move.y * vNodeXAxis.y) * 0.001f;
					}
					break;

				case AM_TRANS_SCALE_Y:
					{
						vNodeYAxis = ViewMatrix * vNodeYAxis;
						vScaleInc.y = (Move.x * vNodeYAxis.x - Move.y * vNodeYAxis.y) * 0.001f;
					}
					break;

				case AM_TRANS_SCALE_Z:
					{					
						vNodeZAxis = ViewMatrix * vNodeZAxis;
						vScaleInc.z = (Move.x * vNodeZAxis.x - Move.y * vNodeZAxis.y) * 0.001f;
					}
				}
				mTarget->getSceneNode()->setScale(
					mTarget->getSceneNode()->getScale() + vScaleInc);
				PropertyWnd::current->firePropertyChanged();
			}
		} else

		if(mMode == OEM_ROTATE)
		{
			Ogre::Quaternion qRotate;
			switch(mAxisMode)
			{
			case AM_ROTATE_X:
				qRotate.FromAngleAxis(Ogre::Radian(Move.y * 0.01f), mRotateNode->getOrientation().xAxis());
				break;
			case AM_ROTATE_Y:
				qRotate.FromAngleAxis(Ogre::Radian(Move.x * 0.01f), mRotateNode->getOrientation().yAxis());
				break;
			case AM_ROTATE_Z:
				qRotate.FromAngleAxis(Ogre::Radian(-Move.y * 0.01f), mRotateNode->getOrientation().zAxis());
				break;
			}
			if (!(GetKeyState(VK_LCONTROL) & 0x8000))
			{
				mTarget->getSceneNode()->rotate(qRotate, Ogre::Node::TS_PARENT);
				PropertyWnd::current->firePropertyChanged();
			}
			mRotateNode->rotate(qRotate, Ogre::Node::TS_PARENT);
		}
	}
	else
	{
		mIndicatorContext->collide();
		OgreOpcode::CollisionPair **CollisionPair = NULL;
		float Distance = 
			mOwner->getCamera()->getFarClipDistance();
		if(Distance < 0.1f) // 近似比较float与0
			Distance = Ogre::Math::POS_INFINITY;

		Ogre::Ray pickRay = mOwner->getCamera()->getCameraToViewportRay(float(Point.x) / mOwner->getActiveView()->getWidth(), 
			float(Point.y) / mOwner->getActiveView()->getHeight());

		if(mIndicatorContext->rayCheck(pickRay, Distance,
			OgreOpcode::COLLTYPE_EXACT,
			OgreOpcode::COLLTYPE_ALWAYS_EXACT,
			CollisionPair))
		{
			OgreOpcode::CollisionObject *CollisionObject = 
				CollisionPair[0]->this_object;
			KAxisMode AxisMode = mCollisionObjectToAxisMode[CollisionObject];

			if(mAxisMode == AM_NONE)
			{
				mAxisMode = mCollisionObjectToAxisMode[CollisionObject];
				mTransformEntities[mAxisMode]->setMaterial(mMaterials[4]);
				return;
			} else 
			
			if(mAxisMode == AxisMode)
				return;
		}
		switch(mAxisMode) // 恢复指示器材质
		{
		case AM_NONE:
			return;
		case AM_TRANS_SCALE_X:
		case AM_ROTATE_X:
			mTransformEntities[mAxisMode]->setMaterial(mMaterials[0]);
			break;
		case AM_TRANS_SCALE_Y:
		case AM_ROTATE_Y:
			mTransformEntities[mAxisMode]->setMaterial(mMaterials[1]);
			break;
		case AM_TRANS_SCALE_Z:
		case AM_ROTATE_Z:
			mTransformEntities[mAxisMode]->setMaterial(mMaterials[2]);
			break;
		case AM_TRANS_SCALE_ALL:
			mTransformEntities[mAxisMode]->setMaterial(mMaterials[3]);
			break;
		}
		mAxisMode = AM_NONE;
	}
}
コード例 #29
0
ファイル: VoodooEntityView.cpp プロジェクト: LiMuBei/ovise
void VoodooEntityView::OnEntityAttributeChanged(
        Entity*                  Rhs,
        const std::string&       Name,
        const EntityVariantType* Attribute
        )
{
	if ( Name == "Position" )
	{
		// Set the position, if it is available
		const vec3* Data = boost::get<vec3>( Attribute );

		if ( Data )
			mNode->setPosition( *Data );
	}
	else if( Name == "Scale" )
	{
		// Set the scale, if it is available
		const vec3* Data = boost::get<vec3>( Attribute );

		if( Data )
			mNode->setScale( *Data );
	}
	else if ( Name == "Model" )
	{
		// Delete all old bone names
		if ( mOgreEntity )
		{
			typedef Ogre::SkeletonInstance::BoneIterator iterator;
			Ogre::SkeletonInstance* Skeleton=
			        mOgreEntity->getSkeleton();
			for ( iterator i=Skeleton->getBoneIterator();
			      i.hasMoreElements();
			      )
			{
				Ogre::Bone* Bone=i.getNext();
				GetDataEntity()->RemoveAttribute( Bone->getName());
			}

			mNode->detachObject( mOgreEntity );
			GetSceneManager()->destroyEntity( mOgreEntity );
			mOgreEntity=0;
		}



		const std::string* Data=boost::get<std::string>( Attribute );

		if (!Data)
			return;

		// Create and attach the model entity
		const std::string EntityName = "Entity:" +
		                               boost::lexical_cast<std::string>(
		        GetDataEntity() );
		mOgreEntity = GetSceneManager()->createEntity( EntityName,
			*Data );
		mNode->attachObject( mOgreEntity );

		// Get all bones as properties
		typedef Ogre::SkeletonInstance::BoneIterator iterator;
		Ogre::SkeletonInstance* Skeleton=mOgreEntity->getSkeleton();
		Skeleton->setBindingPose();
		for ( iterator i=Skeleton->getBoneIterator(); i.hasMoreElements(); )
		{
			Ogre::Bone* Bone=i.getNext();
			Bone->setManuallyControlled( true );
			const std::string Name=Bone->getName();

			const quat Val = Bone->getOrientation();

			// if this attribute has already a attribute, do not overwrite it and inform observers (to  get visualize the orientation here)
			if ( GetDataEntity()->GetAttribute( Name ) == 0 )
			{
				GetDataEntity()->Set<quat>( Name, Val );
			}
			else
			{
				GetDataEntity()->Changed( Name,
					GetDataEntity()->GetAttribute( Name ));
			}
		}
	}
	else if (Rhs->GetAttribute( "Model" ) != 0)
	{
		const Entity::AttributeType& Attributes=Rhs->GetAttributes();
		typedef Entity::AttributeType::value_type ValueType;

		// Check if this is an angle value and a bone of this name exists
		Ogre::SkeletonInstance* Skeleton=mOgreEntity->getSkeleton();
		const quat*             Val = boost::get<quat>( Attribute );

		if ( Val && Skeleton->hasBone( Name ) )
		{
			Ogre::Bone* Bone=Skeleton->getBone( Name );

			Ogre::Quaternion CorrectorX;
			CorrectorX.FromAngleAxis( Ogre::Radian( Ogre::Degree( -
						90 ) ), vec3( 1.f, 0.f, 0.f ) );
			Ogre::Quaternion CorrectorZ;
			CorrectorZ.FromAngleAxis( Ogre::Radian( Ogre::Degree(
						90 ) ), vec3( 0.f, 0.f, 1.f ) );

			Ogre::Quaternion Corrector = CorrectorX * CorrectorZ;

			Bone->setOrientation(
				Bone->getInitialOrientation() * Corrector *
				( *Val ) *
				Corrector.UnitInverse() );

			// FIXME: is this really needed?
			mOgreEntity->getAllAnimationStates()->_notifyDirty();
		}
	}
}
コード例 #30
0
ファイル: Pong.cpp プロジェクト: Artea/ducttape-engine
void Main::updateStateFrame(double simulation_frame_time) {
    mBallSpeed *= 1.0 + (simulation_frame_time * 0.05);

    // move paddle 1
    float move1 = 0;
    if(dt::InputManager::get()->getKeyboard()->isKeyDown(OIS::KC_W)) {
        move1 += 1;
    }
    if(dt::InputManager::get()->getKeyboard()->isKeyDown(OIS::KC_S)) {
        move1 -= 1;
    }
    float new_y1 = mPaddle1Node->getPosition().y + move1 * simulation_frame_time * 8;
    if(new_y1 > FIELD_HEIGHT / 2 - PADDLE_SIZE / 2)
        new_y1 = FIELD_HEIGHT / 2 - PADDLE_SIZE / 2;
    else if(new_y1 < - FIELD_HEIGHT / 2  + PADDLE_SIZE / 2)
        new_y1 = - FIELD_HEIGHT / 2  + PADDLE_SIZE / 2;

    mPaddle1Node->setPosition(Ogre::Vector3(
                mPaddle1Node->getPosition().x,
                new_y1,
                mPaddle1Node->getPosition().z));

    // move paddle 2
    float move2 = 0;
    if(dt::InputManager::get()->getKeyboard()->isKeyDown(OIS::KC_UP)) {
        move2 += 1;
    }

    if(dt::InputManager::get()->getKeyboard()->isKeyDown(OIS::KC_DOWN)) {
        move2 -= 1;
    }

    float new_y2 = mPaddle2Node->getPosition().y + move2 * simulation_frame_time * 8;
    if(new_y2 > FIELD_HEIGHT / 2 - PADDLE_SIZE / 2)
        new_y2 = FIELD_HEIGHT / 2 - PADDLE_SIZE / 2;
    else if(new_y2 < - FIELD_HEIGHT / 2  + PADDLE_SIZE / 2)
        new_y2 = - FIELD_HEIGHT / 2  + PADDLE_SIZE / 2;

    mPaddle2Node->setPosition(Ogre::Vector3(
                mPaddle2Node->getPosition().x,
                new_y2,
                mPaddle2Node->getPosition().z));

    // move ball
    Ogre::Vector3 newpos(mBallNode->getPosition() + mBallSpeed * simulation_frame_time);
    if(newpos.y >= FIELD_HEIGHT / 2 - 0.5 || newpos.y <= -FIELD_HEIGHT / 2 + 0.5) {
        mBallSpeed.y *= -1;
    }

    if(newpos.x >= FIELD_WIDTH / 2 - 0.5) {
        float paddle_y = mPaddle2Node->getPosition().y;
        if(newpos.y < paddle_y - PADDLE_SIZE / 2 - 0.5 || newpos.y > paddle_y + PADDLE_SIZE / 2 + 0.5) {
            dt::Logger::get().info("Player lost!");
            ++mScore1;
            resetBall();
        } else {
            mBallSpeed.x *= -1;
        }
    } else if(newpos.x <= -FIELD_WIDTH / 2 + 0.5) {
        float paddle_y = mPaddle1Node->getPosition().y;
        if(newpos.y < paddle_y - PADDLE_SIZE / 2 - 0.5 || newpos.y > paddle_y + PADDLE_SIZE / 2 + 0.5) {
            dt::Logger::get().info("Computer lost!");
            ++mScore2;
            resetBall();
        } else {
            mBallSpeed.x *= -1;
        }
    }

    mBallNode->setPosition(mBallNode->getPosition() + mBallSpeed * simulation_frame_time);

    Ogre::Quaternion q;
    q.FromAngleAxis(Ogre::Radian(Ogre::Math::Cos(Ogre::Radian(dt::Root::getInstance().getTimeSinceInitialize() * 0.2))) * 0.1, Ogre::Vector3::UNIT_X);
    Ogre::Quaternion w;
    w.FromAngleAxis(Ogre::Radian(Ogre::Math::Sin(Ogre::Radian(dt::Root::getInstance().getTimeSinceInitialize() * 0.2))) * 0.1, Ogre::Vector3::UNIT_Y);
    mGameNode->setRotation(q * w);
}