2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCLIGHT_H__
|
|
|
|
#define __CCLIGHT_H__
|
|
|
|
|
|
|
|
#include "2d/CCNode.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
enum class LightType
|
|
|
|
{
|
|
|
|
DIRECTIONAL = 0,
|
2021-12-25 10:04:45 +08:00
|
|
|
POINT = 1,
|
|
|
|
SPOT = 2,
|
|
|
|
AMBIENT = 3,
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class LightFlag
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
LIGHT0 = 1,
|
|
|
|
LIGHT1 = 1 << 1,
|
|
|
|
LIGHT2 = 1 << 2,
|
|
|
|
LIGHT3 = 1 << 3,
|
|
|
|
LIGHT4 = 1 << 4,
|
|
|
|
LIGHT5 = 1 << 5,
|
|
|
|
LIGHT6 = 1 << 6,
|
|
|
|
LIGHT7 = 1 << 7,
|
|
|
|
LIGHT8 = 1 << 8,
|
|
|
|
LIGHT9 = 1 << 9,
|
2019-11-23 20:27:39 +08:00
|
|
|
LIGHT10 = 1 << 10,
|
|
|
|
LIGHT11 = 1 << 11,
|
|
|
|
LIGHT12 = 1 << 12,
|
|
|
|
LIGHT13 = 1 << 13,
|
|
|
|
LIGHT14 = 1 << 14,
|
|
|
|
LIGHT15 = 1 << 15,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
@js NA
|
|
|
|
*/
|
|
|
|
class CC_DLL BaseLight : public Node
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the light type,light type MUST be one of LightType::DIRECTIONAL ,
|
|
|
|
* LightType::POINT, LightType::SPOT, LightType::AMBIENT.
|
|
|
|
*/
|
|
|
|
virtual LightType getLightType() const = 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** intensity getter and setter */
|
|
|
|
float getIntensity() const { return _intensity; }
|
|
|
|
void setIntensity(float intensity);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**light flag getter and setter*/
|
|
|
|
LightFlag getLightFlag() const { return _lightFlag; }
|
|
|
|
void setLightFlag(LightFlag flag) { _lightFlag = flag; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* light enabled getter and setter.
|
|
|
|
*/
|
|
|
|
void setEnabled(bool enabled) { _enabled = enabled; }
|
|
|
|
bool isEnabled() const { return _enabled; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
// override
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void onExit() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS : BaseLight();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~BaseLight();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
void setRotationFromDirection(const Vec3& direction);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
float _intensity;
|
|
|
|
LightFlag _lightFlag;
|
|
|
|
bool _enabled;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
@js NA
|
|
|
|
*/
|
|
|
|
class CC_DLL DirectionLight : public BaseLight
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a direction light.
|
|
|
|
* @param direction The light's direction
|
|
|
|
* @param color The light's color.
|
|
|
|
*
|
|
|
|
* @return The new direction light.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static DirectionLight* create(const Vec3& direction, const Color3B& color);
|
|
|
|
|
|
|
|
// get light type
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual LightType getLightType() const override { return LightType::DIRECTIONAL; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Sets the Direction in parent.
|
|
|
|
*
|
|
|
|
* @param dir The Direction in parent.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setDirection(const Vec3& dir);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Returns the Direction in parent.
|
|
|
|
*/
|
|
|
|
Vec3 getDirection() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Returns direction in world.
|
|
|
|
*/
|
|
|
|
Vec3 getDirectionInWorld() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS : DirectionLight();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~DirectionLight();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
@js NA
|
|
|
|
*/
|
|
|
|
class CC_DLL PointLight : public BaseLight
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a point light.
|
|
|
|
* @param position The light's position
|
|
|
|
* @param color The light's color.
|
|
|
|
* @param range The light's range.
|
|
|
|
*
|
|
|
|
* @return The new point light.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static PointLight* create(const Vec3& position, const Color3B& color, float range);
|
|
|
|
|
|
|
|
// get light type
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual LightType getLightType() const override { return LightType::POINT; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** get or set range */
|
|
|
|
float getRange() const { return _range; }
|
|
|
|
void setRange(float range) { _range = range; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS : PointLight();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~PointLight();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
|
|
|
float _range;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
@js NA
|
|
|
|
*/
|
|
|
|
class CC_DLL SpotLight : public BaseLight
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a spot light.
|
|
|
|
* @param direction The light's direction
|
|
|
|
* @param position The light's position
|
|
|
|
* @param color The light's color.
|
|
|
|
* @param innerAngle The light's inner angle (in radians).
|
|
|
|
* @param outerAngle The light's outer angle (in radians).
|
|
|
|
* @param range The light's range.
|
|
|
|
*
|
|
|
|
* @return The new spot light.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static SpotLight* create(const Vec3& direction,
|
|
|
|
const Vec3& position,
|
|
|
|
const Color3B& color,
|
|
|
|
float innerAngle,
|
|
|
|
float outerAngle,
|
|
|
|
float range);
|
|
|
|
|
|
|
|
// get light type
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual LightType getLightType() const override { return LightType::SPOT; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Sets the Direction in parent.
|
|
|
|
*
|
|
|
|
* @param dir The Direction in parent.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setDirection(const Vec3& dir);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Returns the Direction in parent.
|
|
|
|
*/
|
|
|
|
Vec3 getDirection() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Returns direction in world.
|
|
|
|
*/
|
|
|
|
Vec3 getDirectionInWorld() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Sets the range of point or spot light.
|
|
|
|
*
|
|
|
|
* @param range The range of point or spot light.
|
|
|
|
*/
|
|
|
|
void setRange(float range) { _range = range; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Returns the range of point or spot light.
|
|
|
|
*
|
|
|
|
* @return The range of the point or spot light.
|
|
|
|
*/
|
|
|
|
float getRange() const { return _range; }
|
|
|
|
/**
|
|
|
|
* Sets the inner angle of a spot light (in radians).
|
|
|
|
*
|
|
|
|
* @param angle The angle of spot light (in radians).
|
|
|
|
*/
|
|
|
|
void setInnerAngle(float angle);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Returns the inner angle the spot light (in radians).
|
|
|
|
*/
|
|
|
|
float getInnerAngle() const { return _innerAngle; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** get cos innerAngle */
|
|
|
|
float getCosInnerAngle() const { return _cosInnerAngle; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Sets the outer angle of a spot light (in radians).
|
|
|
|
*
|
|
|
|
* @param outerAngle The angle of spot light (in radians).
|
|
|
|
*/
|
|
|
|
void setOuterAngle(float outerAngle);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Returns the outer angle of the spot light (in radians).
|
|
|
|
*/
|
|
|
|
float getOuterAngle() const { return _outerAngle; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** get cos outAngle */
|
|
|
|
float getCosOuterAngle() const { return _cosOuterAngle; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS : SpotLight();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~SpotLight();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
|
|
|
float _range;
|
|
|
|
float _innerAngle;
|
|
|
|
float _cosInnerAngle;
|
|
|
|
float _outerAngle;
|
|
|
|
float _cosOuterAngle;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
@js NA
|
|
|
|
*/
|
|
|
|
class CC_DLL AmbientLight : public BaseLight
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a ambient light.
|
|
|
|
* @param color The light's color.
|
|
|
|
*
|
|
|
|
* @return The new ambient light.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static AmbientLight* create(const Color3B& color);
|
|
|
|
|
|
|
|
// get light type
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual LightType getLightType() const override { return LightType::AMBIENT; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS : AmbientLight();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~AmbientLight();
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif
|