RenderableIterator& RenderableIterator::erase( RenderableIterator& item_to_remove )
{
	Renderable* pValueToErase = *item_to_remove;

	RenderLayers::iterator layerElements = theWorld.GetLayers().find( pValueToErase->GetLayer() );
	if (layerElements != theWorld.GetLayers().end())
	{
		RenderList::iterator element = (*layerElements).second.begin();

		while ( element != (*layerElements).second.end() )
		{
			if ( *element == pValueToErase)
			{					
				_myIterator = (*layerElements).second.erase(element);

				// Have to force to next layer.
				// Let our ++ operator do it's magic.
				if ( _myIterator == (*layerElements).second.end() )
				{
					++item_to_remove;
				}
				else
				{
					_ptr = *_myIterator;
				}

				return *this;
			}
			++element;
		}
	}
	return *this;
}
Beispiel #2
0
Renderable* Renderable::Lines(const std::vector<Vec3f> &verts, Material *material) {
    Renderable *renderable;
    float *vertexBuffer;
    unsigned int *indexBuffer;
    unsigned int size;
    unsigned int i;

    size = (unsigned int)verts.size();

    renderable = new Renderable();

    vertexBuffer = new float[size * 3];
    indexBuffer = new unsigned int[size];

    for(i=0; i < size; i++) {
        vertexBuffer[3*i  ] = verts[i].x;
        vertexBuffer[3*i+1] = verts[i].y;
        vertexBuffer[3*i+2] = verts[i].z;

        indexBuffer[i] = i;
    }
    
    renderable->setMaterial(material);
    renderable->setAttribBuffer("position", size, GL_FLOAT, 3, &vertexBuffer[0]);
    renderable->setIndexBuffer(size, &indexBuffer[0]);
    renderable->setDrawMode(GL_LINE_STRIP);

    delete vertexBuffer;
    delete indexBuffer;

    return renderable;
}
Beispiel #3
0
void Level::loadExit(MvUint tileX, MvUint tileY)
{
    LOGME_CALL("Level::loadExit");
    LOGME_DEBUG("Exit at %d, %d", tileX, tileY);

    auto e = mEcsContext.e();
    auto c = mEcsContext.c();
    EngineContext& ctx = mEngineContext;

    MvAnimation::Ptr aSpawn(new MvAnimation(RepeatMode::Loop));

    for (int i = 0; i < 3; ++i) {
        StaticDrawable::Ptr ptr(new StaticDrawable(ctx, Tex::Blob, BlueSpawn[i]));
        aSpawn->addDrawable(std::move(ptr));
        aSpawn->addFrame(i, sf::milliseconds(240));
    }

    Entity eSpawn = createEntity();
    CrawlComponents& cSpawn = c->attach<Transform, Renderable, Sensor>(eSpawn);

    Renderable* cRenderable = cSpawn.get<Renderable>();
    Sensor*     cSensor     = cSpawn.get<Sensor>();
    Transform*  cTransform  = cSpawn.get<Transform>();

    cRenderable->setLayer(def::layer::BackgroundNear);
    cRenderable->setDrawable(std::move(aSpawn));
    cTransform->setPosition(tileX * TW, tileY * TH);
    cSensor->setShapeCircle(2.f, sf::Vector2f(tileX * TW, tileY * TH));
    cSensor->setCollisionCategory(Collision::World);
    cSensor->setCollisionWith(Collision::Player);
    cSensor->setCategory(Category::ExitSensor);

    mEcsContext.s()->get<PhysicsSystem>()->initialize(eSpawn);
}
bool PointCloudRenderer::renderImpl(SoSeparator *ivRoot, Renderable &renderable)
{
    //Being here without a point cloud is a bug.
    assert(renderable.has_pointcloud() || renderable.has_pointcloud2());

    //Create the node subtree of the renderable if necessary.
    if(!ivRoot->getNumChildren())
    {
        createNodes(ivRoot, renderable);
    }
    setScale(ivRoot, renderable);
    //Get the nodes to insert the point data into.
    SoMaterial * mat = static_cast<SoMaterial *>(ivRoot->getChild(3));
    SoCoordinate3 * coord =
            static_cast<SoCoordinate3 *>(ivRoot->getChild(2));

    //Read the point data into Inventor structures.
    std::vector<SbVec3f> points;
    std::vector<SbColor> colors;
    int point_size = fillPointList(renderable, points,colors);
    //If points were parsed or the input meant to send no points,
    //set the new point cloud points and colors.
    if(points.size() || !point_size)
    {
        //Insert the inventor structures in to the
        coord->point.setValues(0,points.size(), &points[0]);
        mat->diffuseColor.setValues(0,colors.size(), &colors[0]);
    }
    return points.size() > 0;
}
void RenderablePlaneProjection::setTarget(std::string body) {

	if (body == "")
		return;

	std::vector<SceneGraphNode*> nodes = OsEng.renderEngine().scene()->allSceneGraphNodes();
	Renderable* possibleTarget;
	bool hasBody, found = false;
	std::string targetBody;

	for (auto node : nodes)
	{
		possibleTarget = node->renderable();
		if (possibleTarget != nullptr) {
			hasBody = possibleTarget->hasBody();
			if (hasBody && possibleTarget->getBody(targetBody) && (targetBody == body)) {
				_target.node = node->name(); // get name from propertyOwner
				found = true;
				break;
			}
		}
	}
	if (found) {
		_target.body = body;
		_target.frame = openspace::SpiceManager::ref().frameFromBody(body);
	}
}
Beispiel #6
0
void Level::ReadTee(char* tee)
{
  std::stringstream ss(tee);
  
  glm::vec3 pos;
  unsigned int tileid;

  ss >> tileid >> pos.x >> pos.y >> pos.z;

  _tee = new Tee;
  _tee->Initialize();
  _tee->SetTile(tileid - 1);

  // Load Renderable for circle
  // Scale appropriately
  // Position according to the stringstream
  Renderable *r = new Renderable;
  r->Initialize();
  Renderable::Color(glm::vec4(0.f, 0.f, 1.f, 1.f));
  r->LoadFromFile("Models/circle.obj");
  r->PostLoad();
  _tee->SetRenderable(r);
  
  _tee->GetMatrix()->Position(pos + glm::vec3(0.f, .01f, 0.f));
  _tee->GetMatrix()->Scale(0.075f);
}
Beispiel #7
0
    int main(int argc, char** argv) {
        //Init block
        glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
        glutInitWindowSize(width, height);
        glutInitWindowPosition(WIN_POS_X, WIN_POS_Y);
        glutInit(&argc, argv);

        //Read the object
        r.read("objects/f16.obj");
        r.normalize();
        r.center();
        path = readMoves("paths/spiral.path", 0.01, false);
        moveObj(); //Position the object for the initial showing

        //Create an appropriately named window
        window = glutCreateWindow(r.getName().c_str());

        //Set up the handlers
        glutReshapeFunc(reshapeHandler);
        glutDisplayFunc(displayHandler);
        glutKeyboardFunc(keypressHandler);

        glutMainLoop();
        return 0;
    }
