📄 showtsshape.cc
字号:
for (S32 i=0; i<threads.size(); i++)
if (play[i])
shapeInstance->advanceTime(scale[i]*dt,threads[i]);
if (addGround)
{
shapeInstance->animateGround();
addGroundTransform(shapeInstance->getGroundTransform());
}
shapeInstance->animate();
}
//------------------------------------------------------------
// TS Control for show objects
//------------------------------------------------------------
bool ShowProcessCameraQuery(CameraQuery *q)
{
MatrixF xRot, zRot;
xRot.set(EulerF(camRot.x, 0, 0));
zRot.set(EulerF(0, 0, camRot.z));
cameraMatrix.mul(zRot, xRot);
q->nearPlane = 0.1;
q->farPlane = 2100.0;
q->fov = 3.1415 / 2;
cameraMatrix.setColumn(3, camPos);
q->cameraMatrix = cameraMatrix;
return true;
}
void ShowRenderWorld()
{
glClear(GL_DEPTH_BUFFER_BIT);
glDisable(GL_CULL_FACE);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
dglSetCanonicalState();
gClientSceneGraph->renderScene();
dglSetCanonicalState();
glDisable(GL_DEPTH_TEST);
AssertFatal(dglIsInCanonicalState(), "Not in canonical state on exit!");
}
//class ShowTSCtrl : public GuiTSCtrl
//{
// typedef GuiTSCtrl Parent;
//public:
// bool processCameraQuery(CameraQuery *query);
// void renderWorld(const RectI &updateRect);
// void onRender(Point2I offset, const RectI &updateRect);
//// void onMouseMove(const GuiEvent &evt);
//
// DECLARE_CONOBJECT(ShowTSCtrl);
//};
IMPLEMENT_CONOBJECT(ShowTSCtrl);
bool ShowTSCtrl::processCameraQuery(CameraQuery * q)
{
return ShowProcessCameraQuery(q);
}
void ShowTSCtrl::onRender(Point2I offset, const RectI &updateRect)
{
glColor3i(0, 0, 0);
glDisable(GL_DEPTH_TEST);
glBegin(GL_TRIANGLE_FAN);
glVertex2i(updateRect.point.x, updateRect.point.y);
glVertex2i(updateRect.point.x + updateRect.extent.x, updateRect.point.y);
glVertex2i(updateRect.point.x + updateRect.extent.x, updateRect.point.y + updateRect.extent.y);
glVertex2i(updateRect.point.x, updateRect.point.y + updateRect.extent.y);
glEnd();
Parent::onRender(offset, updateRect);
}
void ShowTSCtrl::renderWorld(const RectI &updateRect)
{
ShowRenderWorld();
dglSetClipRect(updateRect);
}
//------------------------------------------------------------
// console functions for show plugin
//------------------------------------------------------------
ConsoleFunctionGroupBegin( ShowTool, "Functions for controlling the show tool.");
ConsoleFunction( showShapeLoad, void, 2, 3, "(string shapeName, bool faceCamera)")
{
argc;
Point3F vec,pos;
cameraMatrix.getColumn(1,&vec);
cameraMatrix.getColumn(3,&pos);
vec *= initialShowDistance;
ShowTSShape * show = new ShowTSShape(argv[1]);
if (show->shapeLoaded())
{
show->setPosition(pos+vec);
show->registerObject();
Sim::getRootGroup()->addObject(show);
}
else
delete show;
showUpdateThreadControl();
// make sure detail slider is set correctly
setDetailSlider();
}
ConsoleFunction( showSequenceLoad, void, 2, 3, "(string sequenceFile, string sequenceName=NULL)")
{
ShowTSShape * currentShow = ShowTSShape::currentShow;
if (!currentShow)
return;
char buffer[512];
if (argc==2)
dSprintf(buffer,512,"new TSShapeConstructor() { baseShape=\"%s\";sequence0=\"%s\"; };",currentShow->getShapeName(),argv[1]);
else
dSprintf(buffer,512,"new TSShapeConstructor() { baseShape=\"%s\";sequence0=\"%s %s\"; };",currentShow->getShapeName(),argv[1],argv[2]);
Con::evaluate(buffer);
ShowTSShape::reset();
}
ConsoleFunction( showSelectSequence, void, 1, 1, "")
{
ShowTSShape * currentShow = ShowTSShape::currentShow;
if (!currentShow)
return;
GuiTextListCtrl * threadList = static_cast<GuiTextListCtrl*>(Sim::findObject("threadList"));
if (!threadList)
return;
GuiTextListCtrl * sequenceList = static_cast<GuiTextListCtrl*>(Sim::findObject("sequenceList"));
if (!sequenceList)
return;
S32 threadNum = threadList->getSelectedCell().y;
S32 seq = sequenceList->getSelectedCell().y;
if (threadNum>=0 && seq>=0)
{
if (Con::getBoolVariable("$showTransition",false) && !currentShow->isBlend(seq))
{
F32 pos;
F32 dur = Con::getFloatVariable("$showTransitionDuration",0.2f);
GuiSliderCtrl * tpos = static_cast<GuiSliderCtrl*>(Sim::findObject("transitionPosition"));
if (Con::getBoolVariable("$showTransitionSynched",true) || !tpos)
pos = currentShow->getPos(threadNum);
else
pos = tpos->getValue();
bool targetPlay = Con::getBoolVariable("$showTransitionTargetPlay",true);
currentShow->transitionToSequence(threadNum,seq,pos,dur,targetPlay);
}
else
currentShow->setSequence(threadNum,seq);
GuiSliderCtrl * slider = static_cast<GuiSliderCtrl*>(Sim::findObject("threadPosition"));
if (slider && slider->getRoot())
{
char buffer[32];
dSprintf(buffer,32,"%g",currentShow->getPos(threadNum));
slider->setScriptValue(buffer);
}
}
showUpdateThreadControl();
return;
}
ConsoleFunction( showSetDetailSlider, void, 1, 1, "")
{
setDetailSlider();
}
ConsoleFunction( showUpdateThreadControl, void, 1, 1, "")
{
showUpdateThreadControl();
}
ConsoleFunction( showPlay, void, 1, 2, "(int threadNum = -1)")
{
ShowTSShape * currentShow = ShowTSShape::currentShow;
if (!currentShow)
return;
if (argc==1)
{
for (S32 i=0; i < currentShow->getThreadCount(); i++)
currentShow->setPlay(i,1);
}
else
{
S32 i = dAtoi(argv[1]);
if (i>=0)
currentShow->setPlay(i,1);
}
}
ConsoleFunction( showStop, void, 1, 2, "(int threadNum = -1)")
{
ShowTSShape * currentShow = ShowTSShape::currentShow;
if (!currentShow)
return;
if (argc==1)
{
for (S32 i=0; i < currentShow->getThreadCount(); i++)
currentShow->setPlay(i,0);
}
else
{
S32 i = dAtoi(argv[1]);
if (i>=0)
currentShow->setPlay(i,0);
}
}
ConsoleFunction (showSetScale, void, 3, 3, "(int threadNum, float scale)")
{
ShowTSShape * currentShow = ShowTSShape::currentShow;
if (!currentShow)
return;
S32 idx = dAtoi(argv[1]);
float s = dAtof(argv[2]);
if (idx>=0)
currentShow->setThreadScale(idx,s);
showUpdateThreadControl();
}
ConsoleFunction( showSetPos, void, 2, 2, "(int threadNum, float pos)")
{
ShowTSShape * currentShow = ShowTSShape::currentShow;
if (!currentShow)
return;
S32 idx = dAtoi(argv[1]);
float s = dAtof(argv[2]);
if (idx>=0)
currentShow->setPos(idx,s);
}
ConsoleFunction( showNewThread, void, 1, 1, "")
{
ShowTSShape * currentShow = ShowTSShape::currentShow;
if (!currentShow)
return;
currentShow->newThread();
showUpdateThreadControl();
}
ConsoleFunction( showDeleteThread, void, 2, 2, "(int threadNum)")
{
ShowTSShape * currentShow = ShowTSShape::currentShow;
if (!currentShow)
return;
S32 th = dAtoi(argv[1]);
if (th>=0)
currentShow->deleteThread(th);
showUpdateThreadControl();
}
ConsoleFunction( showToggleRoot, void, 1, 1, "")
{
ShowTSShape * currentShow = ShowTSShape::currentShow;
if (!currentShow)
return;
currentShow->setAnimateRoot(!currentShow->getAnimateRoot());
}
ConsoleFunction( showToggleStick, void, 1, 1, "")
{
ShowTSShape * currentShow = ShowTSShape::currentShow;
if (!currentShow)
return;
currentShow->setStickToGround(!currentShow->getStickToGround());
}
ConsoleFunction( showSetCamera, void, 2, 2, "(char orbitShape) t or T to orbit, else free-fly.")
{
ShowTSShape * currentShow = ShowTSShape::currentShow;
if (argv[1][0]=='t' || argv[1][0]=='T' && currentShow)
// orbit
currentShow->orbitUs();
else
// no orbit -- camera moves freely
orbitPos = NULL;
}
ConsoleFunction(showSetKeyboard, void, 2, 2, "(char moveShape) Set to t or T.")
{
keyboardControlsShape = (argv[1][0]=='t' || argv[1][0]=='T');
}
ConsoleFunction(showTurnLeft, void, 2, 2, "(float amt)")
{
gShowShapeLeftSpeed = dAtof(argv[1]);
}
ConsoleFunction( showTurnRight, void, 2, 2, "(float amt)")
{
gShowShapeRightSpeed = dAtof(argv[1]);
}
ConsoleFunction( showSetLightDirection, void, 1, 1, "")
{
cameraMatrix.getColumn(1,(Point3F*)&lightDir);
lightDir.x *= -1.0f;
lightDir.y *= -1.0f;
lightDir.z *= -1.0f;
lightDir.w *= -1.0f;
}
ConsoleFunctionGroupEnd( ShowTool );
void ShowInit()
{
Con::addVariable("showForwardAction", TypeF32, &gShowForwardAction);
Con::addVariable("showBackwardAction", TypeF32, &gShowBackwardAction);
Con::addVariable("showUpAction", TypeF32, &gShowUpAction);
Con::addVariable("showDownAction", TypeF32, &gShowDownAction);
Con::addVariable("showLeftAction", TypeF32, &gShowLeftAction);
Con::addVariable("showRightAction", TypeF32, &gShowRightAction);
Con::addVariable("showMovementSpeed", TypeF32, &gShowMovementSpeed);
Con::addVariable("showPitch", TypeF32, &camRot.x);
Con::addVariable("showYaw", TypeF32, &camRot.z);
cameraMatrix.identity();
camRot.set(0,0,0);
camPos.set(10,10,10);
cameraMatrix.setColumn(3,camPos);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -