2014-08-15 10:32:07 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
class CC_DLL Light3D : public Node
|
2014-08-15 10:32:07 +08:00
|
|
|
{
|
2014-08-15 14:51:23 +08:00
|
|
|
public:
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
enum LightType
|
|
|
|
{
|
|
|
|
DIRECTIONAL = 0,
|
|
|
|
POINT = 1,
|
|
|
|
SPOT = 2
|
|
|
|
};
|
2014-08-15 14:51:23 +08:00
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
/**
|
2014-08-15 14:51:23 +08:00
|
|
|
* Create light according to type.
|
|
|
|
*/
|
2014-08-19 13:54:30 +08:00
|
|
|
static Light3D* CreateDirectionalLight(const Vec3 &direction, const Color3B &color);
|
2014-08-19 16:32:49 +08:00
|
|
|
static Light3D* CreatePointLight(const Vec3 &position, const Color3B &color, float range);
|
|
|
|
static Light3D* CreateSpotLight(const Vec3 &direction, const Vec3 &position, const Color3B &color, float innerAngle, float outerAngle, float range);
|
2014-08-15 14:51:23 +08:00
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
//override
|
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void onExit() override;
|
2014-08-15 14:51:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets light type.
|
|
|
|
*/
|
2014-08-15 19:15:14 +08:00
|
|
|
LightType getLightType();
|
|
|
|
|
2014-08-19 16:32:49 +08:00
|
|
|
/**
|
2014-08-19 15:51:30 +08:00
|
|
|
* Sets Light Enabled.
|
2014-08-19 16:32:49 +08:00
|
|
|
*/
|
|
|
|
void setEnabled(bool isON);
|
2014-08-19 15:51:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets Light Enabled.
|
|
|
|
*/
|
|
|
|
bool getEnabled();
|
|
|
|
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
/**
|
2014-08-15 14:51:23 +08:00
|
|
|
* Sets the range of point or spot light.
|
|
|
|
*
|
|
|
|
* @param range The range of point or spot light.
|
|
|
|
*/
|
2014-08-15 19:15:14 +08:00
|
|
|
void setRange(float range);
|
2014-08-15 14:51:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the range of point or spot light.
|
|
|
|
*
|
|
|
|
* @return The range of the point or spot light.
|
|
|
|
*/
|
2014-08-15 19:15:14 +08:00
|
|
|
float getRange();
|
2014-08-15 14:51:23 +08:00
|
|
|
|
|
|
|
/**
|
2014-08-20 16:20:22 +08:00
|
|
|
* Sets the Direction of Directional light or Spot light.
|
|
|
|
*
|
|
|
|
* @param dir The Direction of the Directional light or Spot light.
|
|
|
|
*/
|
2014-08-15 19:15:14 +08:00
|
|
|
void setDirection(const Vec3 &dir);
|
2014-08-15 14:51:23 +08:00
|
|
|
|
|
|
|
/**
|
2014-08-20 16:20:22 +08:00
|
|
|
* Returns the Direction of Directional light or Spot light.
|
|
|
|
*
|
|
|
|
* @return dir Direction of the Directional light or Spot light.
|
|
|
|
*/
|
|
|
|
Vec3 getDirection() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the World coordinate Direction of Directional light or Spot light.
|
|
|
|
*
|
|
|
|
* @return dir the World coordinate Direction of the Directional light or Spot light.
|
|
|
|
*/
|
|
|
|
Vec3 getWorldDirection() const;
|
2014-08-15 14:51:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the inner angle of a spot light (in radians).
|
|
|
|
*
|
|
|
|
* @param angle The angle of spot light (in radians).
|
|
|
|
*/
|
2014-08-15 19:15:14 +08:00
|
|
|
void setInnerAngle(float angle);
|
2014-08-15 14:51:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the inner angle the spot light (in radians).
|
|
|
|
*
|
|
|
|
* @return The inner angle of the spot light (in radians).
|
|
|
|
*/
|
2014-08-15 19:15:14 +08:00
|
|
|
float getInnerAngle();
|
2014-08-15 14:51:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the outer angle of a spot light (in radians).
|
|
|
|
*
|
|
|
|
* @param outerAngle The angle of spot light (in radians).
|
|
|
|
*/
|
2014-08-15 19:15:14 +08:00
|
|
|
void setOuterAngle(float angle);
|
2014-08-15 14:51:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the outer angle of the spot light (in radians).
|
|
|
|
*
|
|
|
|
* @return The outer angle of the spot light (in radians).
|
|
|
|
*/
|
2014-08-15 19:15:14 +08:00
|
|
|
float getOuterAngle();
|
2014-08-15 10:32:07 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2014-08-15 14:51:23 +08:00
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
Light3D();
|
|
|
|
virtual ~Light3D();
|
2014-08-15 14:51:23 +08:00
|
|
|
|
2014-08-19 13:54:30 +08:00
|
|
|
protected:
|
|
|
|
|
2014-08-19 16:32:49 +08:00
|
|
|
/**
|
2014-08-19 13:54:30 +08:00
|
|
|
* Sets light type.
|
|
|
|
*/
|
|
|
|
void setLightType(LightType lightType);
|
2014-08-20 16:20:22 +08:00
|
|
|
void calculateRotation(const Vec3 &direction);
|
2014-08-19 13:54:30 +08:00
|
|
|
|
2014-08-15 14:51:23 +08:00
|
|
|
protected:
|
|
|
|
|
2014-08-15 19:15:14 +08:00
|
|
|
LightType _lightType;
|
2014-08-19 16:32:49 +08:00
|
|
|
bool _isEnabled;
|
2014-08-15 19:15:14 +08:00
|
|
|
float _range;
|
|
|
|
float _innerAngle;
|
|
|
|
float _outerAngle;
|
2014-08-15 10:32:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2014-08-15 14:51:23 +08:00
|
|
|
#endif
|