# How to create a sun billboard with Ogre3d

I've been working with a few different engines alongside trying to code my own project. Rather than rewrite an entire renderer, etc I am using Ogre3d. To begin with I am trying to implement a very basic scene with day/night cycle.

I've created a plane, added a simple model over the plane to simulate ground and an object. I've also created a directional light which I rotate to simulate a moving sun.

// Add a sunlight
sunNode = OgreFramework::getSingletonPtr()->m_pSceneMgr->getRootSceneNode()->createChildSceneNode("sunNode");
sunNode->setPosition(0,0,0);

sun = OgreFramework::getSingletonPtr()->m_pSceneMgr->createLight("Sun");
sun->setPosition(0,0,0);
sun->setType(Ogre::Light::LT_DIRECTIONAL);
sun->setDiffuseColour(Ogre::ColourValue(0.7f,0.7f,0.7f));
sun->setSpecularColour(Ogre::ColourValue(0.7f,0.7f,0.7f));
sun->setDirection(Ogre::Vector3(0,0,1));
sunNode->attachObject(sun);


In the main loop, prior to rendering I rotate the sunNode with :

 // Rotate the sun
sunNode->pitch(Ogre::Degree(0.05), Ogre::Node::TS_LOCAL);


This all works pretty much like a expected. However, I then moved onto adding a billboard to the sunNode in order to render the sun moving through the sky. Creating the billboardset, setting the texture, adding a billboard and attaching it to the sunNode, was pretty straight forward, however, when I compiled and ran the application, the billboard just sat at the lights position (0,0,0) and didn't move.

What would be involved in getting a billboard to track through the sky to render a simple sun?

• Well, so far you haven't added any code to change the position of the sunNode, so how do you expect it to move? – Philip Allgaier Apr 1 '14 at 21:12
• Well, given all I've had to do when using other engines has been to rotate the light... they obviously took care of the position of the billboard. Clearly not the case here. I will keep experimenting. – Tim Apr 2 '14 at 9:49
• Do you want to move or to rotate the billboard? Those are two different things! – Philip Allgaier Apr 2 '14 at 9:57
• No, I want to rotate the light which is working. I want the billboard to track through the sky as it does in other engines I've worked with. I realise ogre isn't actually a game engine, however I had considered that a normal function of the renderers. Clearly it's been coded in each engine for simplicity sake. I'm here to learn more, with or without help I will work it out. Seems to me a child node with the billboard attached, positioned a good distance from the light might update it's position as the parent node is rotated. – Tim Apr 2 '14 at 22:25

## 1 Answer

So, the answer it turns out is to create a child scene node of the sunNode positioning it some distance away.

Ogre::SceneNode* sunBBNode = sunNode->createChildSceneNode("sunFlare", Ogre::Vector3(0,0,-1000));


Creating the billboard is easy. In this case, I am just using the Examples/Flare material from the default Ogre media.

Ogre::BillboardSet* sunBillboardSet = OgreFramework::getSingletonPtr()->m_pSceneMgr->createBillboardSet();
Ogre::Billboard* sunBillboard = sunBillboardSet->createBillboard(Ogre::Vector3(0,0,0));
sunBillboardSet->setMaterialName("Examples/Flare");


Then attach the billboardSet to the sunBBNode

sunBBNode->attachObject(sunBillboardSet);


Since sunBBNode is a child of the sunNode, its position is updated when its parent node is rotated, thus moving the billboard through the sky as expected.