Example #1
0
NavLights::NavLights(SceneGraph::Model *model, float period)
: m_time(0.f)
, m_period(period)
, m_enabled(false)
{
	PROFILE_SCOPED();
	assert(g_initted);

	Graphics::Renderer *renderer = model->GetRenderer();

	using SceneGraph::Node;
	using SceneGraph::MatrixTransform;
	using SceneGraph::Billboard;

	//This will find all matrix transforms meant for navlights.
	SceneGraph::FindNodeVisitor lightFinder(SceneGraph::FindNodeVisitor::MATCH_NAME_STARTSWITH, "navlight_");
	model->GetRoot()->Accept(lightFinder);
	const std::vector<Node*> &results = lightFinder.GetResults();

	//attach light billboards
	for (unsigned int i=0; i < results.size(); i++) {
		MatrixTransform *mt = dynamic_cast<MatrixTransform*>(results.at(i));
		assert(mt);
		Billboard *bblight = new Billboard(model, renderer, BILLBOARD_SIZE);
		Uint32 group = 0;
		Uint8 mask  = 0xff; //always on
		Uint8 color = NAVLIGHT_BLUE;

		if (mt->GetName().substr(9, 3) == "red") {
			mask  = 0x0f;
			color = NAVLIGHT_RED;
		} else if (mt->GetName().substr(9, 5) == "green") {
			mask  = 0xf0;
			color = NAVLIGHT_GREEN;
		} else if (mt->GetName().substr(9, 3) == "pad") {
			//group by pad number
			// due to this problem: http://stackoverflow.com/questions/15825254/why-is-scanfhhu-char-overwriting-other-variables-when-they-are-local
			// where MSVC is still using a C89 compiler the format identifer %hhu is not recognised. Therefore I've switched to Uint32 for group.
			PiVerify(1 == sscanf(mt->GetName().c_str(), "navlight_pad%u", &group));
			mask  = 0xf0;
		}
		bblight->SetColorUVoffset(get_color(color));

		GroupLightsVecIter glit = std::find_if(m_groupLights.begin(), m_groupLights.end(), GroupMatch(group));
		if(glit == m_groupLights.end()) {
			// didn't find group, create a new one
			m_groupLights.push_back(TGroupLights(group));
			// now use it
			glit = (m_groupLights.end() - 1);
		}

		assert(glit != m_groupLights.end());
		glit->m_lights.push_back(LightBulb(group, mask, color, bblight));
		mt->SetNodeMask(SceneGraph::NODE_TRANSPARENT);
		mt->AddChild(bblight);
	}
}
Example #2
0
BillboardSprite::BillboardSprite(SceneNode* node, BillboardSet* bs, int row, int col, int unitWidth, int unitHeight)
	: mNode(node), mBillboards(bs), mRow(row), mCol(col), mUnitWidth(unitWidth), mUnitHeight(unitHeight),
	mIsFinished(false)
{
	mWidth = row * unitWidth;
	mHeight = col * unitHeight;
	Billboard* b = mBillboards->getBillboard(0);
	if (b)
		b->setTexcoordRect(0, 0, 1 / (float)mRow, 1 / (float)mCol);
}
bool addBillboard(AddBillboard::Request &req, AddBillboard::Response &res)
{
  ROS_INFO("ADDING BILLBOARD");

  InteractiveMarker tmp;
  if ((imServer->get(req.name, tmp)) || (primitives.count(req.name) != 0))
  {
    ROS_ERROR("Object with that name already exists! Please remove it first.");
    return false;
  }

  Billboard *billboard = new Billboard(imServer, req.frame_id, req.name);
  billboard->setType(req.type);
  billboard->setPoseType(req.pose_type);
  billboard->setPose(req.pose);
  billboard->setScale(req.scale);
  billboard->setDescription(req.description);
  billboard->setDirection(req.direction);
  billboard->setVelocity(req.velocity);
  billboard->insert();
  imServer->applyChanges();

  primitives.insert(make_pair(req.name, billboard));

  ROS_INFO("..... DONE");
  return true;
}
Example #4
0
void Monster::harmCheck(float timeSinceLastFrame)
{
	
	/// 先检查地形,更新怪物信息
	checkCellType();
	checkMonsterIsChange();
	
	mCheckMethod->bulletHarmCheck(mMonsterState->getBulletState(), mBulletHarmValue, mBulletHarmTime, mBlood, mSpeedPre, mSpeedCurrent, mSpeedTemp, timeSinceLastFrame);
	mCheckMethod->terrainHarmCheck(mMonsterState->getTerrainState(), mTerrainHarmvalue, mBlood, mSpeedPre, mSpeedCurrent, mSpeedTemp, timeSinceLastFrame);
	/// 状态恢复
	stateRecover();
	
	/// 判断是否死亡
	//mIsDead = mCheckMethod->checkIsDead(mBlood);
	if (!mIsDead && mCheckMethod->checkIsDead(mBlood))
	{
		mIsDead = true;
		Stage::playSound("../Media/Sound/dead.wav", false);
	}
	/// 根据地形改地图
	changeMazeByTerrain(mMonsterState->getTerrainState());
	/// 改变头顶血量显示
	Billboard* health = mHealthHUD->getBillboard(0);
	float healthPer = mBlood / mMaxBlood;
	float healthLength = healthPer * mHealthHUD->getDefaultWidth();
	health->setDimensions(healthLength, mHealthHUD->getDefaultHeight());
	ColourValue maxHealthCol = ColourValue(0, 0.8f, 0);
	ColourValue minHealthCol = ColourValue(1, 0, 0);
	ColourValue currHealthCol = maxHealthCol * healthPer + minHealthCol * (1 - healthPer);
	health->setColour(currHealthCol);

	// 设置是否显示着火和冰冻
	if (!mFrozenPs)
		mFrozenPs = (ParticleSystem*)mNode->getAttachedObject(mNode->getName() + "frozen");
	if (!mBurnPs)
		mBurnPs = (ParticleSystem*)mNode->getAttachedObject(mNode->getName() + "burn");
	if (mMonsterState->getBulletState() == "ice")
	{
		mBurnPs->setVisible(false);
		mFrozenPs->setVisible(true);
	}
	else if (mMonsterState->getBulletState() == "fire")
	{
		mBurnPs->setVisible(true);
		mFrozenPs->setVisible(false);
	}
	else
	{
		mBurnPs->setVisible(false);
		mFrozenPs->setVisible(false);
	}
}
Example #5
0
void BillboardBase::execSyncV(      FieldContainer    &oFrom,
                                        ConstFieldMaskArg  whichField,
                                        AspectOffsetStore &oOffsets,
                                        ConstFieldMaskArg  syncMode,
                                  const UInt32             uiSyncInfo)
{
    Billboard *pThis = static_cast<Billboard *>(this);

    pThis->execSync(static_cast<Billboard *>(&oFrom),
                    whichField,
                    oOffsets,
                    syncMode,
                    uiSyncInfo);
}
Example #6
0
void Billboard_Test::Init(Scene * scene)
{
	BillboardPtr ptr = scene->AddBillboard();
	Billboard * b = ptr.Get();
	b->SetSize(20.0f, 20.0f);
	b->UseDiffuseTexture(true);
	b->SetDiffuseTexture("assets/fire.png");

	StaticVert verts[4];

	verts[0].pos = Vector3(-1.0f, -1.0f, 0.0f);
	verts[1].pos = Vector3(-1.0f, 1.0f, 0.0f);
	verts[2].pos = Vector3(1.0f, 1.0f, 0.0f);
	verts[3].pos = Vector3(1.0f, -1.0f, 0.0f);

	verts[0].u = 0.0f;
	verts[0].v = 1.0f;

	verts[1].u = 0.0f;
	verts[1].v = 0.0f;

	verts[2].u = 1.0f;
	verts[2].v = 0.0f;

	verts[3].u = 1.0f;
	verts[3].v = 1.0f;
	unsigned int ind[] = { 0, 1, 3, 1, 3, 2 };

	ModelCreator<StaticVert> creator;
	creator.StartMesh();
	creator.SetTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	creator.SetDrawMethod(DM_DRAW_INDEXED);
	creator.SetVertexBuffer(verts, sizeof(verts), sizeof(StaticVert));
	creator.SetIndexBuffer(ind, 6);
	creator.EndMesh();

	StaticEntityPtr triPtr = scene->AddStaticEntity(creator, "tri");
	StaticEntity * tri = triPtr.Get();
	tri->Illuminate(false);
	tri->SetPosition(50.0f, 0.0f, 0.0f);
	tri->SetScale(20.0f, 20.0f, 2.0f);

	Material * mat = tri->GetMaterial(0);
	mat->UseDiffuseMap(true);
	mat->SetDiffuseMap("assets/fire.png");
	mat->SetEmmisivePower(1);
}
Example #7
0
NavLights::NavLights(SceneGraph::Model *model, float period)
: m_time(0.f)
, m_period(period)
, m_enabled(false)
{
	assert(g_initted);

	Graphics::Renderer *renderer = model->GetRenderer();

	using SceneGraph::Node;
	using SceneGraph::MatrixTransform;
	using SceneGraph::Billboard;

	//This will find all matrix transforms meant for navlights.
	SceneGraph::FindNodeVisitor lightFinder(SceneGraph::FindNodeVisitor::MATCH_NAME_STARTSWITH, "navlight_");
	model->GetRoot()->Accept(lightFinder);
	const std::vector<Node*> &results = lightFinder.GetResults();

	//attach light billboards
	for (unsigned int i=0; i < results.size(); i++) {
		MatrixTransform *mt = dynamic_cast<MatrixTransform*>(results.at(i));
		assert(mt);
		Billboard *bblight = new Billboard(renderer, matBlue, vector3f(0.f), BILLBOARD_SIZE);
		Uint8 group = 0;
		Uint8 mask  = 0xff; //always on
		Uint8 color = NAVLIGHT_BLUE;

		if (mt->GetName().substr(9, 3) == "red") {
			bblight->SetMaterial(matRed);
			mask  = 0x0f;
			color = NAVLIGHT_RED;
		} else if (mt->GetName().substr(9, 5) == "green") {
			mask  = 0xf0;
			color = NAVLIGHT_GREEN;
		} else if (mt->GetName().substr(9, 3) == "pad") {
			//group by pad number
			group = atoi(mt->GetName().substr(12, 1).c_str());
			mask  = 0xf0;
		}
		bblight->SetMaterial(get_material(color));

		m_lights.push_back(LightBulb(group, mask, color, bblight));
		mt->SetNodeMask(SceneGraph::NODE_TRANSPARENT);
		mt->AddChild(bblight);
	}
}
void BillboardSetComponent::createBillboard(const PonykartParsers::BillboardBlock* const block)
{
	Billboard* bb = billboardSet->createBillboard(block->getVectorProperty("Position")); // make our billboard
	// set its color if it has one, and a rotation
	auto quatIt=block->getQuatTokens().find("colour");
	if (quatIt != block->getQuatTokens().end())
		bb->setColour(toColourValue(quatIt->second));
	bb->setRotation(Degree(block->getFloatProperty("Rotation", 0)));

	auto rectQIt = block->getQuatTokens().find("texturecoords");
	if (rectQIt != block->getQuatTokens().end())
		bb->setTexcoordRect(rectQIt->second.x, rectQIt->second.y, rectQIt->second.z, rectQIt->second.w);

	// It's best to not do this unless we really need to since it makes it less efficient
	auto fTokens = block->getFloatTokens();
	auto heightIt=fTokens.find("height"), widthIt=fTokens.find("width");
	if (heightIt!=fTokens.end() && widthIt!=fTokens.end())
		bb->setDimensions(widthIt->second, heightIt->second);
}
Example #9
0
void DemoState::Draw()
{

	Game::iterator it = Game::iterator("Camera");
	if (!it.seekName("DemoCam"))
	{
		assert(0);
	}
	GameObject* GO = it;
	((Camera*)GO)->Use();
	Game::instance()->DrawObjects();
	timer += DisplayManager::instance()->getDtSecs();
	if (timer < 0)
	{
		glDisable(GL_DEPTH_TEST);
		glDepthMask(GL_FALSE);
		glMatrixMode(GL_PROJECTION);
		GLfloat f[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
		glGetFloatv(GL_PROJECTION_MATRIX,f);
		glLoadIdentity();
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();

		Splash->UseThisTexture();
		Billboard b;
		b.Draw();
		Splash->UseNoTexture();
		glEnable(GL_DEPTH_TEST);
		glDepthMask(GL_TRUE);
		glMatrixMode(GL_PROJECTION);
		glLoadMatrixf(f);

	}
	if (timer > 1)
	{
		timer = -1;
	}



}
Example #10
0
OSG_USING_NAMESPACE

Action::ResultE ShadingCallbacks::billboardRenderEnter(CNodePtr &pNode, 
                                                       Action   *action)
{
    ShadingAction *pAct = dynamic_cast<ShadingAction *>(action         );
    Billboard     *pBB  = dynamic_cast<Billboard     *>(pNode.getCPtr());

    Matrix mMat;

//    cerr << "BB::render" << std::endl;

    pBB->calcMatrix(pAct, pAct->top_matrix(), mMat);

    pAct->push_matrix(mMat);

// !!! can't use visibles, as ToWorld gives garbage leading to wrong culling
//    pAct->selectVisibles();

    return Action::Continue;
}
Example #11
0
bool FuelCell::Load(File*)
{
  Vec3f p = GetPos();
  float s = 5.0f; // TODO CONFIG

  m_aabb.Set(p.x - s, p.x + s, p.y - s, p.y + s, p.z - s, p.z + s); 
  FuelNode* sm = new FuelNode;
  sm->SetAABB(m_aabb);

  SetSceneNode(sm);

  Billboard* bb = new Billboard;
  Texture* tex = (Texture*)TheResourceManager::Instance()->GetRes("flare.png");
  bb->SetTexture(tex);
  bb->SetSize(30.0f); // TODO CONFIG
  bb->SetAABB(m_aabb);

  sm->AddChild(bb);

  return true;
}
Example #12
0
void EntityEx::Create( const String& entityName, const String& meshName, const String& mtlName )
{
	mpSceneMgr = GetEditor()->GetSceneManager();
	// create main model
	msEntityName = entityName;
	mpSceneNode = mpSceneMgr->getRootSceneNode()->createChildSceneNode();
	mpEntity = mpSceneMgr->createEntity( msEntityName, meshName );
	mpEntity->setUserAny( Ogre::Any(this) );
	mbVisible = false;

	mpTipNode = static_cast<SceneNode*>(mpSceneNode->createChild());
	msBillboardName = entityName + "bbinfo";
	mpTipBoard = mpSceneMgr->createBillboardSet(msBillboardName);
	Billboard* pTip = mpTipBoard->createBillboard(Vector3(0, 50, 0));
	pTip->setDimensions( 20.0f, 20.0f );

	if ( mtlName != "NULL" )
	{
		mpEntity->setMaterialName(mtlName);
		mpTipBoard->setMaterialName(mtlName);
	}
}
void IntersectVisitor::apply(Billboard& node)
{
    if (!enterNode(node)) return;

    // IntersectVisitor doesn't have getEyeLocal(), can we use NodeVisitor::getEyePoint()?
    const Vec3& eye_local = getEyePoint();

    for(unsigned int i = 0; i < node.getNumDrawables(); i++ )
    {
        const Vec3& pos = node.getPosition(i);
        osg::ref_ptr<RefMatrix> billboard_matrix = new RefMatrix;
        node.computeMatrix(*billboard_matrix,eye_local,pos);

        pushMatrix(billboard_matrix.get(), osg::Transform::RELATIVE_RF);

        intersect(*node.getDrawable(i));

        popMatrix();

    }

    leaveNode();
}
//----------------------------------------------------------------------------
bool BillboardController::Update (double applicationTime)
{
	// module update
	if (!EffectableController::Update(applicationTime))
		return false;

	Billboard *billboard = DynamicCast<Billboard>(mObject);
	float elapsedTime = GetElapsedTime();

	if (IsPlaying())
	{
		if (!mBillboardObject)
		{
			mBillboardObject = new0 EffectObject();

			EffectableController::OnNewAEffectObject(mBillboardObject);
		}

		ModulesUpdateEffectObject(mBillboardObject);
		mBillboardObject->Update(billboard, elapsedTime);
	}
	else if (billboard->IsDoAlphaDisAfterStop())
	{
		if (mBillboardObject)
		{
			float curAlpha = mBillboardObject->Alpha;
			float speed = billboard->GetDoAlphaDisAfterStopSpeed();
			if (curAlpha > 0.0f)
			{
				curAlpha -= speed*elapsedTime;
				if (curAlpha < 0.0f)
					curAlpha = 0.0f;
				mBillboardObject->Alpha = curAlpha;
			}
		}
	}
	
	if (billboard->IsDynamic())
	{
		billboard->GenBuffers();
	}
	else 
	{
		if (!billboard->IsBufferEverGenerated())
		{
			billboard->GenBuffers();
		}
	}

	return true;
}
Example #15
0
void Projectile::onTimeStep() {
	Object::onTimeStep();

	Billboard* billboard = billboards_->getBillboard(0);
	billboard->setRotation(billboard->getRotation() + Radian(0.2f));

	time_ += 0.1f;

	float width = billboard->getOwnWidth();
	float height = billboard->getOwnWidth();

	if (hit_) {
		if (target_) node_->setPosition(target_->getPosition());
		width = min(2.0f, width + 0.2f); // Grow the projectile
		height = min(2.0f, height + 0.2f);
	} else {
		width = 0.2f * sinf(time_) + 1.0f; // Make the projectile oscillate in size
		height = 0.2f * sinf(time_) + 1.0f;
	}

	billboard->setDimensions(width, height);
}
Example #16
0
void ScreenMVCullVisitor::apply(Billboard& node)
{
    bool status = _cullingStatus;
    bool firstStatus = _firstCullStatus;
    if(isCulled(node))
    {
        _firstCullStatus = firstStatus;
        _cullingStatus = status;
        return;
    }

    // push the node's state.
    StateSet* node_state = node.getStateSet();
    if(node_state)
        pushStateSet(node_state);

    // traverse any call callbacks and traverse any children.
    handle_cull_callbacks_and_traverse(node);

    const Vec3& eye_local = getEyeLocal();
    const RefMatrix& modelview = *getModelViewMatrix();

    for(unsigned int i = 0; i < node.getNumDrawables(); ++i)
    {
        const Vec3& pos = node.getPosition(i);

        Drawable* drawable = node.getDrawable(i);
        // need to modify isCulled to handle the billboard offset.
        // if (isCulled(drawable->getBound())) continue;

        if(drawable->getCullCallback())
        {
            if(drawable->getCullCallback()->cull(this,drawable,&_renderInfo)
                    == true)
                continue;
        }

        RefMatrix* billboard_matrix = createOrReuseMatrix(modelview);

        node.computeMatrix(*billboard_matrix,eye_local,pos);

        if(_computeNearFar && drawable->getBound().valid())
            updateCalculatedNearFar(*billboard_matrix,*drawable,true);
        float depth = distance(pos,modelview);
        /*
         if (_computeNearFar)
         {
         if (d<_computed_znear)
         {
         if (d<0.0) OSG_NOTIFY(osg::WARN)<<"Alerting billboard handling ="<<d<< std::endl;
         _computed_znear = d;
         }
         if (d>_computed_zfar) _computed_zfar = d;
         }
         */
        StateSet* stateset = drawable->getStateSet();
        if(stateset)
            pushStateSet(stateset);

        if(osg::isNaN(depth))
        {
            /*OSG_NOTIFY(osg::NOTICE)<<"CullVisitor::apply(Billboard&) detected NaN,"<<std::endl
             <<"    depth="<<depth<<", pos=("<<pos<<"),"<<std::endl
             <<"    *billboard_matrix="<<*billboard_matrix<<std::endl;
             OSG_NOTIFY(osg::DEBUG_INFO) << "    NodePath:" << std::endl;
             for (NodePath::const_iterator i = getNodePath().begin(); i != getNodePath().end(); ++i)
             {
             OSG_NOTIFY(osg::DEBUG_INFO) << "        \"" << (*i)->getName() << "\"" << std::endl;
             }*/
        }
        else
        {
            addDrawableAndDepth(drawable,billboard_matrix,depth);
        }

        if(stateset)
            popStateSet();

    }

    // pop the node's state off the geostate stack.    
    if(node_state)
        popStateSet();

    _firstCullStatus = firstStatus;
    _cullingStatus = status;
}
Example #17
0
void Render()
{
	md3dDevice->ClearRenderTargetView(mRenderTargetView, mClearColor);
	md3dDevice->ClearDepthStencilView(mDepthStencilView, D3D10_CLEAR_DEPTH|D3D10_CLEAR_STENCIL, 1.0f, 0);
	md3dDevice->OMSetDepthStencilState(0, 0);

	md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff);

	//draw Trees
	mTrees.draw(GetCamera().getPos(), GetCamera().view()*GetCamera().proj());

	D3D10_TECHNIQUE_DESC techDesc;
	fxU.setRenderUtil(techDesc);

	for(UINT p = 0; p < techDesc.Passes; ++p)
	{
		//draw Cube
		pWave->render(fxU,p);

		//draw Cube "Tower"
		for (UINT i=0; i < mTowers.size(); ++i)
		{
			fxU.setMfx(GetCamera().wvp(mTowers.at(i).getWorld()), mTowers.at(i).getWorld(), 1, nrOfTowers[i]);
			fxU.ApplyPassByIndex(p);
			mTowers.at(i).Draw();
		}

		//draw Pyramid
		fxU.setMfx(GetCamera().wvp(mPyramid.getWorld()), mPyramid.getWorld(), 2, 3);
		fxU.ApplyPassByIndex(p);
		mPyramid.Draw();

		//draw Cylinder
		fxU.setMfx(GetCamera().wvp(mCylinder.getWorld()), mCylinder.getWorld(), 3, 6);
		fxU.ApplyPassByIndex(p);
		mCylinder.Draw();

		//draw Terrain
		//fxU.setMfx(GetCamera().wvp(mTerrain.getWorld()), mTerrain.getWorld(), 0, 9);
		//fxU.ApplyPassByIndex(p);
		//mTerrain.Draw();

		fxU.setMfx(GetCamera().wvp(land.getWorld()), land.getWorld(), 0, 9);
		fxU.ApplyPassByIndex(p);
		land.draw();
	}

	//draw gui
	gui.Render();

	//draw grid
	qtc.draw(GetCamera().view(), GetCamera().proj(), grid);

	//draw Sky
	sky.draw(GetCamera().view(), GetCamera().proj(), GetCamera().getPos(), mLight.lightType);

	//draw Fire
	fire.draw(GetCamera().view(), GetCamera().proj());
	
	md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff);
	
	//draw Rain
	rain.draw(GetCamera().view(), GetCamera().proj());
	
	mSwapChain->Present(0, 0);
}
LabelDecoration::LabelDecoration(BaseEntity* _source, Vector3f _screen_position, float _lifetime)
{
	source_ = _source;
	assert(source_ != NULL);
	source_->AddSubscriber(this);
	source_location_ = source_->GetGlobalPosition();
	lifetime_ = _lifetime;
	full_lifetime_ = _lifetime;
	fill_.SetFillColor(GLColor(255, 255, 255));

	Section_ptr section = (Section_ptr)_source;
	Vector3f screen_position = _screen_position;
	Vector3f icon_spacing(25, 0, 0);
	if(screen_position.x > Camera::Instance().GetWidth() * 0.1f)
		icon_spacing.x *= -1;
	bool interesting = false;

	std::vector<std::string> tags = GetRelevantTags((Section*)_source);

	for(std::vector<std::string>::iterator it = tags.begin(); it != tags.end(); ++it)
	{
		if(!it->compare("Weapon"))
		{
			Billboard* bb = new Billboard("WeaponIcon", BillboardType::ScreenSpace);
			bb->SetPosition(screen_position);
			labels_.push_back(bb);
			screen_position += icon_spacing;
			interesting = true;
		}
		if(!it->compare("Beam"))
		{
			Billboard* bb = new Billboard("BeamIcon", BillboardType::ScreenSpace);
			bb->SetPosition(screen_position);
			labels_.push_back(bb);
			screen_position += icon_spacing;
			interesting = true;
		}
		if(!it->compare("Shield"))
		{
			Billboard* bb = new Billboard("ShieldIcon", BillboardType::ScreenSpace);
			bb->SetPosition(screen_position);
			labels_.push_back(bb);
			screen_position += icon_spacing;
			interesting = true;
		}
		if(!it->compare("Generator"))
		{
			Billboard* bb = new Billboard("GeneratorIcon", BillboardType::ScreenSpace);
			bb->SetPosition(screen_position);
			labels_.push_back(bb);
			screen_position += icon_spacing;
			interesting = true;
		}
		if(!it->compare("EnergyStorage"))
		{
			Billboard* bb = new Billboard("EnergyStorageIcon", BillboardType::ScreenSpace);
			bb->SetPosition(screen_position);
			labels_.push_back(bb);
			screen_position += icon_spacing;
			interesting = true;
		}
		if(!it->compare("Thruster"))
		{
			Billboard* bb = new Billboard("ThrusterIcon", BillboardType::ScreenSpace);
			bb->SetPosition(screen_position);
			labels_.push_back(bb);
			screen_position += icon_spacing;
			interesting = true;
		}
		if(!it->compare("Core"))
		{
			Billboard* bb = new Billboard("CoreIcon", BillboardType::ScreenSpace);
			bb->SetPosition(screen_position);
			labels_.push_back(bb);
			screen_position += icon_spacing;
			interesting = true;
		}
		if(!it->compare("Joint"))
		{
			Billboard* bb = new Billboard("JointIcon", BillboardType::ScreenSpace);
			bb->SetPosition(screen_position);
			labels_.push_back(bb);
			screen_position += icon_spacing;
			interesting = true;
		}
	}
	if(!interesting)
		lifetime_ = -1;

	screen_position_ = screen_position;
}
Example #19
0
void Display()
{
    DrawShadowMap();
    /* Clear window; color specified in 'Initialize()' */
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glUseProgram(ShaderProgram);
    /* Associate program with shader matrices */
    GLint projectionUniform = glGetUniformLocation(ShaderProgram, "ProjectionMatrix");
    if (projectionUniform == -1)
    {
        cerr << "Could not bind uniform ProjectionMatrix" << endl;
        exit(-1);
    }
    glUniformMatrix4fv(projectionUniform, 1, GL_TRUE, ProjectionMatrix.matrix);

    GLint ViewUniform = glGetUniformLocation(ShaderProgram, "ViewMatrix");
    if (ViewUniform == -1)
    {
        cerr << "Could not bind uniform ViewMatrix" << endl;
        exit(-1);
    }
    glUniformMatrix4fv(ViewUniform, 1, GL_FALSE, glm::value_ptr(camera.viewMatrix()));

	/* light */
	GLint LightPos1Uniform = glGetUniformLocation(ShaderProgram, "lightPos1");
	if (LightPos1Uniform == -1){
		cerr << "Could not bind uniform lightPos1" << endl;
		exit(-1);
	}
	glUniform3fv(LightPos1Uniform, 1, glm::value_ptr(camera.viewMatrix() * glm::vec4(lights[0]->pos, 1.0)));
	
	GLint LightColor1Uniform = glGetUniformLocation(ShaderProgram, "lightColor1");
	if (LightColor1Uniform == -1){
		cerr << "Could not bind uniform lightColor1" << endl;
		exit(-1);
	}
	glUniform3fv(LightColor1Uniform, 1, glm::value_ptr(lights[0]->rgb));

	/* green moving light */
	GLint LightPos2Uniform = glGetUniformLocation(ShaderProgram, "lightPos2");
	if (LightPos2Uniform == -1){
		cerr << "Could not bind uniform lightPos2" << endl;
		exit(-1);
	}
	glUniform3fv(LightPos2Uniform, 1, glm::value_ptr(camera.viewMatrix() * glm::transpose(glm::make_mat4(ModelMatrix[6].matrix)) * glm::vec4(lights[1]->pos, 1)));
	GLint LightColor2Uniform = glGetUniformLocation(ShaderProgram, "lightColor2");
	if (LightColor2Uniform == -1){
		cerr << "Could not bind uniform lightColor2" << endl;
		exit(-1);
	}
	glUniform3fv(LightColor2Uniform, 1, glm::value_ptr(lights[1]->rgb));

    GLint kA = glGetUniformLocation(ShaderProgram, "kA");
    GLint kD = glGetUniformLocation(ShaderProgram, "kD");
    GLint kS = glGetUniformLocation(ShaderProgram, "kS");
    if (kA == -1 || kD == -1 || kS == -1)
    {
        cout << kA << kD << kS << endl;
        cerr << "Could not bind uniform light constants" << endl;
        exit(-1);
    }

    const glm::mat4 scale_bias_matrix =
            glm::mat4(glm::vec4(0.5f, 0.0f, 0.0f, 0.0f),
                      glm::vec4(0.0f, 0.5f, 0.0f, 0.0f),
                      glm::vec4(0.0f, 0.0f, 0.5f, 0.0f),
                      glm::vec4(0.5f, 0.5f, 0.5f, 1.0f));
    glUseProgram(ShaderProgram);
    glUniformMatrix4fv(glGetUniformLocation(ShaderProgram, "ShadowMatrix"), 1, GL_FALSE,
                       glm::value_ptr(scale_bias_matrix * light_projection_matrix * light_view_matrix));

    /* Get texture uniform handle from fragment shader */
    GLuint ShadowUniform  = glGetUniformLocation(ShaderProgram, "depth_texture");

    /* Get texture uniform handle from fragment shader */
    GLuint TextureUniform  = glGetUniformLocation(ShaderProgram, "myTextureSampler");

    glUniform1i(TextureUniform, 0);
    glUniform1i(ShadowUniform, 1);

    glActiveTexture(GL_TEXTURE1);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, depth_texture);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, crackles->TextureID);



    glEnableVertexAttribArray(vPosition);
    glEnableVertexAttribArray(vColor);
    glEnableVertexAttribArray(vNormal);
    glEnableVertexAttribArray(vUV);

    for (int i = 0; i < 7; i++) {

        glUniform1f(kA, objects[i]->kA * ky);
        glUniform1f(kD, objects[i]->kD * kx);
        glUniform1f(kS, objects[i]->kS * kc);


        glBindBuffer(GL_ARRAY_BUFFER, VBO[i]);
        glVertexAttribPointer(vPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);

        glBindBuffer(GL_ARRAY_BUFFER, CBO[i]);
        glVertexAttribPointer(vColor, 3, GL_FLOAT, GL_FALSE, 0, 0);

        glBindBuffer(GL_ARRAY_BUFFER, TCBO[i]);
        glVertexAttribPointer(vUV, 2, GL_FLOAT, GL_FALSE, 0, 0);

        glBindBuffer(GL_ARRAY_BUFFER, NBO[i]);
        glVertexAttribPointer(vNormal, 3, GL_FLOAT, GL_FALSE, 0, 0);

        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO[i]);

        GLint size;
        glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
        GLint RotationUniform = glGetUniformLocation(ShaderProgram, "ModelMatrix");
        if (RotationUniform == -1) {
            cerr << "Could not bind uniform ModelMatrix" << endl;
            exit(-1);
        }
        glUniformMatrix4fv(RotationUniform, 1, GL_TRUE, ModelMatrix[i].matrix);

        glDrawElements(GL_TRIANGLES, size / sizeof(GLushort), GL_UNSIGNED_SHORT, 0);
    }

    for (int i = 0; i < 2; i++) {

        glUniform1f(kA, room_components[i]->kA * ky);
        glUniform1f(kD, room_components[i]->kD * kx);
        glUniform1f(kS, room_components[i]->kS * kc);

        glBindBuffer(GL_ARRAY_BUFFER, VBR[i]);
        glVertexAttribPointer(vPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);

        glBindBuffer(GL_ARRAY_BUFFER, CBR[i]);
        glVertexAttribPointer(vColor, 3, GL_FLOAT,GL_FALSE, 0, 0);

        glBindBuffer(GL_ARRAY_BUFFER, NBR[i]);
        glVertexAttribPointer(vNormal, 3, GL_FLOAT, GL_FALSE, 0, 0);

        glBindBuffer(GL_ARRAY_BUFFER, TCBR[i]);
        glVertexAttribPointer(vUV, 2, GL_FLOAT, GL_FALSE, 0, 0);

        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBR[i]);

        GLint size;
        glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);

        GLint RoomUniform = glGetUniformLocation(ShaderProgram, "ModelMatrix");
        if (RoomUniform == -1){
            cerr << "Could not bind uniform ModelMatrix" << endl;
            exit(-1);
        }
        glUniformMatrix4fv(RoomUniform, 1, GL_FALSE, RoomMatrix[0].matrix);

        if (room_components[i]->texture != NULL && room_components[i]->texture->TextureID > 0) {

            /* Bind current texture */
            glBindTexture(GL_TEXTURE_2D, room_components[i]->texture->TextureID);

        }

        /* Issue draw command, using indexed triangle list */
        glDrawElements(GL_TRIANGLES, size/sizeof(GLushort), GL_UNSIGNED_SHORT, 0);
    }
    /* Draw billboard */
    glUniform1f(kA, billboard.kA * ky);
    glUniform1f(kD, billboard.kD * kx);
    glUniform1f(kS, billboard.kS * kc);


    glBindBuffer(GL_ARRAY_BUFFER, VBB);
    glVertexAttribPointer(vPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);

    glBindBuffer(GL_ARRAY_BUFFER, CBB);
    glVertexAttribPointer(vColor, 3, GL_FLOAT, GL_FALSE, 0, 0);

    glBindBuffer(GL_ARRAY_BUFFER, TCBB);
    glVertexAttribPointer(vUV, 2, GL_FLOAT, GL_FALSE, 0, 0);

    glBindBuffer(GL_ARRAY_BUFFER, NBB);
    glVertexAttribPointer(vNormal, 3, GL_FLOAT, GL_FALSE, 0, 0);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBB);

    GLint size;
    glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);

    GLint RotationUniform = glGetUniformLocation(ShaderProgram, "ModelMatrix");
    if (RotationUniform == -1) {
        cerr << "Could not bind uniform ModelMatrix" << endl;
        exit(-1);
    }
    glUniformMatrix4fv(RotationUniform, 1, GL_FALSE, glm::value_ptr(billboard.getPosition()));

    glBindTexture(GL_TEXTURE_2D, billboard.texture->TextureID);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);
    glDrawElements(GL_TRIANGLES, size / sizeof(GLushort), GL_UNSIGNED_SHORT, 0);
    glDisable(GL_BLEND);


    /* Disable attributes */
    glDisableVertexAttribArray(vPosition);
    glDisableVertexAttribArray(vColor);
    glDisableVertexAttribArray(vNormal);
    glDisableVertexAttribArray(vUV);
    
    /* Swap between front and back buffer */ 
    glutSwapBuffers();
}
void drawScene()
{// covert speed to string
	string speedword = to_string(speed);

	string SpeedPhrase = "Speed: ";
	SpeedPhrase.append(speedword);
	string Direction = "Direction: ";
	Direction.append(carHeading);
	glColor3f(1, 0, 0);
	//print words
	glWindowPos2i((winWidth / 2) -125, winHeight - (sHeight*1.2));
	printString(SpeedPhrase);
	glWindowPos2i((winWidth / 2) + 75, winHeight - (sHeight*1.2));
	printString(Direction);


	// Draw terrain
	glCallList(terrainID);

	glEnable(GL_LIGHTING);
	trafficLight.setMaterials();
	
	/*vector<string> test;
	test=trafficLight.GetMaterialNames();
	for (int i = 0; i < test.size(); i++)
		cout << "name: " << test[i] << endl;*/
	// North-East (NS_Signal)
	glPushMatrix();
	glTranslatef(10, 0, -10.5);
	glScalef(1/3.28/12, 1/3.28/12, 1/3.28/12);
	trafficLight.setSignal(NS_Signal);
	trafficLight.Draw();
	glPopMatrix();
	
	
	glPushMatrix();
	glTranslatef(10, 0, -10);
	glRotatef(-45, 0, 1, 0);
	glCallList(surveillanceCameraID);
	glPopMatrix();

	// North-West (WE_Signal)
///board 1
	//glColor3f(1, 1, 0);
	glPushMatrix();
	board.Draw();
	glPopMatrix();
// board 2
	glPushMatrix();
	board2.Draw();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-10, 0, -10.5);
	glScalef(1 / 3.28 / 12, 1 / 3.28 / 12, 1 / 3.28 / 12);
	glRotatef(90, 0, 1, 0);
	trafficLight2.setSignal(WE_Signal);
	trafficLight2.Draw();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-10, 0, -10);
	glRotatef(45, 0, 1, 0);
	glCallList(surveillanceCameraID);
	glPopMatrix();
	
	// South-East (WE_Signal)
	glPushMatrix();
	glTranslatef(10, 0, 10);
	glScalef(1 / 3.28 / 12, 1 / 3.28 / 12, 1 / 3.28 / 12);
	glRotatef(-90, 0, 1, 0);
	trafficLight3.setSignal(WE_Signal);
	trafficLight3.Draw();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(10, 0, 10.5);
	glRotatef(-135, 0, 1, 0);
	glCallList(surveillanceCameraID);
	glPopMatrix();

	// South West(SN_Signal)
	glPushMatrix();
	glTranslatef(-10, 0, 10);
	glScalef(1 / 3.28 / 12, 1 / 3.28 / 12, 1 / 3.28 / 12);
	glRotatef(180, 0, 1, 0);
	trafficLight4.setSignal(NS_Signal);
	trafficLight4.Draw();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-10, 0, 10.5);
	glRotatef(135, 0, 1, 0);
	glCallList(surveillanceCameraID);
	glPopMatrix();

	// Draw the car.
	glPushMatrix();
	glTranslatef(carPosition.x, carPosition.y, carPosition.z);
	glRotatef(carDirection, 0, 1, 0);
	glCallList(carID);
	glPopMatrix();



	
}
void init()
{
	glClearColor(0.5, 0.5, 1.0, 1);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	// Note that the light is defined in the eye or camera frame.
	GLfloat light_position[] = {0.0, 0.0, 0.0, 1.0};

	GLfloat ambient[] = {0.3, 0.3, 0.3, 1};
	GLfloat diffuse[] = {1.0, 1.0, 1.0, 1};
	GLfloat specular[] = {1.0, 1.0, 1.0, 1};

	glLightfv(GL_LIGHT0, GL_POSITION, light_position);

	glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
	glLightfv(GL_LIGHT0, GL_SPECULAR, specular);

	glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
	glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);

	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_NORMALIZE);

	glEnable(GL_LIGHTING);	
	glEnable(GL_LIGHT0);

	// Generate display list for the surveillance camera.
	surveillanceCameraID = glGenLists(1);
	
	glNewList(surveillanceCameraID, GL_COMPILE);
	surveillanceCamera.Draw();
	glEndList();

	// Generate display list for the car.
	carID = glGenLists(1);
	glNewList(carID, GL_COMPILE);
	car.Draw();
	glEndList();



	board.SetLocation(boardPos);
	board.SetOrientation(boarddirection);
	board.SetSize(3, 2.5);
	board.ReadFile("Square.ppm");

	board2.SetLocation(boardPos2);
	board2.SetOrientation(boarddirection2);
	board2.SetSize(5, 3.5);
	board2.ReadFile("wendys.ppm");

	// Generate the display list for terrain, including road and grass.
	terrainID = glGenLists(1);
	glNewList(terrainID, GL_COMPILE);
	glDisable(GL_LIGHTING);

	// Grass
	glColor3f(0, 0.7, 0);
	glBegin(GL_QUADS);
		glVertex3f(-1000, 0, 1000);
		glVertex3f(-10, 0, 1000);
		glVertex3f(-10, 0, 10);
		glVertex3f(-1000, 0, 10);

		glVertex3f(10, 0, 1000);
		glVertex3f(1000, 0, 1000);
		glVertex3f(1000, 0, 10);
		glVertex3f(10, 0, 10);

		glVertex3f(10, 0, -10);
		glVertex3f(1000, 0, -10);
		glVertex3f(1000, 0, -1000);
		glVertex3f(10, 0, -1000);

		glVertex3f(-1000, 0, -10);
		glVertex3f(-10, 0, -10);
		glVertex3f(-10, 0, -1000);
		glVertex3f(-1000, 0, -1000);
	glEnd();

	// Roads
	glBegin(GL_QUADS);
		glColor3f(0.2, 0.2, 0.2);

		glVertex3f(-10, 0, 1000);
		glVertex3f(10, 0, 1000);
		glVertex3f(10, 0, -1000);
		glVertex3f(-10, 0, -1000);

		glVertex3f(-1000, 0, 10);
		glVertex3f(1000, 0, 10);
		glVertex3f(1000, 0, -10);
		glVertex3f(-1000, 0, -10);
	glEnd();

	// Yellow line South
	glBegin(GL_POLYGON);
		glColor3f(1, 1, 0);
		glVertex3f(-0.1, 0.05, 1000);
		glVertex3f(0.1, 0.05, 1000);
		glVertex3f(0.1, 0.05, 10);
		glVertex3f(-0.1, 0.05, 10);
	glEnd();
	// Yellow line North
	glBegin(GL_POLYGON);
	glColor3f(1, 1, 0);
	glVertex3f(-0.1, 0.05, -1000);
	glVertex3f(0.1, 0.05, -1000);
	glVertex3f(0.1, 0.05, -10);
	glVertex3f(-0.1, 0.05, -10);
	glEnd();
	// Yellow line west
	glBegin(GL_POLYGON);
	glColor3f(1, 1, 0);
	glVertex3f(-1000, 0.05, -0.1);
	glVertex3f(-1000, 0.05, 0.1);
	glVertex3f(-10, 0.05, 0.1);
	glVertex3f(-10, 0.05, -0.1);
	glEnd();
	// Yellow line east
	glBegin(GL_POLYGON);
	glColor3f(1, 1, 0);
	glVertex3f(1000, 0.05, -0.1);
	glVertex3f(1000, 0.05, 0.1);
	glVertex3f(10, 0.05, 0.1);
	glVertex3f(10, 0.05, -0.1);
	glEnd();
	// white dashed line South
	for (int i = 10; i <= 1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(4.9, 0.05, i);
		glVertex3f(5.1, 0.05, i);
		glVertex3f(5.1, 0.05, i + 3);
		glVertex3f(4.9, 0.05, i + 3);
		glEnd();
		i += 13;
	}
	
	for (int i = 10; i <= 1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(-4.9, 0.05, i);
		glVertex3f(-5.1, 0.05, i);
		glVertex3f(-5.1, 0.05, i + 3);
		glVertex3f(-4.9, 0.05, i + 3);
		glEnd();
		i += 13;
	}
	// white dashed line north
	for (int i = -10; i >= -1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(-4.9, 0.05, i);
		glVertex3f(-5.1, 0.05, i);
		glVertex3f(-5.1, 0.05, i - 3);
		glVertex3f(-4.9, 0.05, i - 3);
		glEnd();
		i -= 13;
	}

	for (int i = -10; i >= -1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(4.9, 0.05, i);
		glVertex3f(5.1, 0.05, i);
		glVertex3f(5.1, 0.05, i - 3);
		glVertex3f(4.9, 0.05, i - 3);
		glEnd();
		i -= 13;
	}
	// white dashed line west
	for (int i = -10; i >= -1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(i, 0.05, 4.9);
		glVertex3f(i, 0.05, 5.1);
		glVertex3f(i - 3, 0.05, 5.1);
		glVertex3f(i - 3, 0.05, 4.9);
		glEnd();
		i -= 13;
	}

	for (int i = -10; i >= -1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(i, 0.05, -4.9);
		glVertex3f(i, 0.05, -5.1);
		glVertex3f(i - 3, 0.05,-5.1);
		glVertex3f(i - 3, 0.05, -4.9);
		glEnd();
		i -= 13;
	}
	// white dashed line east
	for (int i = 10; i <= 1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(i, 0.05, -4.9);
		glVertex3f(i, 0.05, -5.1);
		glVertex3f(i + 3, 0.05, -5.1);
		glVertex3f(i + 3, 0.05, -4.9);
		glEnd();
		i += 13;
	}
	
	for (int i = 10; i <= 1000; i)
	{
		glBegin(GL_POLYGON);
		glColor3f(1, 1, 1);
		glVertex3f(i, 0.05, 4.9);
		glVertex3f(i, 0.05, 5.1);
		glVertex3f(i + 3, 0.05, 5.1);
		glVertex3f(i + 3, 0.05, 4.9);
		glEnd();
		i += 13;
	}




	glEndList();
}
int main(int argc, char** argv)
{
  ros::init(argc, argv, "test_primitives");

  InteractiveMarkerServerPtr server;
  server.reset(new InteractiveMarkerServer("test_primitives", "", false));

  ColorRGBA c;

  c.a = 0.2;
  c.r = 1.0;
  c.g = 0.0;
  c.b = 0.0;
  Pose p;
  p.position.x = 5;
  p.position.y = 2;
  p.position.z = 1;
  p.orientation.x = M_PI_4;
  p.orientation.y = 0;
  p.orientation.z = M_PI_4;
  Vector3 s;
  s.x = 1.0;
  s.y = 1.0;
  s.z = 1.0;

  // Object
  Billboard *chairBillboard = new Billboard(server, "/world", "person");
  chairBillboard->setType(srs_interaction_primitives::BillboardType::CHAIR);
  chairBillboard->setPose(p);
  chairBillboard->setScale(s);
  chairBillboard->setFrameID("/world");
  chairBillboard->insert();
  // Bounding box
  BoundingBox * chairBoundingBox = new BoundingBox(server, "/world", chairBillboard->getName() + "_bbox");
  chairBoundingBox->setAttachedObjectName(chairBillboard->getName());
  chairBoundingBox->setPose(p);
  chairBoundingBox->setScale(s);
  chairBoundingBox->setColor(c);
  chairBoundingBox->setDescription("Person bounding box");
  chairBoundingBox->insert();

  p.position.x = 1;
  p.position.y = 2;
  p.position.z = 2;
  s.x = 1;
  s.y = 1;
  s.z = 1;
  // Object
  Billboard *milkBillboard = new Billboard(server, "/world", "milk_billboard");
  Quaternion direction;
  direction.x = 2.0;
  direction.y = 1.0;
  direction.z = 3.0;
  direction.w = 1.0;
  milkBillboard->setType(srs_interaction_primitives::BillboardType::MILK);
  milkBillboard->setPose(p);
  milkBillboard->setScale(s);
  milkBillboard->setDirection(direction);
  milkBillboard->setVelocity(3.4);
  milkBillboard->setDescription("MLEEEEKO");
  milkBillboard->insert();

  UnknownObject * unknowObject = new UnknownObject(server, "/world", "unknown_object");
  unknowObject->setFrameID("/world");
  Pose pp;
  pp.position.x = 0;
  pp.position.y = 0;
  pp.position.z = 0;
  unknowObject->setPose(pp);
  Vector3 ss;
  ss.x = 1;
  ss.y = 1;
  ss.z = 1;
  unknowObject->setScale(ss);
  unknowObject->setDescription("Uknown object");
  unknowObject->insert();

  Plane *plane = new Plane(server, "/world", "plane1");
  c.a = 1.0;
  p.position.x = 0;
  p.position.y = 0;
  p.position.z = 0;
  s.x = 5;
  s.y = 2;
  plane->setColor(c);
  plane->setFrameID("/world");
  plane->setPose(p);
  plane->setScale(s);
  plane->insert();
  c.g = 1.0;
  plane->changeColor(c);

  PlanePolygon *planePolygon = new PlanePolygon(server, "/world", "plane_polygon");
  Polygon pol;
  geometry_msgs::Point32 point;
  c.r = 1;
  c.g = 0;
  c.b = 0;
  c.a = 1.0;

  point.x = 0.99171;
  point.y = 0.93265;
  point.z = -0.16251;
  pol.points.push_back(point);
  point.x = 0.47751;
  point.y = -0.93946;
  point.z = -0.64291;
  pol.points.push_back(point);
  point.x = -1.28507;
  point.y = -0.68923;
  point.z = 0.26852;
  pol.points.push_back(point);
  point.x = -0.77087;
  point.y = 1.18289;
  point.z = 0.74892;
  pol.points.push_back(point);
  planePolygon->setPolygon(pol);

  Vector3 normal;
  normal.x = 0.39652;
  normal.y = -0.32885;
  normal.z = 0.85710;
  //planePolygon->setNormal(normal);


  point.x = 0.22078;
  point.y = 0.86032;
  point.z = -0.40858;
  pol.points.push_back(point);
  point.x = 0.95152;
  point.y = -1.00344;
  point.z = 0.31976;
  pol.points.push_back(point);
  point.x = -0.92901;
  point.y = 0.18325;
  point.z = 0.50957;
  pol.points.push_back(point);
  point.x = -0.97683;
  point.y = 1.84874;
  point.z = -0.42075;
  pol.points.push_back(point);
  planePolygon->setPolygon(pol);

  normal.x = 0.37210;
  normal.y = 0.46077;
  normal.z = 0.80575;
  planePolygon->setNormal(normal);

  planePolygon->setColor(c);
  planePolygon->insert();
  /*
   //Object
   s.x = 6;
   s.y = 3.2;
   s.z = 4;
   InteractiveMarker object;
   Marker sphere;
   sphere.type = Marker::SPHERE;
   sphere.color.r = c.g;
   sphere.color.g = c.r;
   sphere.color.b = c.b;
   sphere.color.a = c.a;
   sphere.scale = s;
   object.header.frame_id = "/world";
   object.name = "sphere";
   object.description = "Sphere";
   p.position.x = 20;
   object.pose = p;
   InteractiveMarkerControl control;
   control.name = "sphere_control";
   control.interaction_mode = InteractiveMarkerControl::NONE;
   control.always_visible = true;
   control.markers.push_back(sphere);
   object.controls.push_back(control);
   server->insert(object);
   // Bounding box
   c.r = 1;
   c.g = 0;
   c.b = 0;
   BoundingBox * sphereBoundingBox = new BoundingBox(server, "/world", "sphere_bbox");
   sphereBoundingBox->setAttachedObjectName("sphere");
   sphereBoundingBox->setPose(p);
   sphereBoundingBox->setScale(s);
   sphereBoundingBox->setColor(c);
   sphereBoundingBox->setDescription("Sphere bounding box");
   sphereBoundingBox->insert();

   Object * obj = new Object(server, "/world", "table_object");
   obj->setFrameID("/world");
   Pose ppp;
   ppp.position.x = 6;
   ppp.position.y = 5;
   ppp.position.z = 0;
   obj->setPose(ppp);
   Vector3 sss;
   sss.x = 1;
   sss.y = 1;
   sss.z = 1;
   c.a = 1.0;
   obj->setScale(sss);
   obj->setDescription("Table");
   obj->setColor(c);
   obj->setResource("package://gazebo_worlds/Media/models/table.dae");
   obj->setUseMaterial(false);
   obj->insert();

   ObjectWithBoundingBox * objbb = new ObjectWithBoundingBox(server, "/world", "table_with_bb");
   ppp.position.x = 2;
   ppp.position.y = 2;
   ppp.position.z = 2;
   objbb->setPose(ppp);
   c.a = 1.0;
   Vector3 gp;
   gp.x = 0.7;
   gp.y = 1.2;
   gp.z = 0;
   objbb->setGraspingPosition(GRASP_1, gp);
   gp.x = 0;
   gp.y = 1.2;
   gp.z = 0.9;
   objbb->setGraspingPosition(GRASP_2, gp);
   gp.x = 0.1;
   gp.y = 0.1;
   gp.z = 0.1;
   objbb->setGraspingPosition(GRASP_3, gp);
   Scale sbb;
   sbb.x = 0.2;
   sbb.y = 0.2;
   sbb.z = 0.2;
   Point bbm;
   bbm = Point();
   bbm.x = 1;
   bbm.y = 1;
   bbm.z = 1;
   objbb->setBoundingBoxLWH(bbm);
   objbb->setDescription("Table with Bounding Box");
   objbb->setColor(c);
   objbb->setResource("package://gazebo_worlds/Media/models/table.dae");
   objbb->setUseMaterial(true);

   arm_navigation_msgs::Shape shape;
   Point sp;
   sp.x = 0;
   sp.y = 0;
   sp.z = 0;
   shape.vertices.push_back(sp);
   sp.x = 1;
   shape.vertices.push_back(sp);
   sp.y = 2;
   shape.vertices.push_back(sp);
   shape.triangles.push_back(0);
   shape.triangles.push_back(1);
   shape.triangles.push_back(2);
   objbb->setShape(shape);

   objbb->insert();*/

  server->applyChanges();
  ros::spin();
}
Example #23
0
bool InitWindowsApp(HINSTANCE instanceHandle, int show)
{
	//ShowCursor(0);

	// The first task to creating a window is to describe some of its 
	// characteristics by filling out a WNDCLASS structure.
	WNDCLASS wc;
	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = WndProc; 
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = instanceHandle;
	wc.hIcon         = LoadIcon(0, IDI_APPLICATION);
	wc.hCursor       = LoadCursor(0, IDC_CROSS);
	wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
	wc.lpszMenuName  = 0;
	wc.lpszClassName = L"BasicWndClass";

	// Next, we register this WNDCLASS instance with Windows so that we can 
	// create a window based on it.
	if(!RegisterClass(&wc)) 
	{
		MessageBox(0, L"RegisterClass FAILED", 0, 0);
		return false;
	}

	// With our WNDCLASS instance registered, we can create a window with the
	// CreateWindow function.  This function returns a handle to the window it
	// creates (an HWND).  If the creation failed, the handle will have the value
	// of zero.  A window handle is a way to refer to the window, which is internally
	// managed by Windows.  Many of the Win32 API functions that operate on windows
	// require an HWND so that they know what window to act on.

	RECT rc;
	rc.left = 0;
	rc.top = 0;
	rc.right = SCREEN_WIDTH;
	rc.bottom = SCREEN_HEIGHT;
	AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false);

	g_Hwnd = CreateWindow(
		L"BasicWndClass",	 // Registered WNDCLASS instance to use.
		L"Gruppuppgift",	// window title
		WS_OVERLAPPEDWINDOW, // style flags
		CW_USEDEFAULT,		 // x-coordinate
		CW_USEDEFAULT,       // y-coordinate
		rc.right - rc.left,        // width
		rc.bottom - rc.top,       // height
		0,               // parent window
		0,               // menu handle
		instanceHandle,      // app instance
		0);              // extra creation parameters

	if(g_Hwnd == 0)
	{
		MessageBox(0, L"CreateWindow FAILED", 0, 0);
		return false;
	}

	// Even though we just created a window, it is not initially shown.  
	// Therefore, the final step is to show and update the window we just
	// created, which can be done with the following two function calls.
	// Observe that we pass the handle to the window we want to show and
	// update so that these functions know which window to show and update.

	ShowWindow(g_Hwnd, show);
	UpdateWindow(g_Hwnd);

	//________________________________

	// Fill out a DXGI_SWAP_CHAIN_DESC to describe our swap chain.
	DXGI_SWAP_CHAIN_DESC sd;
	sd.BufferDesc.Width  = SCREEN_WIDTH;
	sd.BufferDesc.Height = SCREEN_HEIGHT;
	sd.BufferDesc.RefreshRate.Numerator = 60;
	sd.BufferDesc.RefreshRate.Denominator = 1;
	sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

	// No multisampling.
	sd.SampleDesc.Count   = 1;
	sd.SampleDesc.Quality = 0;

	sd.BufferUsage  = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	sd.BufferCount  = 1;
	sd.OutputWindow = g_Hwnd;
	sd.Windowed     = true;
	sd.SwapEffect   = DXGI_SWAP_EFFECT_DISCARD;
	sd.Flags        = 0;

	D3D10CreateDeviceAndSwapChain(
		0,                 //default adapter
		D3D10_DRIVER_TYPE_HARDWARE,
		0,                 // no software device
		0, 
		D3D10_SDK_VERSION,
		&sd,
		&mSwapChain,
		&md3dDevice);

	ID3D10Texture2D* backBuffer;
	mSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&backBuffer);
	md3dDevice->CreateRenderTargetView(backBuffer, 0, &mRenderTargetView);
	backBuffer->Release();
	backBuffer = 0;

	
	// Create depth stencil texture
	D3D10_TEXTURE2D_DESC descDepth;
	ZeroMemory( &descDepth, sizeof(descDepth) );
	descDepth.Width = SCREEN_WIDTH;
	descDepth.Height = SCREEN_HEIGHT;
	descDepth.MipLevels = 1;
	descDepth.ArraySize = 1;
	descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	descDepth.SampleDesc.Count = 1;
	descDepth.SampleDesc.Quality = 0;
	descDepth.Usage = D3D10_USAGE_DEFAULT;
	descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;
	descDepth.CPUAccessFlags = 0;
	descDepth.MiscFlags = 0;
	md3dDevice->CreateTexture2D( &descDepth, NULL, &mDepthStencil );

	// Create the depth stencil view
	D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;
	ZeroMemory( &descDSV, sizeof(descDSV) );
	descDSV.Format = descDepth.Format;
	descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
	descDSV.Texture2D.MipSlice = 0;

	// Bind the render target view and depth/stencil view to the pipeline.
	md3dDevice->CreateDepthStencilView( mDepthStencil, &descDSV, &mDepthStencilView );
	md3dDevice->OMSetRenderTargets( 1, &mRenderTargetView, mDepthStencilView );

	// Set the viewport transform.
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	vp.Width    = SCREEN_WIDTH;
	vp.Height   = SCREEN_HEIGHT;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	md3dDevice->RSSetViewports(1, &vp);
	//________________________________

	Effects::InitAll(md3dDevice);
	fxU.init(md3dDevice, Effects::MeshFX);

	Terrain::InitInfo tii;
	tii.CellSpacing = 1.0f;
	tii.HeightmapFilename = L"flat513.raw";
	tii.HeightOffset = -30.0f;
	tii.HeightScale = 0.2f;
	tii.NumCols = 513;
	tii.NumRows = 513;
	land.init(md3dDevice, tii);
	//mTerrain.init(md3dDevice, (std::string)"Textures/Terrain/HeightMap.raw", 0.35f, -50.0f, 0.1f, 512, 512);

	//Cube c;
	//c.init(md3dDevice, D3DXVECTOR3(2.0f, 2.0f, 2.0f), D3DXVECTOR3(-16.0f, land.getHeight(-16.0f, -16.0f)+1.0f, -16.0f));
	//mCubes.push_back(c);
	//nr.push_back(0);

	nrOfTowers.push_back(0);
	
	mCubes.resize(10);
	for(int i = 0; i < mCubes.size();i++)
	{
		mCubes[i].init(i, md3dDevice, D3DXVECTOR3(5.0f,5.0f,5.0f), D3DXVECTOR3(0.0f, land.getHeight(0.0f,0.0f), 0.0f), (i*0.50f+0.50f));
		nr.push_back(0);
	}
	pWave = new wave(1, 20, md3dDevice, &land);
	pWave->initMonsters();
	
	mPyramid.init(md3dDevice, D3DXVECTOR3(2.0f, 2.0f, 2.0f), D3DXVECTOR3(-16.0f, land.getHeight(-16.0f, -16.0f)+5.0f, -16.0f));
	mCylinder.init(md3dDevice, 1.0f, D3DXVECTOR3(-2.0f, land.getHeight(-2.0f, -8.0f)+1.0f, -8.0f));

	//GetCamera().setPosY(land.getHeight(GetCamera().getPos().x, GetCamera().getPos().z));
	GetCamera().setLens(0.30f*pi, (float)SCREEN_WIDTH/SCREEN_HEIGHT, 1.0f, 1000.0f);

	fire.init(md3dDevice, Effects::FireFX, L"Textures/Particle/flare0.dds", 500);
	fire.setEmitPos(D3DXVECTOR3(-2.0f, land.getHeight(-5.0f, 2.0f)+2.5f, -8.0f));

	rain.init(md3dDevice, Effects::RainFX, L"Textures/Particle/raindrop.gif", 1000);

	sky.init(md3dDevice, L"Textures/Terrain/grassenvmap1024.dds", 5000.0f);
	
	//Trees
	D3DXVECTOR3 treeCenters[6];

	float x = -20.0f;
	float z = 20.0f;
	treeCenters[0] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = -23.0f;
	z = 16.0f;
	treeCenters[1] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = -3.0f;
	z = 18.0f;
	treeCenters[2] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = 22.0f;
	z = 13.0f;
	treeCenters[3] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = 17.0f;
	z = -23.0f;
	treeCenters[4] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = 22.0f;
	z = -20.0f;
	treeCenters[5] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);
	mTrees.init(md3dDevice, treeCenters, 6, L"Textures/Wood/tree3.dds");

	//QuadTree
	qtc.init(md3dDevice, &land, GetCamera().proj(), GetCamera().view());

	//init GUI
	gui.Init(md3dDevice,SCREEN_WIDTH,SCREEN_HEIGHT);
	//set gui callback
	gui.SetCallback(OnGUIEvent);
	//adding a button
	gui.AddButton(PLACE_TOWER,L"test.png",10,10,100,100);

	GetTowerScript().Init("tower");

	return true;
}
bool getBillboard(GetBillboard::Request &req, GetBillboard::Response &res)
{
  ROS_INFO("GETTING BILLBOARD");

  if (primitives.count(req.name) > 0)
  {
    Billboard *obj = (Billboard*)primitives.at(req.name);
    if (obj->getPrimitiveType() == srs_interaction_primitives::PrimitiveType::BILLBOARD)
    {
      res.name = req.name;
      res.frame_id = obj->getFrameID();
      res.pose_type = obj->getPoseType();
      res.pose = obj->getPose();
      res.description = obj->getDescription();
      res.scale = obj->getScale();
      res.description = obj->getDescription();
      res.type = obj->getType();
      res.velocity = obj->getVelocity();
      res.direction = obj->getDirection();
      return true;
    }
  }
  ROS_ERROR("Billboard with that name doesn't exist!");
  return false;
}
Example #25
0
File: trees.cpp Project: Sylla/osg
Node *makeTrees( void )
{
    Group *group = new Group;
    int i;

    getDatabaseCenterRadius( dbcenter, &dbradius );
    struct _tree  *t;

    Texture2D *tex = new Texture2D;
    tex->setImage(osgDB::readImageFile("Images/tree0.rgba"));

    StateSet *dstate = new StateSet;
    
    dstate->setTextureAttributeAndModes(0, tex, StateAttribute::ON );
    dstate->setTextureAttribute(0, new TexEnv );

    dstate->setAttributeAndModes( new BlendFunc, StateAttribute::ON );

    AlphaFunc* alphaFunc = new AlphaFunc;
    alphaFunc->setFunction(AlphaFunc::GEQUAL,0.05f);
    dstate->setAttributeAndModes( alphaFunc, StateAttribute::ON );

    dstate->setMode( GL_LIGHTING, StateAttribute::OFF );
    
    dstate->setRenderingHint( StateSet::TRANSPARENT_BIN );

    int tt[] = { 15, 30, 45, 58, 72, 75, 93, 96, 105, -1 };
    int *ttp = tt;

    i = 0;
    while( i < 105 )
    {
        ttx = trees[i].x;
        tty = trees[i].y;
        qsort( &trees[i], 105 - i, sizeof( _tree ), ct );

        i += *ttp;
        ttp++;
    }

    t = trees;
    i = 0;
    ttp = tt;
    while( *ttp != -1 )
    {
        Billboard *bb = new Billboard;
        //int starti = i;

        for( ; i < (*ttp); i++ )
        {
            t->x -= 0.3f;
            float  h = Hat(t->x, t->y, t->z );
            Vec3 pos( t->x, t->y, t->z-h );
            Geometry *geom = makeTree( t, dstate );
            bb->addDrawable( geom, pos );
            t++;
        }
        group->addChild( bb );
        ttp++;
    }

    return group;
}
Example #26
0
bool Billboard::CompareDistance(Billboard& a, Billboard& b)
{
	return a.GetDistanceFromCamera() > b.GetDistanceFromCamera();
}