Beispiel #8
0
std::vector<Object*> Scene::picking(const Vec2& point) const
{
    //var dec
    std::vector<Object*> pickedList;
    std::function<void(Object* obj)> auxPicking = nullptr;
    //aux fun
    auxPicking=[&](Object* obj)
    {
        //pick
        Renderable* renderable = nullptr;
        if ((renderable = obj->getComponent<Renderable>()))
        {
            if (renderable->isVisible())
            {
                const AABox2& box = renderable->getBaseBox();
                const AABox2& wbox = renderable->canTransform() ? box.applay(obj->getGlobalMatrix()) : box;
                if (wbox.isIntersection(point)) pickedList.push_back(obj);
            }
        }
        //rec
        if (!renderable || renderable->isVisible()) 
        for (Object* childs : *obj)
        {
            auxPicking(childs);
        };
    };
    //call aux
    for (Object* obj : objects) auxPicking(obj);
    //return
    return pickedList;
}
Beispiel #9
0
void RenderManager::update()
{
	Renderable *r = m_rendlist;
	while (r != NULL) {
		r->update();
		r = r->m_next;
	}
}
Beispiel #10
0
GLint setY(lua_State* L)
{
    if(lua_isstring(L,-2))
    {
        Renderable* auxrender = (Core::getInstance())->getRenderable(lua_tostring(L,-2));
        auxrender->move(auxrender->getX(), lua_tonumber(L,-1));
    }
}
Beispiel #11
0
void GLSceneNode::draw()
{
    QListIterator<Renderable*> it(this->objects);
    while(it.hasNext()) {
        Renderable *r = it.next();
        r->render();
    }
}
Beispiel #12
0
void ClientPage::PositionChanged(const Renderable& r)
{
    Packet p;
    p.write(PacketType::set_entity_position);
    p.write(r.getID());
    p.write(r.getPosition());
    sendUdpPacket(p);
}
Beispiel #13
0
		static void RenderableActivate(unsigned int aId)
		{
			const RenderableTemplate &renderabletemplate = Database::renderabletemplate.Get(aId);
			Renderable *renderable = new Renderable(renderabletemplate, aId);
			Database::renderable.Put(aId, renderable);
			renderable->SetAction(RenderDrawlist);
			renderable->Show();
		}
