2014-08-15 10:32:07 +08:00
|
|
|
#include "CCLight.h"
|
2014-08-15 14:51:23 +08:00
|
|
|
#include "2d/CCScene.h"
|
2014-08-15 10:32:07 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
Light3D::Light3D()
|
|
|
|
: _isEnabled(false)
|
|
|
|
, _range(0.0f)
|
2014-08-15 14:51:23 +08:00
|
|
|
, _innerAngle(0.0f)
|
|
|
|
, _outerAngle(0.0f)
|
2014-08-15 10:32:07 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
Light3D::~Light3D()
|
2014-08-15 10:32:07 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
Light3D* Light3D::Create( LightType lightType )
|
2014-08-15 14:51:23 +08:00
|
|
|
{
|
2014-08-15 19:15:14 +08:00
|
|
|
Light3D *light = new Light3D;
|
|
|
|
light->setLightType(lightType);
|
|
|
|
light->autorelease();
|
|
|
|
return light;
|
2014-08-15 14:51:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
void Light3D::setLightType( LightType lightType )
|
2014-08-15 14:51:23 +08:00
|
|
|
{
|
2014-08-15 19:15:14 +08:00
|
|
|
_lightType = lightType;
|
2014-08-15 14:51:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
|
|
|
|
Light3D::LightType Light3D::getLightType()
|
|
|
|
{
|
|
|
|
return _lightType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Light3D::setEnabled( bool isEnabled )
|
|
|
|
{
|
|
|
|
_isEnabled = isEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Light3D::getEnabled()
|
|
|
|
{
|
|
|
|
return _isEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Light3D::setRange( float range )
|
2014-08-15 14:51:23 +08:00
|
|
|
{
|
2014-08-15 19:15:14 +08:00
|
|
|
_range = range;
|
2014-08-15 14:51:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
float Light3D::getRange()
|
2014-08-15 14:51:23 +08:00
|
|
|
{
|
2014-08-15 19:15:14 +08:00
|
|
|
return _range;
|
2014-08-15 14:51:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
void Light3D::setDirection( const Vec3 &dir )
|
2014-08-15 14:51:23 +08:00
|
|
|
{
|
2014-08-15 19:15:14 +08:00
|
|
|
_dir = dir;
|
2014-08-15 14:51:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
const Vec3& Light3D::getDirection() const
|
2014-08-15 14:51:23 +08:00
|
|
|
{
|
2014-08-15 19:15:14 +08:00
|
|
|
return _dir;
|
2014-08-15 14:51:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
void Light3D::setInnerAngle( float angle )
|
2014-08-15 14:51:23 +08:00
|
|
|
{
|
2014-08-15 19:15:14 +08:00
|
|
|
_innerAngle = angle;
|
2014-08-15 14:51:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
float Light3D::getInnerAngle()
|
2014-08-15 14:51:23 +08:00
|
|
|
{
|
2014-08-15 19:15:14 +08:00
|
|
|
return _innerAngle;
|
2014-08-15 14:51:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
void Light3D::setOuterAngle( float angle )
|
2014-08-15 14:51:23 +08:00
|
|
|
{
|
2014-08-15 19:15:14 +08:00
|
|
|
_outerAngle = angle;
|
2014-08-15 14:51:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
float Light3D::getOuterAngle()
|
2014-08-15 14:51:23 +08:00
|
|
|
{
|
2014-08-15 19:15:14 +08:00
|
|
|
return _outerAngle;
|
2014-08-15 14:51:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
void Light3D::onEnter()
|
2014-08-15 14:51:23 +08:00
|
|
|
{
|
2014-08-15 19:15:14 +08:00
|
|
|
auto scene = getScene();
|
|
|
|
if (scene)
|
|
|
|
{
|
|
|
|
auto lights = scene->_lights;
|
|
|
|
auto iter = std::find(lights.begin(), lights.end(), this);
|
|
|
|
if (iter == lights.end())
|
|
|
|
lights.push_back(this);
|
|
|
|
}
|
2014-08-15 14:51:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
void Light3D::onExit()
|
2014-08-15 14:51:23 +08:00
|
|
|
{
|
2014-08-15 19:15:14 +08:00
|
|
|
auto scene = getScene();
|
|
|
|
if (scene)
|
|
|
|
{
|
|
|
|
auto lights = scene->_lights;
|
|
|
|
auto iter = std::find(lights.begin(), lights.end(), this);
|
|
|
|
if (iter != lights.end())
|
|
|
|
lights.erase(iter);
|
|
|
|
}
|
2014-08-15 14:51:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
NS_CC_END
|