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-19 16:32:49 +08:00
|
|
|
Light3D::Light3D()
|
|
|
|
: _isEnabled(true)
|
|
|
|
, _range(0.0f)
|
|
|
|
, _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
|
|
|
void Light3D::setLightType( LightType lightType )
|
2014-08-15 14:51:23 +08:00
|
|
|
{
|
2014-08-19 16:32:49 +08:00
|
|
|
_lightType = lightType;
|
2014-08-15 14:51:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
|
|
|
|
Light3D::LightType Light3D::getLightType()
|
|
|
|
{
|
2014-08-19 16:32:49 +08:00
|
|
|
return _lightType;
|
2014-08-15 19:15:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2014-08-18 17:10:07 +08:00
|
|
|
auto &lights = scene->_lights;
|
2014-08-15 19:15:14 +08:00
|
|
|
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)
|
|
|
|
{
|
2014-08-18 17:10:07 +08:00
|
|
|
auto &lights = scene->_lights;
|
2014-08-15 19:15:14 +08:00
|
|
|
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-19 13:54:30 +08:00
|
|
|
Light3D* Light3D::CreateDirectionalLight( const Vec3 &direction, const Color3B &color )
|
|
|
|
{
|
2014-08-19 16:32:49 +08:00
|
|
|
Light3D *light = new Light3D;
|
|
|
|
light->setLightType(DIRECTIONAL);
|
|
|
|
light->setDirection(direction);
|
|
|
|
light->setColor(color);
|
|
|
|
light->autorelease();
|
|
|
|
return light;
|
2014-08-19 13:54:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Light3D* Light3D::CreatePointLight( const Vec3 &position, const Color3B &color, float range )
|
|
|
|
{
|
2014-08-19 16:32:49 +08:00
|
|
|
Light3D *light = new Light3D;
|
|
|
|
light->setLightType(POINT);
|
|
|
|
light->setPosition3D(position);
|
|
|
|
light->setColor(color);
|
|
|
|
light->setRange(range);
|
|
|
|
light->autorelease();
|
|
|
|
return light;
|
2014-08-19 13:54:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Light3D* Light3D::CreateSpotLight( const Vec3 &direction, const Vec3 &position, const Color3B &color, float innerAngle, float outerAngle, float range )
|
|
|
|
{
|
2014-08-19 16:32:49 +08:00
|
|
|
Light3D *light = new Light3D;
|
|
|
|
light->setLightType(SPOT);
|
|
|
|
light->setDirection(direction);
|
|
|
|
light->setPosition3D(position);
|
|
|
|
light->setColor(color);
|
|
|
|
light->setInnerAngle(innerAngle);
|
|
|
|
light->setOuterAngle(outerAngle);
|
|
|
|
light->setRange(range);
|
|
|
|
light->autorelease();
|
|
|
|
return light;
|
2014-08-19 13:54:30 +08:00
|
|
|
}
|
|
|
|
|
2014-08-19 16:32:49 +08:00
|
|
|
void Light3D::setEnabled( bool isON )
|
2014-08-19 15:51:30 +08:00
|
|
|
{
|
2014-08-19 16:32:49 +08:00
|
|
|
_isEnabled = isON;
|
2014-08-19 15:51:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Light3D::getEnabled()
|
|
|
|
{
|
2014-08-19 16:32:49 +08:00
|
|
|
return _isEnabled;
|
2014-08-19 15:51:30 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
NS_CC_END
|