-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLightObj.cpp
133 lines (121 loc) · 4.04 KB
/
LightObj.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "stdafx.h"
#include "LightObj.h"
#include "BaseApplication.h"
SceneLightObj::SceneLightObj( LightType type,int tag )
{
BaseApplication* appMgr=BaseApplication::getInstance();
SceneObj();
mObjType=LightObj;
mType=type;
long t=GetTickCount();
mTag = tag + t;
char strtemp[30];
sprintf(strtemp,"LightObj%i",tag);
mUserName = strtemp;
sprintf(strtemp,"%s%ld",strtemp,t); //%ld表示long类型//
mName=strtemp;
bVisualable=true;
mPostion=Vector3::ZERO;
mScale=Vector3(1,1,1);
mRotaion=Vector3::ZERO;
bCastShadow=true;
mPower=1.0;
mDirection=Ogre::Vector3::NEGATIVE_UNIT_Y;
mdiffuseColor=Ogre::ColourValue::Blue;
mspecularColor=Ogre::ColourValue::White;
farClipDistance=100;
nearClipDistance=2;
shadowFarDistance=800;
influenceDistance=1500;
constParam=0;
lineParam=0.1;
quadParam=0;
innerDegree=30;
outDegree=50;
fallOff=0.1;
mNode=BaseApplication::getInstance()->mSceneMgr->createSceneNode(mName);
subNode=appMgr->mSceneMgr->createSceneNode();
mNode->addChild(subNode);
subNode->setPosition(0,-1,0);
if (type==LightPoint)
{
mEntity=appMgr->mSceneMgr->createEntity("pointLight.mesh");
mEntity->setMaterialName("LightmeshAlph");
mEntity->setCastShadows(false);
mResName=Ogre::String("点光源.Light");
mLight=appMgr->mSceneMgr->createLight();
mLight->setType(Ogre::Light::LT_POINT);
mLight->setAttenuation(influenceDistance,constParam,lineParam,quadParam);
}
else if (type==LightSpot)
{
Ogre::Entity* msub=appMgr->mSceneMgr->createEntity("pointLight.mesh");
msub->setMaterialName("LightmeshAlph");
msub->setCastShadows(false);
subNode->attachObject(msub);
subNode->setScale(0.4,0.4,0.4);
mEntity=appMgr->mSceneMgr->createEntity("spotLight.mesh");
mEntity->setMaterialName("LightmeshFrame");
mEntity->setCastShadows(false);
mResName=Ogre::String("聚光灯.Light");
mLight=appMgr->mSceneMgr->createLight();
mLight->setType(Ogre::Light::LT_SPOTLIGHT);
mLight->setSpotlightRange(Ogre::Degree(innerDegree), Ogre::Degree(outDegree),fallOff);
mLight->setAttenuation(influenceDistance,constParam,lineParam,quadParam);
}
else if (type==Lightdirection)
{
mEntity=appMgr->mSceneMgr->createEntity("directionLight.mesh");
mEntity->setMaterialName("LightmeshAlph");
mEntity->setCastShadows(false);
mResName=Ogre::String("平行光.Light");
mLight=appMgr->mSceneMgr->createLight();
mLight->setType(Ogre::Light::LT_DIRECTIONAL);
mLight->setAttenuation(influenceDistance,constParam,lineParam,quadParam);
}
mNode->attachObject(mEntity);
mLight->setCastShadows(bCastShadow);
mLight->setDiffuseColour(mdiffuseColor);
mLight->setSpecularColour(mspecularColor);
mNode->attachObject(mLight);
mLight->setDirection(mDirection);
mLight->setShadowFarDistance(shadowFarDistance);
mLight->setShadowFarClipDistance(farClipDistance);
mLight->setShadowNearClipDistance(nearClipDistance);
mLight->setDebugDisplayEnabled(true);
}
SceneLightObj::~SceneLightObj()
{
BaseApplication::getInstance()->mSceneMgr->destroyLight(mLight);
}
void SceneLightObj::setPosition( Vector3 &pos )
{
mNode->setPosition(pos);
//mLight->setPosition(pos);
mPostion=pos;
}
void SceneLightObj::setScale( Vector3 &scale )
{
mNode->setScale(scale.x,scale.y,scale.z);
mScale=scale;
}
void SceneLightObj::setRotaion( Vector3 &rotaion )
{
mNode->resetOrientation();
mNode->pitch(Ogre::Degree(rotaion.x),Ogre::Node::TS_PARENT);
mNode->yaw(Ogre::Degree(rotaion.y),Ogre::Node::TS_PARENT);
mNode->roll(Ogre::Degree(rotaion.z),Ogre::Node::TS_PARENT);
mRotaion=rotaion;
Vector3 subNodePos=subNode->_getDerivedPosition();
Vector3 localpos=subNode->getPosition();
mDirection=subNodePos-mNode->getPosition();
//float x,y,z;
//x= -Math::Sin(Ogre::Degree(rotaion.z).valueRadians()) * Math::Cos(Ogre::Degree(rotaion.y).valueRadians());
//y= -Math::Cos(Ogre::Degree(rotaion.z).valueRadians()) * Math::Cos(Ogre::Degree(rotaion.x).valueRadians());
//z= -Math::Sin(Ogre::Degree(rotaion.x).valueRadians()) * Math::Cos(Ogre::Degree(rotaion.y).valueRadians());
//mDirection=Vector3(x,y,z);
mLight->setDirection(mDirection);
}
void SceneLightObj::onUpdateValueChange( int tag )
{
}