mirror of https://github.com/Poikilos/b3view
improve WebKit style compliance
parent
17ecfa6146
commit
9db00c6473
169
Engine.cpp
169
Engine.cpp
|
@ -33,11 +33,16 @@ void Engine::setupScene()
|
|||
m_Scene->setAmbientLight(SColorf(0.2f, 0.2f, 0.2f));
|
||||
|
||||
// Setup Camera
|
||||
// (so z-forward characters face camera partially (formerly vector3df(0, 0, -10), vector3df())
|
||||
// (so z-forward characters face camera partially
|
||||
// (formerly vector3df(0, 0, -10), vector3df())
|
||||
m_CamPos = vector3df(4.5, 3.5, 9);
|
||||
m_CamTarget = vector3df(0, 3, 0);
|
||||
ICameraSceneNode* camera = m_Scene->addCameraSceneNode(nullptr, m_CamPos, m_CamTarget); // this will be overridden by View m_Yaw and m_Pitch--see "calculate m_Yaw" further down
|
||||
camera->setAspectRatio(static_cast<f32>(m_Driver->getScreenSize().Width) / static_cast<f32>(m_Driver->getScreenSize().Height));
|
||||
// Below will be overridden by View m_Yaw and m_Pitch--see "calculate m_Yaw"
|
||||
// further down.
|
||||
ICameraSceneNode* camera = m_Scene->addCameraSceneNode(nullptr, m_CamPos,
|
||||
m_CamTarget);
|
||||
camera->setAspectRatio(static_cast<f32>(m_Driver->getScreenSize().Width)
|
||||
/ static_cast<f32>(m_Driver->getScreenSize().Height));
|
||||
}
|
||||
|
||||
IGUIEnvironment* Engine::getGUIEnvironment() const
|
||||
|
@ -68,7 +73,8 @@ void Engine::drawAxisLines()
|
|||
bool enableAxisWidget = true;
|
||||
m_Driver->setTransform(ETS_WORLD, matrix4());
|
||||
if (m_View != nullptr) {
|
||||
if (this->m_UserInterface->viewMenu->isItemChecked(this->m_UserInterface->viewTargetIdx)) {
|
||||
if (this->m_UserInterface->viewMenu->isItemChecked(
|
||||
this->m_UserInterface->viewTargetIdx)) {
|
||||
if (m_View->zUp()) {
|
||||
descend3df.Z = this->m_CamTarget.Z;
|
||||
}
|
||||
|
@ -85,10 +91,13 @@ void Engine::drawAxisLines()
|
|||
descendSidewaysForward3df.Z = this->m_CamTarget.Z;
|
||||
}
|
||||
m_Driver->setMaterial(descenderMaterialVert);
|
||||
m_Driver->draw3DLine(vector3df(), descend3df, descenderMaterialVert.EmissiveColor);
|
||||
m_Driver->draw3DLine(vector3df(), descend3df,
|
||||
descenderMaterialVert.EmissiveColor);
|
||||
m_Driver->setMaterial(descenderMaterialHorz);
|
||||
m_Driver->draw3DLine(descend3df, descendSideways3df, descenderMaterialHorz.EmissiveColor);
|
||||
m_Driver->draw3DLine(descendSideways3df, descendSidewaysForward3df, descenderMaterialHorz.EmissiveColor);
|
||||
m_Driver->draw3DLine(descend3df, descendSideways3df,
|
||||
descenderMaterialHorz.EmissiveColor);
|
||||
m_Driver->draw3DLine(descendSideways3df, descendSidewaysForward3df,
|
||||
descenderMaterialHorz.EmissiveColor);
|
||||
f32 arrowDirection = 1.0f;
|
||||
vector3df arrowLeft3df(descendSidewaysForward3df);
|
||||
vector3df arrowRight3df(descendSidewaysForward3df);
|
||||
|
@ -109,43 +118,63 @@ void Engine::drawAxisLines()
|
|||
arrowRight3df.X -= arrowSize;
|
||||
arrowRight3df.Z += arrowSize * arrowDirection;
|
||||
}
|
||||
m_Driver->draw3DLine(descendSidewaysForward3df, arrowLeft3df, descenderMaterialHorz.EmissiveColor);
|
||||
m_Driver->draw3DLine(descendSidewaysForward3df, arrowRight3df, descenderMaterialHorz.EmissiveColor);
|
||||
// position2d<s32> targetPos2d = m_Scene->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(this->m_CamTarget);
|
||||
m_Driver->draw3DLine(descendSidewaysForward3df, arrowLeft3df,
|
||||
descenderMaterialHorz.EmissiveColor);
|
||||
m_Driver->draw3DLine(descendSidewaysForward3df, arrowRight3df,
|
||||
descenderMaterialHorz.EmissiveColor);
|
||||
// position2d<s32> targetPos2d = m_Scene->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(
|
||||
// this->m_CamTarget
|
||||
// );
|
||||
// dimension2d<u32> textSize;
|
||||
// if (m_AxisFont != nullptr) {
|
||||
// textSize = m_AxisFont->getDimension(L"target");
|
||||
// m_AxisFont->draw(L"target", rect<s32>(targetPos2d, textSize), descenderMaterial.EmissiveColor, true, true);
|
||||
// m_AxisFont->draw(L"target", rect<s32>(targetPos2d, textSize),
|
||||
// descenderMaterial.EmissiveColor, true,
|
||||
// true);
|
||||
// }
|
||||
}
|
||||
enableAxisWidget = this->m_UserInterface->viewMenu->isItemChecked(this->m_UserInterface->viewAxisWidgetIdx);
|
||||
enableAxisWidget = this->m_UserInterface->viewMenu->isItemChecked(
|
||||
this->m_UserInterface->viewAxisWidgetIdx
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (enableAxisWidget) {
|
||||
m_Driver->setMaterial(xMaterial);
|
||||
m_Driver->draw3DLine(vector3df(), vector3df(axisLength, 0, 0), SColor(255, 255, 0, 0));
|
||||
position2d<s32> textPos = m_Scene->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(vector3df(axisLength + axisLength*.1f, 0, 0));
|
||||
m_Driver->draw3DLine(vector3df(), vector3df(axisLength, 0, 0),
|
||||
SColor(255, 255, 0, 0));
|
||||
position2d<s32> textPos = m_Scene->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(
|
||||
vector3df(axisLength + axisLength*.1f, 0, 0)
|
||||
);
|
||||
dimension2d<u32> textSize;
|
||||
if (m_AxisFont != nullptr) {
|
||||
textSize = m_AxisFont->getDimension(L"X+");
|
||||
m_AxisFont->draw(L"X+", rect<s32>(textPos, textSize), SColor(255, 255, 0, 0), true, true);
|
||||
m_AxisFont->draw(L"X+", rect<s32>(textPos, textSize),
|
||||
SColor(255, 255, 0, 0), true, true);
|
||||
}
|
||||
|
||||
m_Driver->setMaterial(yMaterial);
|
||||
m_Driver->draw3DLine(vector3df(), vector3df(0, axisLength, 0), SColor(255, 0, 255, 0));
|
||||
textPos = m_Scene->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(vector3df(0, axisLength + axisLength*.1f, 0));
|
||||
m_Driver->draw3DLine(vector3df(), vector3df(0, axisLength, 0),
|
||||
SColor(255, 0, 255, 0));
|
||||
textPos = m_Scene->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(
|
||||
vector3df(0, axisLength + axisLength*.1f, 0)
|
||||
);
|
||||
if (m_AxisFont != nullptr) {
|
||||
textSize = m_AxisFont->getDimension(L"Y+");
|
||||
m_AxisFont->draw(L"Y+", rect<s32>(textPos, textSize), SColor(255, 0, 255, 0), true, true);
|
||||
m_AxisFont->draw(L"Y+", rect<s32>(textPos, textSize),
|
||||
SColor(255, 0, 255, 0), true, true);
|
||||
}
|
||||
|
||||
m_Driver->setMaterial(zMaterial);
|
||||
m_Driver->draw3DLine(vector3df(), vector3df(0, 0, axisLength), SColor(255, 0, 0, 255));
|
||||
textPos = m_Scene->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(vector3df(0, 0, axisLength + axisLength*.1f));
|
||||
m_Driver->draw3DLine(vector3df(), vector3df(0, 0, axisLength),
|
||||
SColor(255, 0, 0, 255));
|
||||
textPos = m_Scene->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(
|
||||
vector3df(0, 0, axisLength + axisLength*.1f)
|
||||
);
|
||||
if (m_AxisFont != nullptr) {
|
||||
textSize = m_AxisFont->getDimension(L"Z+");
|
||||
m_AxisFont->draw(L"Z+", rect<s32>(textPos, textSize), SColor(255, 0, 0, 255), true, true);
|
||||
m_AxisFont->draw(L"Z+", rect<s32>(textPos, textSize),
|
||||
SColor(255, 0, 0, 255), true, true);
|
||||
}
|
||||
//delete xMaterial;
|
||||
//delete yMaterial;
|
||||
|
@ -156,16 +185,20 @@ void Engine::drawAxisLines()
|
|||
void Engine::drawBackground()
|
||||
{
|
||||
dimension2d<u32> screenSize = m_Driver->getScreenSize();
|
||||
m_Driver->draw2DRectangle(rect<s32>(0, 0, static_cast<s32>(screenSize.Width), static_cast<s32>(screenSize.Height)),
|
||||
m_Driver->draw2DRectangle(
|
||||
rect<s32>(0, 0, static_cast<s32>(screenSize.Width),
|
||||
static_cast<s32>(screenSize.Height)),
|
||||
SColor(255, 128, 128, 255),
|
||||
SColor(255, 128, 128, 255),
|
||||
SColor(255, 224, 224, 255),
|
||||
SColor(255, 224, 224, 255));
|
||||
SColor(255, 224, 224, 255)
|
||||
);
|
||||
}
|
||||
|
||||
void Engine::checkResize()
|
||||
{
|
||||
if ((m_WindowSize.Width != m_Driver->getScreenSize().Width) || (m_WindowSize.Height != m_Driver->getScreenSize().Height)) {
|
||||
if ((m_WindowSize.Width != m_Driver->getScreenSize().Width)
|
||||
|| (m_WindowSize.Height != m_Driver->getScreenSize().Height)) {
|
||||
m_WindowSize.Width = m_Driver->getScreenSize().Width;
|
||||
m_WindowSize.Height = m_Driver->getScreenSize().Height;
|
||||
|
||||
|
@ -214,9 +247,11 @@ Engine::Engine()
|
|||
this->textureExtensions.push_back(L"jpg");
|
||||
this->textureExtensions.push_back(L"bmp");
|
||||
#if WIN32
|
||||
m_Device = createDevice(EDT_DIRECT3D9, dimension2d<u32>(1024, 768), 32, false, false, false, nullptr);
|
||||
m_Device = createDevice(EDT_DIRECT3D9, dimension2d<u32>(1024, 768), 32,
|
||||
false, false, false, nullptr);
|
||||
#else
|
||||
m_Device = createDevice(EDT_OPENGL, dimension2d<u32>(1024, 768), 32, false, false, false, nullptr);
|
||||
m_Device = createDevice(EDT_OPENGL, dimension2d<u32>(1024, 768), 32,
|
||||
false, false, false, nullptr);
|
||||
#endif
|
||||
m_Device->setResizable(true);
|
||||
|
||||
|
@ -227,7 +262,8 @@ Engine::Engine()
|
|||
m_Scene = m_Device->getSceneManager();
|
||||
|
||||
wstringstream windowTitle;
|
||||
windowTitle << L"b3view (Blitz3D/Irrlicht Viewer) [" << m_Driver->getName() << L"]";
|
||||
windowTitle << L"b3view (Blitz3D/Irrlicht Viewer) [" << m_Driver->getName()
|
||||
<< L"]";
|
||||
m_Device->setWindowCaption(windowTitle.str().c_str());
|
||||
|
||||
setupScene();
|
||||
|
@ -242,7 +278,8 @@ Engine::Engine()
|
|||
|
||||
// Load font for displaying Axis names
|
||||
m_AxisFontFace = new CGUITTFace();
|
||||
// NOTE: m_FontPath is modified y UserInterface constructor above if font was missing
|
||||
// NOTE: m_FontPath is modified y UserInterface constructor above if font
|
||||
// was missing
|
||||
if (m_AxisFontFace->load(m_FontPath.c_str())) {
|
||||
m_AxisFont = new CGUITTFont(m_UserInterface->getGUIEnvironment());
|
||||
m_AxisFont->attach(m_AxisFontFace, 14);
|
||||
|
@ -286,7 +323,7 @@ void Engine::loadMesh(const wstring& fileName)
|
|||
|
||||
irr::scene::IAnimatedMesh* mesh = m_Scene->getMesh(fileName.c_str());
|
||||
if (mesh != nullptr) {
|
||||
m_Device->setWindowCaption(( wstring(L"b3view - ") + fileName).c_str());
|
||||
m_Device->setWindowCaption((wstring(L"b3view - ") + fileName).c_str());
|
||||
m_LoadedMesh = m_Scene->addAnimatedMeshSceneNode(mesh);
|
||||
Utility::dumpMeshInfoToConsole(m_LoadedMesh);
|
||||
if (Utility::toLower(Utility::extensionOf(fileName)) == L"3ds") {
|
||||
|
@ -295,7 +332,9 @@ void Engine::loadMesh(const wstring& fileName)
|
|||
m_View->setZUp(false);
|
||||
}
|
||||
if (m_LoadedMesh != nullptr) {
|
||||
this->m_UserInterface->playbackFPSEditBox->setText(Utility::toWstring(m_LoadedMesh->getAnimationSpeed()).c_str());
|
||||
this->m_UserInterface->playbackFPSEditBox->setText(
|
||||
Utility::toWstring(m_LoadedMesh->getAnimationSpeed()).c_str()
|
||||
);
|
||||
ICameraSceneNode* camera = this->m_Scene->getActiveCamera();
|
||||
aabbox3d<f32> box = m_LoadedMesh->getTransformedBoundingBox();
|
||||
//vector3d<float> extents = box.getExtent();
|
||||
|
@ -331,12 +370,16 @@ void Engine::loadMesh(const wstring& fileName)
|
|||
m_CamPos.Y = m_CamPos.Y * scale;
|
||||
m_CamPos.Z = m_CamPos.Z * scale;
|
||||
oldCamPos = m_CamPos;
|
||||
m_View->setCameraDistance(m_CamPos.getDistanceFrom(m_CamTarget));
|
||||
m_View->setCameraDistance(
|
||||
m_CamPos.getDistanceFrom(m_CamTarget)
|
||||
);
|
||||
camera->setPosition(m_CamPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_LoadedMesh->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
|
||||
m_LoadedMesh->setMaterialType(
|
||||
video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF
|
||||
);
|
||||
// EMT_TRANSPARENT_ALPHA_CHANNEL: constant transparency
|
||||
}
|
||||
}
|
||||
|
@ -369,12 +412,15 @@ bool Engine::loadTexture(const wstring& fileName)
|
|||
ret = true;
|
||||
}
|
||||
this->m_PrevTexturePath = fileName;
|
||||
this->m_UserInterface->texturePathEditBox->setText(this->m_PrevTexturePath.c_str());
|
||||
this->m_UserInterface->texturePathEditBox->setText(
|
||||
this->m_PrevTexturePath.c_str()
|
||||
);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Engine::setMeshDisplayMode(bool wireframe, bool lighting, bool textureInterpolation)
|
||||
void Engine::setMeshDisplayMode(bool wireframe, bool lighting,
|
||||
bool textureInterpolation)
|
||||
{
|
||||
if (m_LoadedMesh != nullptr) {
|
||||
for (u32 materialIndex = 0; materialIndex < m_LoadedMesh->getMaterialCount(); materialIndex++) {
|
||||
|
@ -384,30 +430,50 @@ void Engine::setMeshDisplayMode(bool wireframe, bool lighting, bool textureInter
|
|||
// Set Lighting
|
||||
if (!lighting) {
|
||||
m_LoadedMesh->getMaterial(materialIndex).Lighting = false;
|
||||
m_LoadedMesh->getMaterial(materialIndex).EmissiveColor = SColor(255, 255, 255, 255);
|
||||
m_LoadedMesh->getMaterial(materialIndex).EmissiveColor = SColor(
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
);
|
||||
} else {
|
||||
m_LoadedMesh->getMaterial(materialIndex).Lighting = true;
|
||||
m_LoadedMesh->getMaterial(materialIndex).EmissiveColor = SColor(255, 0, 0, 0);
|
||||
m_LoadedMesh->getMaterial(materialIndex).EmissiveColor = SColor(
|
||||
255,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
);
|
||||
}
|
||||
// m_LoadedMesh->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL); //already done on load
|
||||
// m_LoadedMesh->setMaterialFlag(video::E_ALPHA_SOURCE, true); // requires EMT_ONETEXTURE
|
||||
// m_LoadedMesh->setMaterialType(
|
||||
// video::EMT_TRANSPARENT_ALPHA_CHANNEL
|
||||
// ); //already done on load
|
||||
// // requires EMT_ONETEXTURE:
|
||||
// m_LoadedMesh->setMaterialFlag(video::E_ALPHA_SOURCE, true);
|
||||
if (textureInterpolation) {
|
||||
m_LoadedMesh->setMaterialFlag(video::EMF_BILINEAR_FILTER, true);
|
||||
m_LoadedMesh->setMaterialFlag(video::EMF_TRILINEAR_FILTER, true);
|
||||
m_LoadedMesh->setMaterialFlag(video::EMF_TRILINEAR_FILTER,
|
||||
true);
|
||||
} else {
|
||||
m_LoadedMesh->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
|
||||
m_LoadedMesh->setMaterialFlag(video::EMF_TRILINEAR_FILTER, false);
|
||||
m_LoadedMesh->setMaterialFlag(video::EMF_BILINEAR_FILTER,
|
||||
false);
|
||||
m_LoadedMesh->setMaterialFlag(video::EMF_TRILINEAR_FILTER,
|
||||
false);
|
||||
//m_LoadedMesh->setMaterialFlag(video::E_ALPHA_SOURCE, true);
|
||||
|
||||
// below doesn't work for some reason:
|
||||
// video::SMaterial mat = m_LoadedMesh->getMaterial(materialIndex);
|
||||
// video::SMaterial mat = m_LoadedMesh->getMaterial(
|
||||
// materialIndex
|
||||
// );
|
||||
// mat.UseMipMaps = false;
|
||||
// mat.setFlag(video::EMF_BILINEAR_FILTER, false);
|
||||
// mat.setFlag(video::EMF_TRILINEAR_FILTER, false);
|
||||
|
||||
// below would require patching Irrlicht:
|
||||
// GLint filteringMipMaps = GL_NEAREST_MIPMAP_NEAREST
|
||||
// // above is used by glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filteringMipMaps);
|
||||
// // above is used by glTexParameteri(GL_TEXTURE_2D,
|
||||
// // GL_TEXTURE_MIN_FILTER,
|
||||
// // filteringMipMaps);
|
||||
}
|
||||
}
|
||||
} else
|
||||
|
@ -461,9 +527,12 @@ void Engine::setAnimationFPS(u32 animationFPS)
|
|||
{
|
||||
if (this->m_LoadedMesh != nullptr) {
|
||||
if (animationFPS > 0) this->isPlaying = true;
|
||||
// Do NOT call playAnimation, otherwise infinite recursion occurs (it calls setAnimationFPS).
|
||||
// Do NOT call playAnimation, otherwise infinite recursion occurs
|
||||
// (it calls setAnimationFPS).
|
||||
this->m_LoadedMesh->setAnimationSpeed(animationFPS);
|
||||
this->m_UserInterface->playbackFPSEditBox->setText(Utility::toWstring(this->m_LoadedMesh->getAnimationSpeed()).c_str());
|
||||
this->m_UserInterface->playbackFPSEditBox->setText(
|
||||
Utility::toWstring(this->m_LoadedMesh->getAnimationSpeed()).c_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -471,8 +540,10 @@ void Engine::incrementAnimationFPS(irr::f32 by)
|
|||
{
|
||||
if (this->m_LoadedMesh != nullptr) {
|
||||
if (by < 0) {
|
||||
if (this->m_LoadedMesh->getAnimationSpeed() + by >= 0.999999f) // don't use this->animationFPS(), because its unsigned!
|
||||
this->setAnimationFPS(this->m_LoadedMesh->getAnimationSpeed() + by);
|
||||
if (this->m_LoadedMesh->getAnimationSpeed() + by >= 0.999999f)
|
||||
// don't use this->animationFPS() above--its unsigned!
|
||||
this->setAnimationFPS(this->m_LoadedMesh->getAnimationSpeed()
|
||||
+ by);
|
||||
else
|
||||
this->setAnimationFPS(1);
|
||||
}
|
||||
|
@ -514,7 +585,9 @@ void Engine::run()
|
|||
if (this->m_LoadedMesh != nullptr) {
|
||||
if (isPlaying) {
|
||||
this->m_LoadedMesh->setLoopMode(true);
|
||||
this->m_UserInterface->playbackSetFrameEditBox->setText(Utility::toWstring(this->m_LoadedMesh->getFrameNr()).c_str());
|
||||
this->m_UserInterface->playbackSetFrameEditBox->setText(
|
||||
Utility::toWstring(this->m_LoadedMesh->getFrameNr()).c_str()
|
||||
);
|
||||
} else {
|
||||
this->m_LoadedMesh->setLoopMode(false);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@ EventHandler::~EventHandler()
|
|||
delete m_EventReceivers;
|
||||
}
|
||||
|
||||
bool EventHandler::addEventReceiver(EventReceiverType type, IEventReceiver* receiver)
|
||||
bool EventHandler::addEventReceiver(EventReceiverType type,
|
||||
IEventReceiver* receiver)
|
||||
{
|
||||
m_EventReceivers->insert(make_pair(type, receiver));
|
||||
return true;
|
||||
|
|
|
@ -43,22 +43,46 @@ void UserInterface::setupUserInterface()
|
|||
|
||||
// View Menu
|
||||
viewMenu = menu->getSubMenu(1);
|
||||
viewWireframeIdx = viewMenu->addItem(L"Wireframe", UIC_VIEW_WIREFRAME, true, false, this->m_WireframeDisplay, true);
|
||||
viewLightingIdx = viewMenu->addItem(L"Lighting", UIC_VIEW_LIGHTING, true, false, this->m_Lighting, true);
|
||||
viewAxisWidgetIdx = viewMenu->addItem(L"Origin Axis Widget", UIC_VIEW_AXIS_WIDGET, true, false, true, true);
|
||||
viewTargetIdx = viewMenu->addItem(L"Camera Target", UIC_VIEW_TARGET, true, false, false, true);
|
||||
viewWireframeIdx = viewMenu->addItem(L"Wireframe",
|
||||
UIC_VIEW_WIREFRAME, true,
|
||||
false, this->m_WireframeDisplay, true);
|
||||
viewLightingIdx = viewMenu->addItem(L"Lighting",
|
||||
UIC_VIEW_LIGHTING, true,
|
||||
false, this->m_Lighting, true);
|
||||
viewAxisWidgetIdx = viewMenu->addItem(L"Origin Axis Widget",
|
||||
UIC_VIEW_AXIS_WIDGET, true, false,
|
||||
true, true);
|
||||
viewTargetIdx = viewMenu->addItem(L"Camera Target",
|
||||
UIC_VIEW_TARGET, true, false,
|
||||
false, true);
|
||||
|
||||
viewTextureInterpolationIdx = viewMenu->addItem(L"Texture Interpolation Ctrl i", UIC_VIEW_TEXTURE_INTERPOLATION, true, false, this->m_TextureInterpolation, true);
|
||||
viewTextureInterpolationIdx = viewMenu->addItem(L"Texture Interpolation Ctrl i",
|
||||
UIC_VIEW_TEXTURE_INTERPOLATION, true, false,
|
||||
this->m_TextureInterpolation, true);
|
||||
|
||||
viewYUpIdx = viewMenu->addItem(L"Y Up", UIC_VIEW_Y_UP, true, false, true, true);
|
||||
viewZUpIdx = viewMenu->addItem(L"Z Up", UIC_VIEW_Z_UP, true, false, false, true);
|
||||
viewMenu->addItem(L"Slower Ctrl Left", UIC_VIEW_SLOWER, true, false, false, false);
|
||||
viewMenu->addItem(L"Faster Ctrl Right", UIC_VIEW_FASTER, true, false, false, false);
|
||||
viewYUpIdx = viewMenu->addItem(L"Y Up",
|
||||
UIC_VIEW_Y_UP, true, false,
|
||||
true, true);
|
||||
viewZUpIdx = viewMenu->addItem(L"Z Up",
|
||||
UIC_VIEW_Z_UP, true, false,
|
||||
false, true);
|
||||
viewMenu->addItem(L"Slower Ctrl Left",
|
||||
UIC_VIEW_SLOWER, true, false,
|
||||
false, false);
|
||||
viewMenu->addItem(L"Faster Ctrl Right",
|
||||
UIC_VIEW_FASTER, true, false,
|
||||
false, false);
|
||||
|
||||
// Playback Control Window
|
||||
dimension2d<u32> windowSize = m_Engine->m_Driver->getScreenSize();
|
||||
playbackWindow = m_Gui->addWindow(
|
||||
rect<s32>(vector2d<s32>(windowSize.Width - 4 - 160, 28), dimension2d<s32>(160, 300)), false, L"Playback", nullptr, UIE_PLAYBACKWINDOW);
|
||||
rect<s32>(vector2d<s32>(windowSize.Width - 4 - 160, 28),
|
||||
dimension2d<s32>(160, 300)),
|
||||
false,
|
||||
L"Playback",
|
||||
nullptr,
|
||||
UIE_PLAYBACKWINDOW
|
||||
);
|
||||
playbackWindow->getCloseButton()->setVisible(false);
|
||||
s32 spacing_x = 4;
|
||||
s32 margin_y = 4;
|
||||
|
@ -67,7 +91,8 @@ void UserInterface::setupUserInterface()
|
|||
s32 size_y = 24;
|
||||
s32 y = 24;
|
||||
playbackStartStopButton = m_Gui->addButton(
|
||||
rect<s32>(vector2d<s32>(spacing_x, y), dimension2d<s32>(size_x, size_y)),
|
||||
rect<s32>(vector2d<s32>(spacing_x, y),
|
||||
dimension2d<s32>(size_x, size_y)),
|
||||
playbackWindow,
|
||||
UIE_PLAYBACKSTARTSTOPBUTTON,
|
||||
L"Start/Stop",
|
||||
|
@ -76,7 +101,8 @@ void UserInterface::setupUserInterface()
|
|||
y += size_y + spacing_y;
|
||||
playbackSetFrameEditBox = m_Gui->addEditBox(
|
||||
L"",
|
||||
rect<s32>(vector2d<s32>(spacing_x, y), dimension2d<s32>(size_x, size_y)),
|
||||
rect<s32>(vector2d<s32>(spacing_x, y),
|
||||
dimension2d<s32>(size_x, size_y)),
|
||||
true,
|
||||
playbackWindow,
|
||||
UIE_PLAYBACKSETFRAMEEDITBOX);
|
||||
|
@ -84,7 +110,8 @@ void UserInterface::setupUserInterface()
|
|||
|
||||
y += size_y + spacing_y;
|
||||
playbackIncreaseButton = m_Gui->addButton(
|
||||
rect<s32>(vector2d<s32>(spacing_x, y), dimension2d<s32>(size_x, size_y)),
|
||||
rect<s32>(vector2d<s32>(spacing_x, y),
|
||||
dimension2d<s32>(size_x, size_y)),
|
||||
playbackWindow,
|
||||
UIE_PLAYBACKINCREASEBUTTON,
|
||||
L"Faster",
|
||||
|
@ -92,7 +119,8 @@ void UserInterface::setupUserInterface()
|
|||
|
||||
y += size_y + spacing_y;
|
||||
playbackDecreaseButton = m_Gui->addButton(
|
||||
rect<s32>(vector2d<s32>(spacing_x, y), dimension2d<s32>(size_x, size_y)),
|
||||
rect<s32>(vector2d<s32>(spacing_x, y),
|
||||
dimension2d<s32>(size_x, size_y)),
|
||||
playbackWindow,
|
||||
UIE_PLAYBACKDECREASEBUTTON,
|
||||
L"Slower",
|
||||
|
@ -101,7 +129,8 @@ void UserInterface::setupUserInterface()
|
|||
y += size_y + spacing_y;
|
||||
playbackFPSEditBox = m_Gui->addEditBox(
|
||||
L"",
|
||||
rect<s32>(vector2d<s32>(spacing_x, y), dimension2d<s32>(size_x, size_y)),
|
||||
rect<s32>(vector2d<s32>(spacing_x, y),
|
||||
dimension2d<s32>(size_x, size_y)),
|
||||
true,
|
||||
playbackWindow,
|
||||
UIE_FPSEDITBOX);
|
||||
|
@ -110,7 +139,8 @@ void UserInterface::setupUserInterface()
|
|||
y += size_y + spacing_y;
|
||||
texturePathStaticText = m_Gui->addStaticText(
|
||||
L"Texture Path:",
|
||||
rect<s32>(vector2d<s32>(spacing_x, y), dimension2d<s32>(size_x, size_y)),
|
||||
rect<s32>(vector2d<s32>(spacing_x, y),
|
||||
dimension2d<s32>(size_x, size_y)),
|
||||
true,
|
||||
true,
|
||||
playbackWindow,
|
||||
|
@ -120,7 +150,8 @@ void UserInterface::setupUserInterface()
|
|||
y += size_y + spacing_y;
|
||||
texturePathEditBox = m_Gui->addEditBox(
|
||||
L"",
|
||||
rect<s32>(vector2d<s32>(spacing_x, y), dimension2d<s32>(size_x, size_y)),
|
||||
rect<s32>(vector2d<s32>(spacing_x, y),
|
||||
dimension2d<s32>(size_x, size_y)),
|
||||
true,
|
||||
playbackWindow,
|
||||
UIE_TEXTUREPATHEDITBOX);
|
||||
|
@ -129,7 +160,8 @@ void UserInterface::setupUserInterface()
|
|||
y += size_y + spacing_y;
|
||||
axisSizeStaticText = m_Gui->addStaticText(
|
||||
L"Axis Size:",
|
||||
rect<s32>(vector2d<s32>(spacing_x, y), dimension2d<s32>(size_x, size_y)),
|
||||
rect<s32>(vector2d<s32>(spacing_x, y)
|
||||
dimension2d<s32>(size_x, size_y)),
|
||||
true,
|
||||
true,
|
||||
playbackWindow,
|
||||
|
@ -139,7 +171,8 @@ void UserInterface::setupUserInterface()
|
|||
y += size_y + spacing_y;
|
||||
axisSizeEditBox = m_Gui->addEditBox(
|
||||
L"",
|
||||
rect<s32>(vector2d<s32>(spacing_x, y), dimension2d<s32>(size_x, size_y)),
|
||||
rect<s32>(vector2d<s32>(spacing_x, y),
|
||||
dimension2d<s32>(size_x, size_y)),
|
||||
true,
|
||||
playbackWindow,
|
||||
UIE_AXISSIZEEDITBOX);
|
||||
|
@ -175,7 +208,8 @@ void UserInterface::setupUserInterface()
|
|||
m_GuiFont->attach(m_GuiFontFace, 14);
|
||||
m_Gui->getSkin()->setFont(m_GuiFont);
|
||||
} else {
|
||||
std::wcerr << L"WARNING: Missing '" << m_Engine->m_FontPath << L"'" << endl;
|
||||
std::wcerr << L"WARNING: Missing '" << m_Engine->m_FontPath << L"'"
|
||||
<< endl;
|
||||
delete m_GuiFontFace;
|
||||
m_GuiFontFace = nullptr;
|
||||
if (m_GuiFont != nullptr) {
|
||||
|
@ -187,12 +221,14 @@ void UserInterface::setupUserInterface()
|
|||
|
||||
void UserInterface::displayLoadFileDialog()
|
||||
{
|
||||
m_Gui->addFileOpenDialog(L"Select file to load", true, nullptr, UIE_LOADFILEDIALOG);
|
||||
m_Gui->addFileOpenDialog(L"Select file to load",
|
||||
true, nullptr, UIE_LOADFILEDIALOG);
|
||||
}
|
||||
|
||||
void UserInterface::displayLoadTextureDialog()
|
||||
{
|
||||
m_Gui->addFileOpenDialog(L"Select file to load", true, nullptr, UIE_LOADTEXTUREDIALOG);
|
||||
m_Gui->addFileOpenDialog(L"Select file to load",
|
||||
true, nullptr, UIE_LOADTEXTUREDIALOG);
|
||||
}
|
||||
|
||||
void UserInterface::handleMenuItemPressed(IGUIContextMenu* menu)
|
||||
|
@ -224,12 +260,14 @@ void UserInterface::handleMenuItemPressed(IGUIContextMenu* menu)
|
|||
|
||||
case UIC_VIEW_WIREFRAME:
|
||||
m_WireframeDisplay = viewMenu->isItemChecked(viewWireframeIdx);
|
||||
m_Engine->setMeshDisplayMode(m_WireframeDisplay, m_Lighting, m_TextureInterpolation);
|
||||
m_Engine->setMeshDisplayMode(m_WireframeDisplay, m_Lighting,
|
||||
m_TextureInterpolation);
|
||||
break;
|
||||
|
||||
case UIC_VIEW_LIGHTING:
|
||||
m_Lighting = viewMenu->isItemChecked(viewLightingIdx);
|
||||
m_Engine->setMeshDisplayMode(m_WireframeDisplay, m_Lighting, m_TextureInterpolation);
|
||||
m_Engine->setMeshDisplayMode(m_WireframeDisplay, m_Lighting,
|
||||
m_TextureInterpolation);
|
||||
break;
|
||||
|
||||
case UIC_VIEW_TARGET:
|
||||
|
@ -247,8 +285,11 @@ void UserInterface::handleMenuItemPressed(IGUIContextMenu* menu)
|
|||
break;
|
||||
|
||||
case UIC_VIEW_TEXTURE_INTERPOLATION:
|
||||
m_TextureInterpolation = viewMenu->isItemChecked(viewTextureInterpolationIdx);
|
||||
m_Engine->setMeshDisplayMode(m_WireframeDisplay, m_Lighting, m_TextureInterpolation);
|
||||
m_TextureInterpolation = viewMenu->isItemChecked(
|
||||
viewTextureInterpolationIdx
|
||||
);
|
||||
m_Engine->setMeshDisplayMode(m_WireframeDisplay, m_Lighting,
|
||||
m_TextureInterpolation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -261,15 +302,21 @@ void UserInterface::snapWidgets()
|
|||
//newRect.LowerRightCorner.X = static_cast<s32>(size.Width);
|
||||
//newRect.LowerRightCorner.Y = static_cast<s32>(size.Height);
|
||||
rect<s32> prevRect = playbackWindow->getRelativePosition();
|
||||
newRect.UpperLeftCorner.X = static_cast<s32>(screenSize.Width) - prevRect.getWidth() - spacing_y;
|
||||
//debug() << "screen size: " << screenSize.Width << "x" << screenSize.Height;
|
||||
//debug() << " prevRect: "
|
||||
// << prevRect.UpperLeftCorner.X << "," << prevRect.UpperLeftCorner.Y << ","
|
||||
// << prevRect.LowerRightCorner.X << "," << prevRect.LowerRightCorner.Y
|
||||
// << " size=(" << prevRect.getWidth() << "," <<prevRect.getHeight() << ")" << endl;
|
||||
newRect.UpperLeftCorner.X = static_cast<s32>(screenSize.Width)
|
||||
- prevRect.getWidth() - spacing_y;
|
||||
// debug() << "screen size: " << screenSize.Width << "x" << screenSize.Height;
|
||||
// debug() << " prevRect: "
|
||||
// << prevRect.UpperLeftCorner.X << ","
|
||||
// << prevRect.UpperLeftCorner.Y << ","
|
||||
// << prevRect.LowerRightCorner.X << ","
|
||||
// << prevRect.LowerRightCorner.Y
|
||||
// << " size=(" << prevRect.getWidth() << ","
|
||||
// << prevRect.getHeight() << ")" << endl;
|
||||
newRect.UpperLeftCorner.Y = prevRect.UpperLeftCorner.Y;
|
||||
newRect.LowerRightCorner.X = newRect.UpperLeftCorner.X + prevRect.getWidth();
|
||||
newRect.LowerRightCorner.Y = newRect.UpperLeftCorner.Y + prevRect.getHeight();
|
||||
newRect.LowerRightCorner.X = newRect.UpperLeftCorner.X
|
||||
+ prevRect.getWidth();
|
||||
newRect.LowerRightCorner.Y = newRect.UpperLeftCorner.Y
|
||||
+ prevRect.getHeight();
|
||||
playbackWindow->setRelativePosition(newRect);
|
||||
m_WindowSize.Width = m_Engine->m_Driver->getScreenSize().Width;
|
||||
m_WindowSize.Height = m_Engine->m_Driver->getScreenSize().Height;
|
||||
|
@ -315,17 +362,26 @@ bool UserInterface::loadNextTexture(int direction)
|
|||
this->m_Engine->m_NextPath = L"";
|
||||
std::wstring basePath = L".";
|
||||
if (this->m_Engine->m_PreviousPath.length() > 0) {
|
||||
std::wstring lastName = Utility::basename(this->m_Engine->m_PreviousPath);
|
||||
std::wstring lastDirPath = Utility::parentOfPath(this->m_Engine->m_PreviousPath);
|
||||
std::wstring lastName = Utility::basename(
|
||||
this->m_Engine->m_PreviousPath
|
||||
);
|
||||
std::wstring lastDirPath = Utility::parentOfPath(
|
||||
this->m_Engine->m_PreviousPath
|
||||
);
|
||||
std::wstring parentPath = Utility::parentOfPath(lastDirPath);
|
||||
std::wstring dirSeparator = Utility::delimiter(this->m_Engine->m_PreviousPath);
|
||||
std::wstring dirSeparator = Utility::delimiter(
|
||||
this->m_Engine->m_PreviousPath
|
||||
);
|
||||
std::wstring texturesPath = parentPath + dirSeparator + L"textures";
|
||||
std::wstring tryTexPath = texturesPath + dirSeparator + Utility::withoutExtension(lastName) + L".png";
|
||||
std::wstring tryTexPath = texturesPath + dirSeparator
|
||||
+ Utility::withoutExtension(lastName)
|
||||
+ L".png";
|
||||
if (direction == 0 && Utility::isFile(tryTexPath)) {
|
||||
this->m_Engine->m_NextPath = tryTexPath;
|
||||
this->m_Engine->loadTexture(this->m_Engine->m_NextPath);
|
||||
} else {
|
||||
tryTexPath = lastDirPath + dirSeparator + Utility::withoutExtension(lastName) + L".png";
|
||||
tryTexPath = lastDirPath + dirSeparator
|
||||
+ Utility::withoutExtension(lastName) + L".png";
|
||||
if (direction == 0 && Utility::isFile(tryTexPath)) {
|
||||
this->m_Engine->m_NextPath = tryTexPath;
|
||||
ret = this->m_Engine->loadTexture(this->m_Engine->m_NextPath);
|
||||
|
@ -333,9 +389,9 @@ bool UserInterface::loadNextTexture(int direction)
|
|||
std::wstring path = texturesPath;
|
||||
|
||||
if (!fs::is_directory(fs::status(path)))
|
||||
path = lastDirPath; // cycle textures in model's directory instead
|
||||
path = lastDirPath; // cycle in model's directory instead
|
||||
|
||||
fs::directory_iterator end_itr; // default construction yields past-the-end
|
||||
fs::directory_iterator end_itr; // default yields past-the-end
|
||||
|
||||
std::wstring nextPath = L"";
|
||||
std::wstring retroPath = L"";
|
||||
|
@ -347,19 +403,25 @@ bool UserInterface::loadNextTexture(int direction)
|
|||
if (fs::is_directory(fs::status(path))) {
|
||||
if (this->m_Engine->m_PrevTexturePath.length() == 0) {
|
||||
if (this->m_Engine->m_PreviousPath.length() > 0) {
|
||||
//debug() << "tryPath..." << endl;
|
||||
tryPath = texturesPath + dirSeparator + Utility::withoutExtension(Utility::basename(this->m_Engine->m_PreviousPath)) + L".png";
|
||||
// debug() << "tryPath 1a " << Utility::toString(tryPath) << "..." << endl;
|
||||
tryPath = texturesPath + dirSeparator
|
||||
+ Utility::withoutExtension(
|
||||
Utility::basename(
|
||||
this->m_Engine->m_PreviousPath
|
||||
)
|
||||
)
|
||||
+ L".png";
|
||||
tryPath = Utility::toWstring(Utility::toString(tryPath));
|
||||
// debug() << "tryPath 1b " << Utility::toString(tryPath) << "..." << endl;
|
||||
// tryPath = texturesPath + dirSeparator + Utility::basename(this->m_Engine->m_PreviousPath) + L".png";
|
||||
if (!Utility::isFile(tryPath)) {
|
||||
tryPath = texturesPath + dirSeparator + Utility::withoutExtension(Utility::basename(this->m_Engine->m_PreviousPath)) + L".jpg";
|
||||
// debug() << "tryPath 2a " << Utility::toString(tryPath) << "..." << endl;
|
||||
tryPath = Utility::toWstring(Utility::toString(tryPath));
|
||||
// tryPath = Utility::toWstring(Utility::toString(L"debug1")); // ../iconv/loop.c:457: internal_utf8_loop_single: Assertion `inptr - (state->__count & 7)' failed.
|
||||
// debug() << "tryPath 2b " << Utility::toString(tryPath) << "..." << endl;
|
||||
// tryPath = texturesPath + dirSeparator + Utility::basename(this->m_Engine->m_PreviousPath) + L".jpg";
|
||||
tryPath = texturesPath + dirSeparator
|
||||
+ Utility::withoutExtension(
|
||||
Utility::basename(
|
||||
this->m_Engine->m_PreviousPath
|
||||
)
|
||||
)
|
||||
+ L".jpg";
|
||||
tryPath = Utility::toWstring(
|
||||
Utility::toString(tryPath)
|
||||
);
|
||||
if (Utility::isFile(tryPath)) {
|
||||
nextPath = tryPath;
|
||||
found = true;
|
||||
|
@ -372,14 +434,17 @@ bool UserInterface::loadNextTexture(int direction)
|
|||
}
|
||||
}
|
||||
}
|
||||
// debug() << "tryPath: " << Utility::toString(tryPath) << endl;
|
||||
// debug() << "nextPath: " << Utility::toString(nextPath) << endl;
|
||||
for (const auto& itr : fs::directory_iterator(path)) {
|
||||
std::wstring ext = Utility::extensionOf(itr.path().wstring()); // no dot!
|
||||
std::wstring ext = Utility::extensionOf(
|
||||
itr.path().wstring()
|
||||
); // no dot!
|
||||
if (!is_directory(itr.status())
|
||||
&& std::find(m_Engine->textureExtensions.begin(), m_Engine->textureExtensions.end(), ext) != m_Engine->textureExtensions.end()) {
|
||||
// cycle through files (go to next after m_PrevTexturePath
|
||||
// if any previously loaded, otherwise first)
|
||||
&& std::find(m_Engine->textureExtensions.begin(),
|
||||
m_Engine->textureExtensions.end(), ext)
|
||||
!= m_Engine->textureExtensions.end()) {
|
||||
// cycle through files (go to next after
|
||||
// m_PrevTexturePath if any previously loaded,
|
||||
// otherwise first)
|
||||
if (nextPath.length() == 0)
|
||||
nextPath = itr.path().wstring();
|
||||
lastPath = itr.path().wstring();
|
||||
|
@ -388,14 +453,15 @@ bool UserInterface::loadNextTexture(int direction)
|
|||
nextPath = itr.path().wstring();
|
||||
break;
|
||||
}
|
||||
if (itr.path().wstring() == this->m_Engine->m_PrevTexturePath)
|
||||
if (itr.path().wstring()
|
||||
== this->m_Engine->m_PrevTexturePath)
|
||||
found = true;
|
||||
if (!found)
|
||||
retroPath = itr.path().wstring();
|
||||
}
|
||||
}
|
||||
if (retroPath.length() == 0)
|
||||
retroPath = lastPath; // previous is last if at beginning
|
||||
retroPath = lastPath; // previous is last if at start
|
||||
if (direction < 0)
|
||||
nextPath = retroPath;
|
||||
if (nextPath.length() > 0) {
|
||||
|
@ -417,7 +483,8 @@ bool UserInterface::OnEvent(const SEvent& event)
|
|||
if (event.EventType == EET_USER_EVENT) {
|
||||
// debug() << "EET_USER_EVENT..." << endl;
|
||||
if (event.UserEvent.UserData1 == UEI_WINDOWSIZECHANGED) {
|
||||
if ((m_WindowSize.Width != m_Engine->m_Driver->getScreenSize().Width) || (m_WindowSize.Height != m_Engine->m_Driver->getScreenSize().Height)) {
|
||||
if ((m_WindowSize.Width != m_Engine->m_Driver->getScreenSize().Width)
|
||||
|| (m_WindowSize.Height != m_Engine->m_Driver->getScreenSize().Height)) {
|
||||
snapWidgets();
|
||||
}
|
||||
handled = true;
|
||||
|
@ -467,7 +534,9 @@ bool UserInterface::OnEvent(const SEvent& event)
|
|||
case UIE_PLAYBACKSETFRAMEEDITBOX:
|
||||
if (ge->EventType == EGET_EDITBOX_ENTER) {
|
||||
if (this->m_Engine->m_LoadedMesh != nullptr) {
|
||||
this->m_Engine->m_LoadedMesh->setCurrentFrame(Utility::toF32(this->playbackSetFrameEditBox->getText()));
|
||||
this->m_Engine->m_LoadedMesh->setCurrentFrame(
|
||||
Utility::toF32(this->playbackSetFrameEditBox->getText())
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -481,13 +550,17 @@ bool UserInterface::OnEvent(const SEvent& event)
|
|||
case UIE_FPSEDITBOX:
|
||||
if (ge->EventType == EGET_EDITBOX_ENTER) {
|
||||
if (this->m_Engine->m_LoadedMesh != nullptr) {
|
||||
this->m_Engine->m_LoadedMesh->setAnimationSpeed(Utility::toF32(this->playbackFPSEditBox->getText()));
|
||||
this->m_Engine->m_LoadedMesh->setAnimationSpeed(
|
||||
Utility::toF32(this->playbackFPSEditBox->getText())
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case UIE_AXISSIZEEDITBOX:
|
||||
if (ge->EventType == EGET_EDITBOX_ENTER) {
|
||||
this->m_Engine->axisLength = Utility::toF32(this->axisSizeEditBox->getText());
|
||||
this->m_Engine->axisLength = Utility::toF32(
|
||||
this->axisSizeEditBox->getText()
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -500,21 +573,30 @@ bool UserInterface::OnEvent(const SEvent& event)
|
|||
handled = true; // set to false below if not handled
|
||||
if (event.KeyInput.PressedDown && !m_Engine->KeyIsDown[event.KeyInput.Key]) {
|
||||
if (event.KeyInput.Key == irr::KEY_F5) {
|
||||
if (m_Engine->KeyIsDown[irr::KEY_LSHIFT] || m_Engine->KeyIsDown[irr::KEY_RSHIFT]) {
|
||||
if (m_Engine->KeyIsDown[irr::KEY_LSHIFT]
|
||||
|| m_Engine->KeyIsDown[irr::KEY_RSHIFT]) {
|
||||
m_Engine->reloadTexture();
|
||||
}
|
||||
else
|
||||
m_Engine->reloadMesh();
|
||||
} else if (event.KeyInput.Key == irr::KEY_F3) {
|
||||
if (m_Engine->KeyIsDown[irr::KEY_LSHIFT] || m_Engine->KeyIsDown[irr::KEY_RSHIFT]) {
|
||||
if (m_Engine->KeyIsDown[irr::KEY_LSHIFT]
|
||||
|| m_Engine->KeyIsDown[irr::KEY_RSHIFT]) {
|
||||
loadNextTexture(-1);
|
||||
debug() << " - back" << endl;
|
||||
}
|
||||
else
|
||||
loadNextTexture(1);
|
||||
} else if (event.KeyInput.Key == irr::KEY_KEY_I) {
|
||||
if (m_Engine->KeyIsDown[irr::KEY_LCONTROL] || m_Engine->KeyIsDown[irr::KEY_RCONTROL]) {
|
||||
// IGUIContextMenu* textureInterpolationElement = dynamic_cast<IGUIContextMenu*>(viewMenu->getElementFromId(UIC_VIEW_TEXTURE_INTERPOLATION));
|
||||
if (m_Engine->KeyIsDown[irr::KEY_LCONTROL]
|
||||
|| m_Engine->KeyIsDown[irr::KEY_RCONTROL]) {
|
||||
// IGUIContextMenu* textureInterpolationElement = (
|
||||
// dynamic_cast<IGUIContextMenu*>(
|
||||
// viewMenu->getElementFromId(
|
||||
// UIC_VIEW_TEXTURE_INTERPOLATION
|
||||
// )
|
||||
// );
|
||||
// )
|
||||
// m_TextureInterpolation = textureInterpolationElement->isItemChecked(UIC_VIEW_TEXTURE_INTERPOLATION);
|
||||
m_TextureInterpolation = m_TextureInterpolation ? false : true;
|
||||
// doesn't work: m_TextureInterpolation = viewMenu->isItemChecked(UIC_VIEW_TEXTURE_INTERPOLATION);
|
||||
|
@ -524,13 +606,15 @@ bool UserInterface::OnEvent(const SEvent& event)
|
|||
else
|
||||
handled = false;
|
||||
} else if (event.KeyInput.Key == irr::KEY_RIGHT) {
|
||||
if (m_Engine->KeyIsDown[irr::KEY_LCONTROL] || m_Engine->KeyIsDown[irr::KEY_RCONTROL]) {
|
||||
if (m_Engine->KeyIsDown[irr::KEY_LCONTROL]
|
||||
|| m_Engine->KeyIsDown[irr::KEY_RCONTROL]) {
|
||||
m_Engine->incrementAnimationFPS(5);
|
||||
}
|
||||
else
|
||||
handled = false;
|
||||
} else if (event.KeyInput.Key == irr::KEY_LEFT) {
|
||||
if (m_Engine->KeyIsDown[irr::KEY_LCONTROL] || m_Engine->KeyIsDown[irr::KEY_RCONTROL]) {
|
||||
if (m_Engine->KeyIsDown[irr::KEY_LCONTROL]
|
||||
|| m_Engine->KeyIsDown[irr::KEY_RCONTROL]) {
|
||||
m_Engine->incrementAnimationFPS(-5);
|
||||
}
|
||||
else
|
||||
|
@ -541,15 +625,27 @@ bool UserInterface::OnEvent(const SEvent& event)
|
|||
if (this->m_Engine->m_LoadedMesh != nullptr) {
|
||||
if (m_Engine->isPlaying)
|
||||
m_Engine->toggleAnimation();
|
||||
this->m_Engine->m_LoadedMesh->setCurrentFrame(round(this->m_Engine->m_LoadedMesh->getFrameNr()) - 1);
|
||||
this->playbackSetFrameEditBox->setText(Utility::toWstring(this->m_Engine->m_LoadedMesh->getFrameNr()).c_str());
|
||||
this->m_Engine->m_LoadedMesh->setCurrentFrame(
|
||||
round(this->m_Engine->m_LoadedMesh->getFrameNr()) - 1
|
||||
);
|
||||
this->playbackSetFrameEditBox->setText(
|
||||
Utility::toWstring(
|
||||
this->m_Engine->m_LoadedMesh->getFrameNr()
|
||||
).c_str()
|
||||
);
|
||||
}
|
||||
} else if (event.KeyInput.Key == irr::KEY_RIGHT) {
|
||||
if (this->m_Engine->m_LoadedMesh != nullptr) {
|
||||
if (m_Engine->isPlaying)
|
||||
m_Engine->toggleAnimation();
|
||||
this->m_Engine->m_LoadedMesh->setCurrentFrame(round(this->m_Engine->m_LoadedMesh->getFrameNr()) + 1);
|
||||
this->playbackSetFrameEditBox->setText(Utility::toWstring(this->m_Engine->m_LoadedMesh->getFrameNr()).c_str());
|
||||
this->m_Engine->m_LoadedMesh->setCurrentFrame(
|
||||
round(this->m_Engine->m_LoadedMesh->getFrameNr()) + 1
|
||||
);
|
||||
this->playbackSetFrameEditBox->setText(
|
||||
Utility::toWstring(
|
||||
this->m_Engine->m_LoadedMesh->getFrameNr()
|
||||
).c_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
78
Utility.cpp
78
Utility.cpp
|
@ -34,14 +34,25 @@ void Utility::dumpMeshInfoToConsole(IAnimatedMeshSceneNode* node)
|
|||
// Dump some information about the mesh to the console
|
||||
IAnimatedMesh* mesh = node->getMesh();
|
||||
|
||||
debug() << "[MESH]: # of frames : " << mesh->getFrameCount() << endl;
|
||||
debug() << "[MESH]: # of materials : " << node->getMaterialCount() << endl;
|
||||
debug() << "[MESH]: # of frames : " << mesh->getFrameCount()
|
||||
<< endl;
|
||||
debug() << "[MESH]: # of materials : " << node->getMaterialCount()
|
||||
<< endl;
|
||||
for (irr::u32 matIndex = 0; matIndex < node->getMaterialCount(); matIndex++) {
|
||||
debug() << "[MESH]: Material # " << matIndex << endl;
|
||||
const SMaterial& material = node->getMaterial(matIndex);
|
||||
debug() << "[MESH]: Diffuse Color : A" << material.DiffuseColor.getAlpha() << " R" << material.DiffuseColor.getRed() << " G" << material.DiffuseColor.getGreen() << " B" << material.DiffuseColor.getBlue() << endl;
|
||||
debug() << "[MESH]: Specular Color : A" << material.SpecularColor.getAlpha() << " R" << material.SpecularColor.getRed() << " G" << material.SpecularColor.getGreen() << " B" << material.SpecularColor.getBlue() << endl;
|
||||
debug() << "[MESH]: Specular Shininess : " << material.Shininess << endl;
|
||||
debug() << "[MESH]: Diffuse Color : A"
|
||||
<< material.DiffuseColor.getAlpha()
|
||||
<< " R" << material.DiffuseColor.getRed()
|
||||
<< " G" << material.DiffuseColor.getGreen()
|
||||
<< " B" << material.DiffuseColor.getBlue() << endl;
|
||||
debug() << "[MESH]: Specular Color : A"
|
||||
<< material.SpecularColor.getAlpha()
|
||||
<< " R" << material.SpecularColor.getRed()
|
||||
<< " G" << material.SpecularColor.getGreen()
|
||||
<< " B" << material.SpecularColor.getBlue() << endl;
|
||||
debug() << "[MESH]: Specular Shininess : "
|
||||
<< material.Shininess << endl;
|
||||
|
||||
// check for # textures
|
||||
int textures = 0;
|
||||
|
@ -154,23 +165,33 @@ std::string Utility::toString(const std::wstring& ws)
|
|||
}
|
||||
return ret;
|
||||
|
||||
//below sometimes results in "internal_utf8_loop_single: Assertion `inptr - bytebuf > (state->__count & 7)' failed." on the converter.out call:
|
||||
//if (ws.length() > 0) {
|
||||
// // convert to w_string using locale: see Phillipp on <https://stackoverflow.com/questions/4804298/how-to-convert-wstring-into-string>
|
||||
// std::setlocale(LC_ALL, "");
|
||||
// const std::locale locale("");
|
||||
// typedef std::codecvt<wchar_t, char, std::mbstate_t> converter_type;
|
||||
// const converter_type& converter = std::use_facet<converter_type>(locale);
|
||||
// std::vector<char> to(ws.length() * converter.max_length());
|
||||
// std::mbstate_t state;
|
||||
// const wchar_t* from_next = nullptr;
|
||||
// char* to_next = nullptr;
|
||||
// const converter_type::result result = converter.out(state, ws.data(), ws.data() + ws.length(), from_next, &to[0], &to[0] + to.size(), to_next);
|
||||
// if (result == converter_type::ok or result == converter_type::noconv) {
|
||||
// const std::string s(&to[0], to_next);
|
||||
// //std::cout <<"std::string = "<<s<<std::endl;
|
||||
// ret = s;
|
||||
// }
|
||||
// below sometimes results in "internal_utf8_loop_single: Assertion
|
||||
// `inptr - bytebuf > (state->__count & 7)' failed."
|
||||
// on the converter.out call:
|
||||
// if (ws.length() > 0) {
|
||||
// // convert to w_string using locale: see Phillipp on
|
||||
// // <https://stackoverflow.com/questions/4804298/how-to-convert-wstring-into-string>
|
||||
// std::setlocale(LC_ALL, "");
|
||||
// const std::locale locale("");
|
||||
// typedef std::codecvt<wchar_t, char, std::mbstate_t> converter_type;
|
||||
// const converter_type& converter = std::use_facet<converter_type>(locale);
|
||||
// std::vector<char> to(ws.length() * converter.max_length());
|
||||
// std::mbstate_t state;
|
||||
// const wchar_t* from_next = nullptr;
|
||||
// char* to_next = nullptr;
|
||||
// const converter_type::result result = converter.out(
|
||||
// state, ws.data(),
|
||||
// ws.data() + ws.length(),
|
||||
// from_next,
|
||||
// &to[0],
|
||||
// &to[0] + to.size(),
|
||||
// to_next
|
||||
// );
|
||||
// if (result == converter_type::ok or result == converter_type::noconv) {
|
||||
// const std::string s(&to[0], to_next);
|
||||
// // std::cout <<"std::string = "<<s<<std::endl;
|
||||
// ret = s;
|
||||
// }
|
||||
//return ret;
|
||||
}
|
||||
|
||||
|
@ -240,9 +261,10 @@ std::string Utility::toString(irr::f32 val)
|
|||
return std::to_string(val);
|
||||
}
|
||||
|
||||
//don't do late instantiation (see header file)
|
||||
//template<typename T>
|
||||
//bool Utility::equalsApprox(T f1, T f2)
|
||||
//{
|
||||
// return abs(f2-f1) < .00000001; // TODO: kEpsilon? (see also <https://en.wikipedia.org/wiki/Machine_epsilon#How_to_determine_machine_epsilon>)
|
||||
//}
|
||||
// don't do late instantiation (see header file)
|
||||
// template<typename T>
|
||||
// bool Utility::equalsApprox(T f1, T f2)
|
||||
// {
|
||||
// return abs(f2-f1) < .00000001; // TODO: kEpsilon? (see also
|
||||
// // <https://en.wikipedia.org/wiki/Machine_epsilon#How_to_determine_machine_epsilon>)
|
||||
// }
|
||||
|
|
71
View.cpp
71
View.cpp
|
@ -91,7 +91,7 @@ View::View(Engine* engine)
|
|||
m_LastMousePosition = new vector2d<int>();
|
||||
m_RotMouse = false;
|
||||
|
||||
//m_Pitch = PI;
|
||||
// m_Pitch = PI;
|
||||
|
||||
// Initial camera values: see Engine::setupScene
|
||||
|
||||
|
@ -154,11 +154,15 @@ bool View::zUp()
|
|||
bool View::OnEvent(const SEvent& event)
|
||||
{
|
||||
// If it's not a mouse event or window resize event, return
|
||||
if (event.EventType != EET_MOUSE_INPUT_EVENT && !(event.EventType == EET_USER_EVENT && event.UserEvent.UserData1 == UEI_WINDOWSIZECHANGED))
|
||||
if (event.EventType != EET_MOUSE_INPUT_EVENT
|
||||
&& !(event.EventType == EET_USER_EVENT
|
||||
&& event.UserEvent.UserData1 == UEI_WINDOWSIZECHANGED)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Handle window resize
|
||||
if (event.EventType == EET_USER_EVENT && event.UserEvent.UserData1 == UEI_WINDOWSIZECHANGED) {
|
||||
if (event.EventType == EET_USER_EVENT
|
||||
&& event.UserEvent.UserData1 == UEI_WINDOWSIZECHANGED) {
|
||||
dimension2d<u32> windowSize = m_Engine->m_Driver->getScreenSize();
|
||||
f32 aspectRatio = static_cast<f32>(windowSize.Width) / static_cast<f32>(windowSize.Height);
|
||||
// debug() << "Setting aspect to: " << aspectRatio << endl;
|
||||
|
@ -176,7 +180,7 @@ bool View::OnEvent(const SEvent& event)
|
|||
m_RotMouse = false;
|
||||
} else if (mouseEvent->Event == EMIE_MOUSE_WHEEL) {
|
||||
// Zoom camera.
|
||||
//debug() << "Wheel=" << mouseEvent->Wheel; // -1 or 1
|
||||
// debug() << "Wheel=" << mouseEvent->Wheel; // -1 or 1
|
||||
vector3df offsetVec3(
|
||||
m_Engine->m_CamPos.X - m_Engine->m_CamTarget.X,
|
||||
m_Engine->m_CamPos.Y - m_Engine->m_CamTarget.Y,
|
||||
|
@ -185,29 +189,33 @@ bool View::OnEvent(const SEvent& event)
|
|||
f32 distanceDelta = mouseEvent->Wheel * -1 * (offsetVec3.getLength() / 10);
|
||||
ICameraSceneNode* camera = m_Engine->m_Scene->getActiveCamera();
|
||||
f32 distanceFactor = distanceDelta / Utility::distance(m_Engine->m_CamPos, m_Engine->m_CamTarget);
|
||||
////m_Engine->m_CamPos.interpolate(m_Engine->m_CamPos, m_Engine->m_CamTarget, distanceFactor);
|
||||
////offsetVec3.normalize();
|
||||
//m_Engine->m_CamPos.X -= offsetVec3.X * distanceFactor;
|
||||
//m_Engine->m_CamPos.Y -= offsetVec3.Y * distanceFactor;
|
||||
//m_Engine->m_CamPos.Z -= offsetVec3.Z * distanceFactor;
|
||||
//m_Engine->m_CamTarget.X -= offsetVec3.X * distanceFactor;
|
||||
//m_Engine->m_CamTarget.Y -= offsetVec3.Y * distanceFactor;
|
||||
//m_Engine->m_CamTarget.Z -= offsetVec3.Z * distanceFactor;
|
||||
//// m_Engine->m_CamPos.interpolate(m_Engine->m_CamPos, m_Engine->m_CamTarget, distanceFactor);
|
||||
//// offsetVec3.normalize();
|
||||
// m_Engine->m_CamPos.X -= offsetVec3.X * distanceFactor;
|
||||
// m_Engine->m_CamPos.Y -= offsetVec3.Y * distanceFactor;
|
||||
// m_Engine->m_CamPos.Z -= offsetVec3.Z * distanceFactor;
|
||||
// m_Engine->m_CamTarget.X -= offsetVec3.X * distanceFactor;
|
||||
// m_Engine->m_CamTarget.Y -= offsetVec3.Y * distanceFactor;
|
||||
// m_Engine->m_CamTarget.Z -= offsetVec3.Z * distanceFactor;
|
||||
|
||||
offsetVec3 = vector3df(
|
||||
m_Engine->m_CamPos.X - m_Engine->m_CamTarget.X,
|
||||
m_Engine->m_CamPos.Y - m_Engine->m_CamTarget.Y,
|
||||
m_Engine->m_CamPos.Z - m_Engine->m_CamTarget.Z);
|
||||
//camera->setPosition(m_Engine->m_CamPos);
|
||||
//camera->setTarget(m_Engine->m_CamTarget);
|
||||
m_Engine->m_CamPos.Z - m_Engine->m_CamTarget.Z
|
||||
);
|
||||
// camera->setPosition(m_Engine->m_CamPos);
|
||||
// camera->setTarget(m_Engine->m_CamTarget);
|
||||
|
||||
//m_Yaw = atan2(offsetVec3.X, offsetVec3.Z);
|
||||
//m_Pitch = asin(offsetVec3.Y);
|
||||
// m_Yaw = atan2(offsetVec3.X, offsetVec3.Z);
|
||||
// m_Pitch = asin(offsetVec3.Y);
|
||||
|
||||
//m_CameraDistance = Utility::distance(m_Engine->m_CamPos, m_Engine->m_CamTarget);
|
||||
// m_CameraDistance = Utility::distance(m_Engine->m_CamPos, m_Engine->m_CamTarget);
|
||||
m_CameraDistance += distanceDelta;
|
||||
setNewCameraPosition();
|
||||
debug() << "m_CamPos: " << m_Engine->m_CamPos.X << "," << m_Engine->m_CamPos.Y << " m_CamTarget: " << m_Engine->m_CamTarget.X << "," << m_Engine->m_CamTarget.Y << endl;
|
||||
debug() << "m_CamPos: " << m_Engine->m_CamPos.X
|
||||
<< "," << m_Engine->m_CamPos.Y
|
||||
<< " m_CamTarget: " << m_Engine->m_CamTarget.X
|
||||
<< "," << m_Engine->m_CamTarget.Y << endl;
|
||||
} else if (m_RotMouse) {
|
||||
// debug() << "Yaw: " << radToDeg(m_Yaw) << " Pitch: " << radToDeg(m_Pitch) << endl;
|
||||
int dx = mouseEvent->X - m_LastMousePosition->X;
|
||||
|
@ -250,11 +258,11 @@ bool View::OnEvent(const SEvent& event)
|
|||
dirVec3.rotateYZBy(camRot.X);
|
||||
dirVec3.rotateXYBy(camRot.Y);
|
||||
}
|
||||
// vector3df dirVec3 = rotationVec3.rotationToDirection(forwards);
|
||||
// // move up and down, not in and out:
|
||||
// float z = dirVec3.Z;
|
||||
// dirVec3.Z = dirVec3.Y;
|
||||
// dirVec3.Z = z;
|
||||
// vector3df dirVec3 = rotationVec3.rotationToDirection(forwards);
|
||||
// // move up and down, not in and out:
|
||||
// float z = dirVec3.Z;
|
||||
// dirVec3.Z = dirVec3.Y;
|
||||
// dirVec3.Z = z;
|
||||
dirVec3.X *= yDelta;
|
||||
dirVec3.Y *= yDelta;
|
||||
dirVec3.Z *= yDelta;
|
||||
|
@ -267,11 +275,11 @@ bool View::OnEvent(const SEvent& event)
|
|||
|
||||
|
||||
if (m_zUp) {
|
||||
//m_Engine->m_CamPos.Z += yDelta;
|
||||
//m_Engine->m_CamTarget.Z += yDelta;
|
||||
// m_Engine->m_CamPos.Z += yDelta;
|
||||
// m_Engine->m_CamTarget.Z += yDelta;
|
||||
} else {
|
||||
//m_Engine->m_CamPos.Y += yDelta;
|
||||
//m_Engine->m_CamTarget.Y += yDelta;
|
||||
// m_Engine->m_CamPos.Y += yDelta;
|
||||
// m_Engine->m_CamTarget.Y += yDelta;
|
||||
}
|
||||
// camera->setPosition(m_Engine->m_CamPos);
|
||||
// camera->setTarget(m_Engine->m_CamTarget);
|
||||
|
@ -286,7 +294,8 @@ bool View::OnEvent(const SEvent& event)
|
|||
// m_Yaw = atan2(offsetVec3.X, offsetVec3.Z);
|
||||
// m_Pitch = asin(offsetVec3.Y);
|
||||
setNewCameraPosition();
|
||||
debug() << "AFTER Yaw: " << radToDeg(m_YawFromTarget)<< " Pitch: " << radToDeg(m_PitchFromTarget) << endl;
|
||||
debug() << "AFTER Yaw: " << radToDeg(m_YawFromTarget)
|
||||
<< " Pitch: " << radToDeg(m_PitchFromTarget) << endl;
|
||||
|
||||
float xDelta = (dx / static_cast<float>(m_Engine->m_Driver->getScreenSize().Width/2)) * m_CameraDistance;
|
||||
|
||||
|
@ -311,7 +320,8 @@ bool View::OnEvent(const SEvent& event)
|
|||
sidewaysVec3.Z = xDelta * sin(sidewaysAngle);
|
||||
sidewaysVec3.Y = 0;
|
||||
}
|
||||
debug() << "sidewaysAngle:" << sidewaysAngle << " zUp:" << ((m_zUp)?"true":"false") << endl;
|
||||
debug() << "sidewaysAngle:" << sidewaysAngle
|
||||
<< " zUp:" << ((m_zUp)?"true":"false") << endl;
|
||||
m_Engine->m_CamPos.X += sidewaysVec3.X;
|
||||
m_Engine->m_CamPos.Y += sidewaysVec3.Y;
|
||||
m_Engine->m_CamPos.Z += sidewaysVec3.Z;
|
||||
|
@ -341,6 +351,5 @@ bool View::OnEvent(const SEvent& event)
|
|||
setNewCameraPosition();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
7
main.cpp
7
main.cpp
|
@ -13,7 +13,8 @@ wchar_t* getWideCharString(char* str);
|
|||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine, int nCmdShow)
|
||||
#else
|
||||
int main(int argc, char** argv)
|
||||
#endif
|
||||
|
@ -58,7 +59,9 @@ int main(int argc, char** argv)
|
|||
|
||||
wchar_t* getWideCharString(char* str)
|
||||
{
|
||||
wchar_t* dest = static_cast<wchar_t*>(malloc(sizeof(wchar_t) * (strlen(str) + 1)));
|
||||
wchar_t* dest = static_cast<wchar_t*>(
|
||||
malloc(sizeof(wchar_t) * (strlen(str) + 1))
|
||||
);
|
||||
|
||||
size_t resultSize = mbstowcs(nullptr, str, strlen(str));
|
||||
mbstowcs(dest, str, strlen(str));
|
||||
|
|
Loading…
Reference in New Issue