Skip to content

Commit

Permalink
Light: deprecate node-less positioning
Browse files Browse the repository at this point in the history
same rationale like for camera. setDirection is only soft-deprected for
now due to the inconsistent default direction between SceneNode (0,0,-1)
and Light (0, 0, 1).
  • Loading branch information
paroj committed Aug 30, 2017
1 parent 8a3f414 commit e84d43e
Show file tree
Hide file tree
Showing 32 changed files with 152 additions and 104 deletions.
2 changes: 2 additions & 0 deletions OgreMain/include/Ogre.i
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ ADD_REPR(ColourValue)
%include "OgreShadowCaster.h"
%include "OgreMovableObject.h"
%include "OgreMovablePlane.h"
%ignore Ogre::Light::setPosition;
%ignore Ogre::Light::getPosition;
%include "OgreLight.h"
%include "OgreNode.h"
%include "OgreBone.h"
Expand Down
12 changes: 9 additions & 3 deletions OgreMain/include/OgreLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,32 +184,38 @@ namespace Ogre {
Applicable to point lights and spotlights only.
@note
This will be overridden if the light is attached to a SceneNode.
@deprecated attach to SceneNode and use SceneNode::setPosition
*/
void setPosition(Real x, Real y, Real z);
OGRE_DEPRECATED void setPosition(Real x, Real y, Real z);

/// @overload
/// @deprecated attach to SceneNode and use SceneNode::setPosition
void setPosition(const Vector3& vec);

/** Returns the position of the light.
@note
Applicable to point lights and spotlights only.
@deprecated attach to SceneNode and use SceneNode::getPosition
*/
const Vector3& getPosition(void) const;
OGRE_DEPRECATED const Vector3& getPosition(void) const;

/** Sets the direction in which a light points.
@remarks
Applicable only to the spotlight and directional light types.
@note
This will be overridden if the light is attached to a SceneNode.
@deprecated only call with (0, 0, -1), then attach to SceneNode and use SceneNode::setDirection
*/
void setDirection(Real x, Real y, Real z);

//// @overload
/// @overload
/// @deprecated only call with Vector3::NEGATIVE_UNIT_Z, then attach to SceneNode and use SceneNode::setDirection
void setDirection(const Vector3& vec);

/** Returns the light's direction.
@remarks
Applicable only to the spotlight and directional light types.
@deprecated attach to SceneNode and use SceneNode::getLocalAxes
*/
const Vector3& getDirection(void) const;

Expand Down
6 changes: 4 additions & 2 deletions Samples/AndroidJNI/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,17 @@ public void run() {
ShaderGenerator.getSingleton().addSceneManager(scnMgr);

Light light = scnMgr.createLight("MainLight");
light.setPosition(0, 10, 15);
SceneNode lightnode = scnMgr.getRootSceneNode().createChildSceneNode();
lightnode.setPosition(0, 10, 15);
lightnode.attachObject(light);

Camera cam = scnMgr.createCamera("myCam");
cam.setNearClipDistance(5);
cam.setAutoAspectRatio(true);

SceneNode camnode = scnMgr.getRootSceneNode().createChildSceneNode();
camnode.attachObject(cam);
camnode.translate(new Vector3(0, 0, 15), Node.TransformSpace.TS_LOCAL);
camnode.setPosition(0, 0, 15);

Entity ent = scnMgr.createEntity("Sinbad.mesh");
SceneNode node = scnMgr.getRootSceneNode().createChildSceneNode();
Expand Down
4 changes: 3 additions & 1 deletion Samples/BezierPatch/include/BezierPatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class _OgreSampleClassExport Sample_BezierPatch : public SdkSample
{
// setup some basic lighting for our scene
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
mSceneMgr->createLight()->setPosition(100, 100, 100);
mSceneMgr->getRootSceneNode()
->createChildSceneNode(Vector3(100, 100, 100))
->attachObject(mSceneMgr->createLight());

// define the control point vertices for our patch
PatchVertex verts[9] =
Expand Down
4 changes: 3 additions & 1 deletion Samples/Bootstrap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ void MyTestApp::setup(void)

// without light we would just get a black screen
Ogre::Light* light = scnMgr->createLight("MainLight");
light->setPosition(0, 10, 15);
Ogre::SceneNode* lightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
lightNode->setPosition(0, 10, 15);
lightNode->attachObject(light);

// also need to tell where we are
Ogre::SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
Expand Down
4 changes: 3 additions & 1 deletion Samples/CameraTrack/include/CameraTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class _OgreSampleClassExport Sample_CameraTrack : public SdkSample
{
// setup some basic lighting for our scene
mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
mSceneMgr->createLight()->setPosition(20, 80, 50);
mSceneMgr->getRootSceneNode()
->createChildSceneNode(Vector3(20, 80, 50))
->attachObject(mSceneMgr->createLight());

mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");

Expand Down
9 changes: 4 additions & 5 deletions Samples/CelShading/include/CelShading.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ class _OgreSampleClassExport Sample_CelShading : public SdkSample
mCameraMan->setStyle(CS_ORBIT);
mTrayMgr->showCursor();

// create a basic point light with an offset
Light* light = mSceneMgr->createLight();
light->setPosition(20, 40, 50);

// attach the light to a pivot node
mLightPivot = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mLightPivot->attachObject(light);

// create a basic point light with an offset
Light* light = mSceneMgr->createLight();
mLightPivot->createChildSceneNode(Vector3(20, 40, 50))->attachObject(light);

// create our model, give it the shader material, and place it at the origin
Entity *ent = mSceneMgr->createEntity("Head", "ogrehead.mesh");
Expand Down
4 changes: 3 additions & 1 deletion Samples/Character/include/CharacterSample.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class _OgreSampleClassExport Sample_Character : public SdkSample
// add a bright light above the scene
Light* light = mSceneMgr->createLight();
light->setType(Light::LT_POINT);
light->setPosition(-10, 40, 20);
mSceneMgr->getRootSceneNode()
->createChildSceneNode(Vector3(-10, 40, 20))
->attachObject(light);
light->setSpecularColour(ColourValue::White);

// create a floor mesh resource
Expand Down
4 changes: 3 additions & 1 deletion Samples/CubeMapping/include/CubeMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class _OgreSampleClassExport Sample_CubeMapping : public SdkSample, public Rende

// setup some basic lighting for our scene
mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
mSceneMgr->createLight()->setPosition(20, 80, 50);
mSceneMgr->getRootSceneNode()
->createChildSceneNode(Vector3(20, 80, 50))
->attachObject(mSceneMgr->createLight());

createCubeMap();

Expand Down
6 changes: 2 additions & 4 deletions Samples/Dot3Bump/include/Dot3Bump.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,28 +237,26 @@ class _OgreSampleClassExport Sample_Dot3Bump : public SdkSample

// create white light
l = mSceneMgr->createLight();
l->setPosition(200, 0, 0);
mLightPivot1->createChildSceneNode(Vector3(200, 0, 0))->attachObject(l);
l->setDiffuseColour(1, 1, 1);
l->setSpecularColour(1, 1, 1);
// create white flare
bbs = mSceneMgr->createBillboardSet();
bbs->setMaterialName("Examples/Flare");
bbs->createBillboard(200, 0, 0)->setColour(ColourValue::White);

mLightPivot1->attachObject(l);
mLightPivot1->attachObject(bbs);

// create red light
l = mSceneMgr->createLight();
l->setPosition(40, 200, 50);
mLightPivot2->createChildSceneNode(Vector3(50, 200, 50))->attachObject(l);
l->setDiffuseColour(1, 0, 0);
l->setSpecularColour(1, 0.8, 0.8);
// create white flare
bbs = mSceneMgr->createBillboardSet();
bbs->setMaterialName("Examples/Flare");
bbs->createBillboard(50, 200, 50)->setColour(ColourValue::Red);

mLightPivot2->attachObject(l);
mLightPivot2->attachObject(bbs);
}

Expand Down
12 changes: 6 additions & 6 deletions Samples/DualQuaternion/include/DualQuaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ class _OgreSampleClassExport Sample_DualQuaternion : public SdkSample
lightsBbsNode->attachObject(bbs);

Light* l = mSceneMgr->createLight();
Vector3 dir;
Vector3 pos(30, 70, 40);
l->setType(Light::LT_POINT);
l->setPosition(30, 70, 40);
dir = -l->getPosition();
dir.normalise();
l->setDirection(dir);
mSceneMgr->getRootSceneNode()
->createChildSceneNode(pos)
->attachObject(l);
l->setDirection(-pos.normalisedCopy());
l->setDiffuseColour(1, 1, 1);
bbs->createBillboard(l->getPosition())->setColour(l->getDiffuseColour());
bbs->createBillboard(pos)->setColour(l->getDiffuseColour());

// Create a floor mesh resource.
MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Expand Down
4 changes: 3 additions & 1 deletion Samples/DynTex/include/DynTex.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ class _OgreSampleClassExport Sample_DynTex : public SdkSample

// setup some basic lighting for our scene
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
mSceneMgr->createLight()->setPosition(20, 80, 50);
mSceneMgr->getRootSceneNode()
->createChildSceneNode(Vector3(20, 80, 50))
->attachObject(mSceneMgr->createLight());

// set initial camera position
mCameraMan->setStyle(CS_MANUAL);
Expand Down
8 changes: 6 additions & 2 deletions Samples/FacialAnimation/include/FacialAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ class _OgreSampleClassExport Sample_FacialAnimation : public SdkSample
{
// setup some basic lighting for our scene
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
mSceneMgr->createLight()->setPosition(40, 60, 50);
mSceneMgr->createLight()->setPosition(-120, -80, -50);
mSceneMgr->getRootSceneNode()
->createChildSceneNode(Vector3(40, 60, 50))
->attachObject(mSceneMgr->createLight());
mSceneMgr->getRootSceneNode()
->createChildSceneNode(Vector3(-120, -80, -50))
->attachObject(mSceneMgr->createLight());

// pre-load the mesh so that we can tweak it with a manual animation
mHeadMesh = MeshManager::getSingleton().load("facial.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Expand Down
4 changes: 2 additions & 2 deletions Samples/NewInstancing/src/NewInstancing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void Sample_NewInstancing::setupLighting()
//Create main (point) light
Light* light = mSceneMgr->createLight();
light->setDiffuseColour(lightColour);
light->setPosition( 0.0f, 25.0f, 0.0f );
mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3( 0.0f, 25.0f, 0.0f ))->attachObject(light);
light->setSpecularColour( 0.6, 0.82, 1.0 );
light->setAttenuation( 3500, 0.085, 0.00008, 0.00006 );
light->setCastShadows( false );
Expand All @@ -197,7 +197,7 @@ void Sample_NewInstancing::setupLighting()
light = mSceneMgr->createLight();
light->setType( Light::LT_SPOTLIGHT );
light->setDiffuseColour( ColourValue( 0.15f, 0.35f, 0.44f ) );
light->setPosition( 250.0f, 200.0f, 250.0f );
mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3( 250.0f, 200.0f, 250.0f ))->attachObject(light);
light->setDirection( (Vector3::UNIT_SCALE * -1.0f).normalisedCopy() );
light->setSpecularColour( 0.2, 0.12, 0.11 );
light->setAttenuation( 3500, 0.005, 0.00002, 0.00001 );
Expand Down
14 changes: 10 additions & 4 deletions Samples/PNTrianglesTessellation/include/PNTrianglesTessellation.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,11 @@ class _OgreSampleClassExport Sample_PNTriangles : public SdkSample
l = mSceneMgr->createLight();
l->setDiffuseColour(1.0f, 1.0f, 1.0f);
l->setSpecularColour(1.0f, 1.0f, 1.0f);
l->setDirection(Ogre::Vector3::UNIT_X*-1.0f);
l->setPosition(200, 0, 0);
l->setDirection(Vector3::NEGATIVE_UNIT_Z);
SceneNode* ln = mSceneMgr->getRootSceneNode()->createChildSceneNode();
ln->setPosition(Vector3(200, 0, 0));
ln->setDirection(-Vector3::UNIT_X);
ln->attachObject(l);
// create white flare
bbs = mSceneMgr->createBillboardSet();
bbs->setMaterialName("Examples/Flare");
Expand All @@ -223,8 +226,11 @@ class _OgreSampleClassExport Sample_PNTriangles : public SdkSample
l = mSceneMgr->createLight();
l->setDiffuseColour(1.0f, 0.0f, 0.0f);
l->setSpecularColour(1.0f, 0.0f, 0.0f);
l->setDirection(Ogre::Vector3::UNIT_X);
l->setPosition(-200, 0, 0);
l->setDirection(Vector3::NEGATIVE_UNIT_Z);
ln = mSceneMgr->getRootSceneNode()->createChildSceneNode();
ln->setPosition(Vector3(-200, 0, 0));
ln->setDirection(Vector3::UNIT_X);
ln->attachObject(l);
// create white flare
bbs = mSceneMgr->createBillboardSet();
bbs->setMaterialName("Examples/Flare");
Expand Down
4 changes: 3 additions & 1 deletion Samples/ParticleFX/include/ParticleFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class _OgreSampleClassExport Sample_ParticleFX : public SdkSample
{
// setup some basic lighting for our scene
mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
mSceneMgr->createLight()->setPosition(20, 80, 50);
mSceneMgr->getRootSceneNode()
->createChildSceneNode(Vector3(20, 80, 50))
->attachObject(mSceneMgr->createLight());

// set our camera to orbit around the origin and show cursor
mCameraMan->setStyle(CS_ORBIT);
Expand Down
4 changes: 3 additions & 1 deletion Samples/Python/bites_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def setup(self):
scn_mgr.setAmbientLight(Ogre.ColourValue(.1, .1, .1))

light = scn_mgr.createLight("MainLight")
light.setPosition(0, 10, 15)
lightnode = scn_mgr.getRootSceneNode().createChildSceneNode()
lightnode.setPosition(0, 10, 15)
lightnode.attachObject(light)

cam = scn_mgr.createCamera("myCam")
cam.setNearClipDistance(5)
Expand Down
4 changes: 3 additions & 1 deletion Samples/Python/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def main():
scn_mgr.setAmbientLight(Ogre.ColourValue(.1, .1, .1))

light = scn_mgr.createLight("MainLight")
light.setPosition(0, 10, 15)
lightnode = scn_mgr.getRootSceneNode().createChildSceneNode()
lightnode.setPosition(0, 10, 15)
lightnode.attachObject(light)

cam = scn_mgr.createCamera("myCam")
cam.setPosition(0, 0, 15)
Expand Down
2 changes: 1 addition & 1 deletion Samples/SSAO/include/SSAO.h
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ class _OgreSampleClassExport Sample_SSAO : public SdkSample
CompositorManager::getSingleton().setCompositorEnabled(mViewport, "SSAO/Post/Modulate", true);
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
mLight = mSceneMgr->createLight();
mLight->setPosition(30, 80, 30);
mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(30, 80, 30))->attachObject(mLight);
}
else
{
Expand Down
9 changes: 4 additions & 5 deletions Samples/Shadows/include/Shadows.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,11 @@ class _OgreSampleClassExport Sample_Shadows : public SdkSample
// Fixed light, dim
mSunLight = mSceneMgr->createLight("SunLight");
mSunLight->setType(Light::LT_SPOTLIGHT);
mSunLight->setPosition(1500,1750,1300);

Vector3 pos(1500,1750,1300);
mSceneMgr->getRootSceneNode()->createChildSceneNode(pos)->attachObject(mSunLight);
mSunLight->setSpotlightRange(Degree(30), Degree(50));
Vector3 dir;
dir = -mSunLight->getPosition();
dir.normalise();
mSunLight->setDirection(dir);
mSunLight->setDirection(-pos.normalisedCopy());
mSunLight->setDiffuseColour(0.35, 0.35, 0.38);
mSunLight->setSpecularColour(0.9, 0.9, 1);

Expand Down
23 changes: 12 additions & 11 deletions Samples/SkeletalAnimation/include/SkeletalAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,25 +197,26 @@ class _OgreSampleClassExport Sample_SkeletalAnimation : public SdkSample

// add a blue spotlight
Light* l = mSceneMgr->createLight();
Vector3 dir;
Vector3 pos(-40, 180, -10);
SceneNode* ln = mSceneMgr->getRootSceneNode()->createChildSceneNode(pos);
ln->attachObject(l);
l->setType(Light::LT_SPOTLIGHT);
l->setPosition(-40, 180, -10);
dir = -l->getPosition();
dir.normalise();
l->setDirection(dir);
l->setDirection(Vector3::NEGATIVE_UNIT_Z);
ln->setDirection(-pos);
l->setDiffuseColour(0.0, 0.0, 0.5);
bbs->createBillboard(l->getPosition())->setColour(l->getDiffuseColour());
bbs->createBillboard(pos)->setColour(l->getDiffuseColour());


// add a green spotlight.
l = mSceneMgr->createLight();
l->setType(Light::LT_SPOTLIGHT);
l->setPosition(0, 150, -100);
dir = -l->getPosition();
dir.normalise();
l->setDirection(dir);
l->setDirection(Vector3::NEGATIVE_UNIT_Z);
pos = Vector3(0, 150, -100);
ln = mSceneMgr->getRootSceneNode()->createChildSceneNode(pos);
ln->attachObject(l);
ln->setDirection(-pos);
l->setDiffuseColour(0.0, 0.5, 0.0);
bbs->createBillboard(l->getPosition())->setColour(l->getDiffuseColour());
bbs->createBillboard(pos)->setColour(l->getDiffuseColour());

// create a floor mesh resource
MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Expand Down
4 changes: 3 additions & 1 deletion Samples/SkyBox/include/SkyBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class _OgreSampleClassExport Sample_SkyBox : public SdkSample
{
// setup some basic lighting for our scene
mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
mSceneMgr->createLight()->setPosition(20, 80, 50);
mSceneMgr->getRootSceneNode()
->createChildSceneNode(Vector3(20, 80, 50))
->attachObject(mSceneMgr->createLight());

mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 5000); // set our skybox

Expand Down
4 changes: 3 additions & 1 deletion Samples/SkyDome/include/SkyDome.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class _OgreSampleClassExport Sample_SkyDome : public SdkSample
{
// setup some basic lighting for our scene
mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
mSceneMgr->createLight()->setPosition(20, 80, 50);
mSceneMgr->getRootSceneNode()
->createChildSceneNode(Vector3(20, 80, 50))
->attachObject(mSceneMgr->createLight());

// set our camera to orbit around the origin and show cursor
mCameraMan->setStyle(CS_ORBIT);
Expand Down
4 changes: 3 additions & 1 deletion Samples/SkyPlane/include/SkyPlane.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class _OgreSampleClassExport Sample_SkyPlane : public SdkSample
{
// setup some basic lighting for our scene
mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
mSceneMgr->createLight()->setPosition(20, 80, 50);
mSceneMgr->getRootSceneNode()
->createChildSceneNode(Vector3(20, 80, 50))
->attachObject(mSceneMgr->createLight());

// create a skyplane 5000 units away, facing down, 10000 square units large, with 3x texture tiling
mSceneMgr->setSkyPlane(true, Plane(0, -1, 0, 5000), "Examples/SpaceSkyPlane", 10000, 3);
Expand Down
Loading

0 comments on commit e84d43e

Please sign in to comment.