Beispiel #14
0
void setupBounds()
{
    Vec3f topLeftFront = Vec3f(-WIDTH/2., HEIGHT/2.,DEPTH/2.);
    Vec3f topLeftBack = Vec3f(-WIDTH/2., HEIGHT/2.,-DEPTH/2.);
    Vec3f topRightFront = Vec3f(WIDTH/2., HEIGHT/2.,DEPTH/2.);
    Vec3f topRightBack = Vec3f(WIDTH/2., HEIGHT/2.,-DEPTH/2.);
    Vec3f botLeftFront = Vec3f(-WIDTH/2., -HEIGHT/2.,DEPTH/2.);
    Vec3f botLeftBack = Vec3f(-WIDTH/2., -HEIGHT/2.,-DEPTH/2.);
    Vec3f botRightFront = Vec3f(WIDTH/2., -HEIGHT/2.,DEPTH/2.);
    Vec3f botRightBack = Vec3f(WIDTH/2., -HEIGHT/2.,-DEPTH/2.);


    bounds.setColour(Vec3f(0,0,1));
    bounds.setFragmentShaderPath("Shaders/basic_fs.glsl");
    bounds.setVertexShaderPath("Shaders/basic_vs.glsl");
    bounds.setRenderMode(GL_LINES);
    std::vector<Vec3f> points;

    points.push_back(topLeftFront);
    points.push_back(topLeftBack);

    points.push_back(topLeftBack);
    points.push_back(topRightBack);

    points.push_back(topRightBack);
    points.push_back(topRightFront);

    points.push_back(topRightFront);
    points.push_back(topLeftFront);

    points.push_back(botLeftFront);
    points.push_back(botLeftBack);

    points.push_back(botLeftBack);
    points.push_back(botRightBack);

    points.push_back(botRightBack);
    points.push_back(botRightFront);

    points.push_back(botRightFront);
    points.push_back(botLeftFront);

    points.push_back(topLeftFront);
    points.push_back(botLeftFront);

    points.push_back(topRightFront);
    points.push_back(botRightFront);

    points.push_back(topLeftBack);
    points.push_back(botLeftBack);

    points.push_back(topRightBack);
    points.push_back(botRightBack);



    bounds.setVerts(points);
}
float PointCloudRenderer::getProtoScale(Renderable & renderable)
{
    float factor = 1.0;
    if(renderable.pointcloud().has_units())
    {
        factor = 1000.0/renderable.pointcloud().units();
    }
    return factor;
}
Beispiel #16
0
void UiRenderPass::render(Renderer* client, const DrawContext& context)
{
	sLock.lock();
	myDrawTimeStat->startTiming();

	if(context.task == DrawContext::SceneDrawTask)
	{
		client->getRenderer()->beginDraw3D(context);
		glPushAttrib(GL_ALL_ATTRIB_BITS);

		// This is a bit of a hack. DIsable depth testing for ui stuff. We will take care of ordering.
		// This may lead to depth inconsistencies wrt the background scene when drawing 3d menus, but we want te
		// menus to always be visible and unoccluded by geometry.
		glDisable(GL_DEPTH_TEST);

		ui::Container* ui = myUiRoot;
		Renderable* uiRenderable = ui->getRenderable(client);
		if(uiRenderable != NULL)
		{
			uiRenderable->draw(context);
		}

		glPopAttrib();
		client->getRenderer()->endDraw();
	}
	else if(context.task == DrawContext::OverlayDrawTask)
	{
		Vector2i displaySize;
		// check if the tile is part of a canvas (a multi-tile grid). If it is,
		// get the canvas resolution. Otherwise simply use the tile resolution.
		if(context.tile->isInGrid)
		{
			DisplaySystem* ds = SystemManager::instance()->getDisplaySystem();
			displaySize = ds->getCanvasSize();
		}
		else
		{
			displaySize = context.tile->pixelSize;
		}

		client->getRenderer()->beginDraw2D(context);
		glPushAttrib(GL_ALL_ATTRIB_BITS);

		Renderable* uiRenderable = myUiRoot->getRenderable(client);
		if(uiRenderable != NULL)
		{
			uiRenderable->draw(context);
		}

		glPopAttrib();
		client->getRenderer()->endDraw();
	}

	myDrawTimeStat->stopTiming();
	sLock.unlock();
}
Beispiel #17
0
void ClosestHud::check(const Renderable& r, Vector pos)
{
    double dist = (pos - r.getPosition()).magnitudeSquared();
    if (m_dDistSquared > dist || !m_bValid) {
        m_dDistSquared = dist;
        m_bValid = true;
        m_vecPos = r.getPosition();
        m_ID = r.getID();
    }
}
Beispiel #18
0
void SpacePage::render(const Renderable& r)
{
    if (m_PlayerRenderable) {
        if (r.getType() == "troll") {
            m_Closest.check(r, m_PlayerRenderable->getPosition());
        }
    }
	Gosu::Graphics& g = PageManager::Instance()->graphics();
    r.draw(m_matGlobalToLocal, g.width(), g.height());
}
//----------------------------------------------------------------------------
void _ModePreViewTravelExecuteFun(Movable *mov, Any *data)
{
	PX2_UNUSED(data);

	Renderable *renderable = DynamicCast<Renderable>(mov);
	if (renderable)
	{
		renderable->SetFogInfulenceParam_Height(0.001f);
		renderable->SetFogInfulenceParam_Distance(0.001f);
	}
}
Beispiel #20
0
int main() {
    //Set up debug and info logging
    StreamAppender *appender = new StreamAppender(Logger::DEBUG | Logger::INFO, std::cout);
    Logger::add_appender(appender);
    fps::enable_fps_logging(true);
    
    //Create a window
    WindowManager &window_manager = WindowManager::get_instance();
    EasyWindow *easy_window = create_easy_window(640, 480);
    
    Window *window = easy_window->window;
    window->set_keyboard_callback(key_callback);
    
    //Create an object to add to the world
    Renderer *renderer = new Renderer(FLAT_VERTEX_SHADER,
                                      FLAT_FRAGMENT_SHADER);
    
    Mesh *mesh = new Mesh(2, Mesh::TRIANGLES);
    mesh->set_vertex_attribute(0, 3, 3, g_vertex_buffer_data);
    mesh->set_vertex_attribute(1, 3, 3, cube_colors);
    
    //Create an asset to wrap all of the above
    Asset *asset = new Asset;
    asset->set_mesh(mesh);
    asset->set_renderer(renderer);
    
    //Create a renderable to actually draw on the screen
    Renderable *renderable = new Renderable;
    renderable->asset = asset;
    renderable->set_position(0.0f, 0.0f, 0.3f);
    
    easy_window->world->add_child(renderable);
     
    //Set up the viewpoint
    viewpoint = new Viewpoint;
    viewpoint->set_far(100.0f);
    viewpoint->set_near(1.0f);
    viewpoint->set_position(0.0f, 0.0f, -0.5f);
    easy_window->screen->set_viewpoint(viewpoint);
    
    while(!window->get_should_close()) {
        window->render();
        window_manager.poll();
        fps::fps_tick();
    }
    
    destroy_easy_window(easy_window);
    delete viewpoint;
    
    //Clean up and exit
    Logger::shutdown();
    delete appender;
}
Beispiel #21
0
void Renderer::AddRenderable(const glm::vec3& position, const glm::vec3& rotation, const glm::vec3& scale, Mesh* mesh, GLuint texture, const Frustum& frustum)
{
	Renderable* renderable = new Renderable;

	renderable->SetMesh(mesh);
	renderable->SetModelMatrix(position, rotation, scale);
	renderable->SetTexture(texture);

	renderable->ApplyModelMatrix();

	if (ShouldDraw(renderable, frustum))
		m_Renderables.push_back(renderable);
}
Beispiel #22
0
void RenderManager::doRender() const
{
	int camW = m_Camera->Width(), camH = m_Camera->Height();
	//m_camX = _x; m_camY = _y, 
	double camZoom = m_Camera->Zoom(), camRot = m_Camera->Rotation(), camScale = m_Camera->Scale();

	Renderable *r = m_rendlist;
	while (r != NULL) {
		CameraTransform trans = m_Camera->worldToScreen( r->m_posX, r->m_posY, r->m_layer);
		r->draw(trans.x, trans.y, trans.zoom, trans.rot);
		r = r->m_next;
	}
}
Beispiel #23
0
// object
bool Commands::getObject(int argc, char** argv) {
    Renderable* ren = Renderable::get(argv[1]);
    if (ren) {
        if (ren->getType() != OBJ) {
            fprintf(stderr, "Commands::getObject ERROR Renderable with name %s already exists and has type %s\n",
                argv[1], toCstr(ren->getType()));
            CommandLine::clearState();
            return false;
        }
    } else {
        Renderable::create(OBJ, argv[1]);
    }
    return true;
}
bool FrameRenderer::renderImpl(SoSeparator * ivRoot, Renderable &renderable)
{
    SoSeparator * worldIVRoot = GraspItGUI::getInstance()->getIVmgr()->getWorld()->getIVRoot();
    SbName pc2Name("PointCloudRoot2");
    SoNodeList pointCloud2 = getChildByName(worldIVRoot, pc2Name);

    assert(renderable.has_renderableframe());
    SbName frameName(renderable.renderableframe().c_str());
    ivRoot = getOrAddSeparator(worldIVRoot, frameName);
    SoTransform * tran;

    if(ivRoot->getNumChildren() && ivRoot->getChild(0)->getTypeId() == SoTransform::getClassTypeId())
    {
        tran = static_cast<SoTransform *>(ivRoot->getChild(0));
       // DBGA("IVRoot child number: " << ivRoot->getNumChildren());
    }
    else
    {
        tran = new SoTransform();
        ivRoot->insertChild(tran, 0);
    }
    Quaternion q(renderable.frame().orientation().w(),renderable.frame().orientation().x(),
                 renderable.frame().orientation().y(),renderable.frame().orientation().z());
    tran->rotation.setValue(q.toSbRotation());
    float units = 1.0;

    if(renderable.frame().has_units())
        units = 1000.0/renderable.frame().units();

    tran->translation.setValue(renderable.frame().translation().x() * units,
                               renderable.frame().translation().y() * units,
                               renderable.frame().translation().z() * units);
    return true;
}
Beispiel #25
0
void Entity::updateRenderable(MeshHandle meshHandle)
{
	clearAllRenderable();
	IMesh *pMesh = gEngModule->pMeshMgr->getDataPtr(meshHandle);
	const SubMeshVec &subMeshVec = pMesh->getSubMeshVec();
	for (int i = 0; i < subMeshVec.size(); ++i)
	{
		Renderable *pRenderable = new StaticRenderable(meshHandle, i);
		addRenderable(pRenderable);
		std::string mtlName = subMeshVec[i].mtlName;
		IMaterial *pMaterial = gEngModule->pMaterialMgr->create("res/mesh/" + mtlName);
		pRenderable->setMaterial(gEngModule->pMaterialMgr->getHandle(pMaterial->getName()));
	}
}
Beispiel #26
0
void GenericRenderer::set_auto_attributes_on_shader(Renderable &buffer) {
    /*
     *  Binding attributes generically is hard. So we have some template magic in the send_attribute
     *  function above that takes the VertexData member functions we need to provide the attribute
     *  and just makes the whole thing generic. Before this was 100s of lines of boilerplate. Thank god
     *  for templates!
     */
    send_attribute(SP_ATTR_VERTEX_POSITION, buffer.vertex_data(), &VertexData::has_positions, &VertexData::position_offset);
    send_attribute(SP_ATTR_VERTEX_TEXCOORD0, buffer.vertex_data(), &VertexData::has_texcoord0, &VertexData::texcoord0_offset);
    send_attribute(SP_ATTR_VERTEX_TEXCOORD1, buffer.vertex_data(), &VertexData::has_texcoord1, &VertexData::texcoord1_offset);
    send_attribute(SP_ATTR_VERTEX_TEXCOORD2, buffer.vertex_data(), &VertexData::has_texcoord2, &VertexData::texcoord2_offset);
    send_attribute(SP_ATTR_VERTEX_TEXCOORD3, buffer.vertex_data(), &VertexData::has_texcoord3, &VertexData::texcoord3_offset);
    send_attribute(SP_ATTR_VERTEX_DIFFUSE, buffer.vertex_data(), &VertexData::has_diffuse, &VertexData::diffuse_offset);
    send_attribute(SP_ATTR_VERTEX_NORMAL, buffer.vertex_data(), &VertexData::has_normals, &VertexData::normal_offset);
}
Beispiel #27
0
Renderable* Renderable::Builder::build() {
  Renderable *renderable = new Renderable(renderType);
  if (renderType == RENDER_IMAGE) {
    Sprite *sprite = new Sprite();
    sprite->build(filePath, numClipsInRow, numClipsInCol, numTotalClips,
                 clipWidth, clipHeight);

    renderable->setSprite(sprite);
    renderable->setClipId(clipId);
  } else if (renderType == RENDER_TEXT) {
    renderable->setText(text);
  }

  return renderable;
}
Beispiel #28
0
bool Viewport::isContainedInFrustum(const Renderable& r) const {
	AABB bb = r.getObject().transformAABB(r.getMesh()->getBounds());

	Vector halfSize = (bb.max - bb.min) * 0.5f;
	Vector worldPos = r.getObject().getWorldPosition();

	//for each plane, check where the AABB is placed
	for (auto&& i : range(4)) {
		if (mWorldFrustumPlanes[i].getSide(worldPos, halfSize) < 0) {
			return false;
		}
	}

	return true;
}
Renderable::Renderable(const Renderable &other)
{
	model = other.getModel();
	object_id = ++NUMBER_OF_OBJECTS;
	object = other.object;
	selected = false;
}
Beispiel #30
0
void BaseRenderer::Render()
{
    glEnable(GL_DEPTH_TEST);

    for(int i = 0; i < m_Renderables.size(); i++)
    {
        Renderable* Ptr = m_Renderables[i];
        if(Ptr->GetType() == DEFAULT_RENDERABLE || Ptr->GetType() == ENTITY_RENDERABLE)
            RenderDefault(Ptr);

        if(Ptr->GetType() == TWODIM_RENDERABLE)
            Render2D(Ptr);
    }

    glDisable(GL_DEPTH_TEST);
}