move playback on resize (snapWidgets), coding style ./etc/quality.sh

master
poikilos 2019-04-11 04:31:04 -04:00
parent d2aaced734
commit a3118c12e5
18 changed files with 653 additions and 526 deletions

118
.clang-format Normal file
View File

@ -0,0 +1,118 @@
---
Language: Cpp
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: WebKit
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...

3
.gitignore vendored
View File

@ -35,4 +35,7 @@ Makefile*
# QtCtreator CMake
CMakeLists.txt.user
# dev generated files
nohup.out
*.tmp

View File

@ -3,8 +3,8 @@
using std::cout;
using std::endl;
using std::ostream;
using std::wcout;
using std::wcerr;
using std::wcout;
ostream& debug()
{

View File

@ -3,12 +3,12 @@
#include "Engine.h"
#include "UserInterface.h"
#include "View.h"
#include "Utility.h"
#include "View.h"
using std::cout;
using std::wcerr;
using std::endl;
using std::wcerr;
using std::wstring;
using std::wstringstream;
@ -99,10 +99,9 @@ void Engine::drawBackground()
void Engine::checkResize()
{
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;
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;
// Send custom event
IEventReceiver* eventReceiver = m_Device->getEventReceiver();
@ -182,8 +181,7 @@ Engine::Engine()
m_AxisFont = new CGUITTFont(m_UserInterface->getGUIEnvironment());
m_AxisFont->attach(m_AxisFontFace, 14);
m_AxisFont->AntiAlias = false;
}
else {
} else {
delete m_AxisFontFace;
m_AxisFontFace = nullptr;
}
@ -192,9 +190,8 @@ Engine::Engine()
m_LoadedMesh = nullptr;
// Store actual window size
m_WindowSize = new dimension2d<u32>();
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;
// (do not calculate m_Yaw and m_Pitch here--see View constructor)
@ -204,7 +201,6 @@ Engine::Engine()
Engine::~Engine()
{
m_Device->drop();
delete m_WindowSize;
delete m_AxisFont;
delete m_AxisFontFace;
}
@ -223,8 +219,7 @@ void Engine::loadMesh( const wstring &fileName )
Utility::dumpMeshInfoToConsole(m_LoadedMesh);
if (Utility::toLower(Utility::extensionOf(fileName)) == L"3ds") {
m_View->setZUp(true);
}
else {
} else {
m_View->setZUp(false);
}
if (m_LoadedMesh != nullptr) {
@ -234,7 +229,7 @@ void Engine::loadMesh( const wstring &fileName )
if (m_View->zUp()) {
float oldDist = m_CamPos.getDistanceFrom(m_CamTarget);
float newDist = oldDist;
if (oldDist != 0) {
if (Utility::equalsApprox(oldDist, 0.0f)) {
vector3d<float> center = box.getCenter();
vector3df edges[8];
box.getEdges(edges);
@ -251,7 +246,8 @@ void Engine::loadMesh( const wstring &fileName )
newDist = 0;
for (int i = 0; i < 8; i++) {
float tryDist = center.getDistanceFrom(edges[i]);
if (tryDist>newDist) newDist = tryDist;
if (tryDist > newDist)
newDist = tryDist;
}
newDist *= 2; // so camera doesn't touch model
if (!Utility::equalsApprox<float>(newDist, oldDist)) {
@ -306,19 +302,15 @@ bool Engine::loadTexture(const wstring &fileName)
void Engine::setMeshDisplayMode(bool wireframe, bool lighting, bool textureInterpolation)
{
if (m_LoadedMesh != nullptr) {
for( u32 materialIndex = 0; materialIndex < m_LoadedMesh->getMaterialCount(); materialIndex ++ )
{
for (u32 materialIndex = 0; materialIndex < m_LoadedMesh->getMaterialCount(); materialIndex++) {
// Set Wireframe display
m_LoadedMesh->getMaterial(materialIndex).Wireframe = wireframe;
// Set Lighting
if( ! lighting )
{
if (!lighting) {
m_LoadedMesh->getMaterial(materialIndex).Lighting = false;
m_LoadedMesh->getMaterial(materialIndex).EmissiveColor = SColor(255, 255, 255, 255);
}
else
{
} else {
m_LoadedMesh->getMaterial(materialIndex).Lighting = true;
m_LoadedMesh->getMaterial(materialIndex).EmissiveColor = SColor(255, 0, 0, 0);
}
@ -327,8 +319,7 @@ void Engine::setMeshDisplayMode( bool wireframe, bool lighting, bool textureInte
if (textureInterpolation) {
m_LoadedMesh->setMaterialFlag(video::EMF_BILINEAR_FILTER, true);
m_LoadedMesh->setMaterialFlag(video::EMF_TRILINEAR_FILTER, true);
}
else {
} else {
m_LoadedMesh->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
m_LoadedMesh->setMaterialFlag(video::EMF_TRILINEAR_FILTER, false);
//m_LoadedMesh->setMaterialFlag(video::E_ALPHA_SOURCE, true);
@ -344,8 +335,8 @@ void Engine::setMeshDisplayMode( bool wireframe, bool lighting, bool textureInte
// // above is used by glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filteringMipMaps);
}
}
}
else debug() << "WARNING in setMeshDisplayMode: No mesh is loaded " << endl;
} else
debug() << "WARNING in setMeshDisplayMode: No mesh is loaded " << endl;
}
bool Engine::isAnimating()
@ -360,7 +351,8 @@ void Engine::playAnimation()
}
if (!this->isAnimating()) {
if (this->m_LoadedMesh != nullptr) {
if (this->prevFPS < 1) this->prevFPS = 5;
if (this->prevFPS < 1)
this->prevFPS = 5;
this->m_LoadedMesh->setAnimationSpeed(this->prevFPS);
}
}
@ -384,12 +376,10 @@ void Engine::toggleAnimation()
if (this->isAnimating()) {
this->pauseAnimation();
debug() << "paused " << this->animationFPS() << "fps" << endl;
}
else {
} else {
this->playAnimation();
debug() << "unpaused " << this->animationFPS() << "fps" << endl;
}
}
void Engine::setAnimationFPS(u32 animationFPS)
@ -424,8 +414,7 @@ void Engine::run()
ITimer* timer = m_Device->getTimer();
// Run the Device with fps frames/sec
while( m_Device->run() && m_RunEngine )
{
while (m_Device->run() && m_RunEngine) {
u32 startTime = timer->getRealTime();
checkResize();
@ -433,8 +422,7 @@ void Engine::run()
if (isPlaying) {
this->m_LoadedMesh->setLoopMode(true);
this->m_UserInterface->playbackSetFrameEditBox->setText(Utility::toWstring(this->m_LoadedMesh->getFrameNr()).c_str());
}
else {
} else {
this->m_LoadedMesh->setLoopMode(false);
}
}

View File

@ -5,24 +5,22 @@
class UserInterface;
class View;
#include <string>
#include <sstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <irrlicht/irrlicht.h>
#include "EventHandler.h"
#include "extlib/CGUITTFont.h"
#include <irrlicht/irrlicht.h>
enum SceneItemID
{
enum SceneItemID {
SIID_LIGHT = 1,
SIID_CAMERA = 2,
SIID_MODEL = 3
};
class Engine
{
class Engine {
friend class UserInterface;
friend class View;
@ -36,7 +34,7 @@ private:
irr::gui::CGUITTFont* m_AxisFont;
irr::gui::CGUITTFace* m_AxisFontFace;
irr::core::dimension2d<irr::u32> *m_WindowSize;
irr::core::dimension2d<irr::u32> m_WindowSize;
bool m_RunEngine;
@ -71,7 +69,6 @@ public:
std::wstring m_PreviousPath;
std::wstring m_PrevTexturePath;
Engine();
~Engine();

View File

@ -1,8 +1,8 @@
#include "EventHandler.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <Utility.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
using namespace irr;
using namespace irr::video;
@ -29,23 +29,17 @@ bool EventHandler::addEventReceiver( EventReceiverType type, IEventReceiver *rec
// IEventReceiver
bool EventHandler::OnEvent(const SEvent& event)
{
if (event.EventType == EET_GUI_EVENT)
{
if (event.EventType == EET_GUI_EVENT) {
// Pass to User Interface Handler
map<EventReceiverType, IEventReceiver*>::iterator iter = m_EventReceivers->find(ERT_USERINTERFACE);
iter->second->OnEvent(event);
}
else if (event.EventType == EET_MOUSE_INPUT_EVENT)
{
} else if (event.EventType == EET_MOUSE_INPUT_EVENT) {
map<EventReceiverType, IEventReceiver*>::iterator iter = m_EventReceivers->find(ERT_3DVIEW);
iter->second->OnEvent(event);
}
else if (event.EventType == EET_KEY_INPUT_EVENT) {
} else if (event.EventType == EET_KEY_INPUT_EVENT) {
map<EventReceiverType, IEventReceiver*>::iterator iter = m_EventReceivers->find(ERT_USERINTERFACE);
iter->second->OnEvent(event);
}
else if (event.EventType == EET_USER_EVENT)
{
} else if (event.EventType == EET_USER_EVENT) {
if (event.UserEvent.UserData1 == UEI_WINDOWSIZECHANGED) {
// Window resize handling - send to all subscribers
map<EventReceiverType, IEventReceiver*>::iterator iter;

View File

@ -5,30 +5,28 @@
#include <map>
#include <utility>
#include <irrlicht/irrlicht.h>
#include "Debug.h"
#include <irrlicht/irrlicht.h>
using std::cout;
using std::endl;
using std::map;
using std::make_pair;
using std::map;
enum EventReceiverType
{
enum EventReceiverType {
ERT_USERINTERFACE = 1,
ERT_3DVIEW = 2
};
enum UserEventIdentifier
{
enum UserEventIdentifier {
UEI_WINDOWSIZECHANGED = 1
};
class EventHandler : public irr::IEventReceiver
{
class EventHandler : public irr::IEventReceiver {
private:
irr::IrrlichtDevice* m_Device;
map<EventReceiverType, IEventReceiver*>* m_EventReceivers;
public:
EventHandler(irr::IrrlichtDevice* device);
~EventHandler();

View File

@ -1,7 +1,7 @@
#include "UserInterface.h"
#include <string>
#include <iostream>
#include <algorithm>
#include <iostream>
#include <string>
// NOTE: to use filesystem, you must also include the fs library such
// as via the `-lstdc++fs` linker option -- see b3view.pro
@ -51,7 +51,7 @@ void UserInterface::setupUserInterface()
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 spacing_y = 4;
spacing_y = 4;
s32 size_x = playbackWindow->getClientRect().getWidth() - 8;
s32 size_y = 24;
s32 y = 24;
@ -60,24 +60,21 @@ void UserInterface::setupUserInterface()
playbackWindow,
UIE_PLAYBACKSTARTSTOPBUTTON,
L"Start/Stop",
nullptr
);
nullptr);
y += size_y + spacing_y;
playbackIncreaseButton = m_Gui->addButton(
rect<s32>(vector2d<s32>(spacing_x, y), dimension2d<s32>(size_x, size_y)),
playbackWindow,
UIE_PLAYBACKINCREASEBUTTON,
L"Faster",
nullptr
);
nullptr);
y += size_y + spacing_y;
playbackDecreaseButton = m_Gui->addButton(
rect<s32>(vector2d<s32>(spacing_x, y), dimension2d<s32>(size_x, size_y)),
playbackWindow,
UIE_PLAYBACKDECREASEBUTTON,
L"Slower",
nullptr
);
nullptr);
y += size_y + spacing_y;
playbackSetFrameEditBox = m_Gui->addEditBox(
@ -85,8 +82,7 @@ void UserInterface::setupUserInterface()
rect<s32>(vector2d<s32>(spacing_x, y), dimension2d<s32>(size_x, size_y)),
true,
playbackWindow,
UIE_PLAYBACKSETFRAMEEDITBOX
);
UIE_PLAYBACKSETFRAMEEDITBOX);
y += size_y + spacing_y;
texturePathStaticText = m_Gui->addStaticText(
@ -96,21 +92,19 @@ void UserInterface::setupUserInterface()
true,
playbackWindow,
UIE_TEXTUREPATHSTATICTEXT,
false
);
false);
y += size_y + spacing_y;
texturePathEditBox = m_Gui->addEditBox(
L"",
rect<s32>(vector2d<s32>(spacing_x, y), dimension2d<s32>(size_x, size_y)),
true,
playbackWindow,
UIE_TEXTUREPATHEDITBOX
);
UIE_TEXTUREPATHEDITBOX);
// Set Font for UI Elements
m_GuiFontFace = new CGUITTFace();
// irrString defines stringc as string<c8>
// if (QFile(fontPath).exists()) {}
// if (QFile(fontPath).exists()) {
if (!Utility::isFile(m_Engine->m_FontPath)) {
m_Engine->m_FontPath = L"C:\\Windows\\Fonts\\calibrib.ttf";
}
@ -134,8 +128,7 @@ void UserInterface::setupUserInterface()
m_GuiFont = new CGUITTFont(m_Gui);
m_GuiFont->attach(m_GuiFontFace, 14);
m_Gui->getSkin()->setFont(m_GuiFont);
}
else {
} else {
std::wcerr << L"WARNING: Missing '" << m_Engine->m_FontPath << L"'" << endl;
delete m_GuiFontFace;
m_GuiFontFace = nullptr;
@ -162,8 +155,7 @@ void UserInterface::handleMenuItemPressed( IGUIContextMenu *menu )
if (selected > -1) {
s32 id = menu->getItemCommandId(static_cast<u32>(selected));
switch( id )
{
switch (id) {
case UIC_FILE_LOAD:
displayLoadFileDialog();
break;
@ -190,10 +182,29 @@ void UserInterface::handleMenuItemPressed( IGUIContextMenu *menu )
m_TextureInterpolation = viewMenu->isItemChecked(INDEX_VIEW_TEXTURE_INTERPOLATION);
m_Engine->setMeshDisplayMode(m_WireframeDisplay, m_Lighting, m_TextureInterpolation);
break;
}
}
}
void UserInterface::snapWidgets()
{
dimension2d<u32> screenSize = m_Engine->m_Driver->getScreenSize();
rect<s32> newRect;
//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.Y = prevRect.UpperLeftCorner.Y;
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;
}
// PUBLIC
@ -245,14 +256,12 @@ bool UserInterface::loadNextTexture(int direction)
if (direction == 0 && Utility::isFile(tryTexPath)) {
this->m_Engine->m_NextPath = tryTexPath;
this->m_Engine->loadTexture(this->m_Engine->m_NextPath);
}
else {
} else {
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);
}
else {
} else {
std::wstring path = texturesPath;
if (!fs::is_directory(fs::status(path)))
@ -289,8 +298,7 @@ bool UserInterface::loadNextTexture(int direction)
found = true;
force = true;
}
}
else {
} else {
nextPath = tryPath;
found = true;
force = true;
@ -305,14 +313,18 @@ bool UserInterface::loadNextTexture(int direction)
&& 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();
if (nextPath.length() == 0)
nextPath = itr.path().wstring();
lastPath = itr.path().wstring();
if (found && direction > 0) {
if (!force) nextPath = itr.path().wstring();
if (!force)
nextPath = itr.path().wstring();
break;
}
if (itr.path().wstring() == this->m_Engine->m_PrevTexturePath) found = true;
if (!found) retroPath = itr.path().wstring();
if (itr.path().wstring() == this->m_Engine->m_PrevTexturePath)
found = true;
if (!found)
retroPath = itr.path().wstring();
}
}
if (retroPath.length() == 0)
@ -325,8 +337,8 @@ bool UserInterface::loadNextTexture(int direction)
}
}
}
}
else debug() << "Can't cycle texture since no file was opened" << endl;
} else
debug() << "Can't cycle texture since no file was opened" << endl;
return ret;
}
@ -334,55 +346,53 @@ bool UserInterface::loadNextTexture(int direction)
bool UserInterface::OnEvent(const SEvent& event)
{
// Events arriving here should be destined for us
if (event.EventType == EET_KEY_INPUT_EVENT) {
if (event.EventType == EET_USER_EVENT) {
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)) {
snapWidgets();
}
}
return true;
} else if (event.EventType == EET_KEY_INPUT_EVENT) {
if (event.KeyInput.PressedDown && !m_Engine->KeyIsDown[event.KeyInput.Key]) {
if (event.KeyInput.Key == irr::KEY_F5) {
m_Engine->reloadMesh();
}
else if (event.KeyInput.Key == irr::KEY_KEY_T) {
} else if (event.KeyInput.Key == irr::KEY_KEY_T) {
loadNextTexture(1);
}
else if (event.KeyInput.Key == irr::KEY_KEY_E) {
} else if (event.KeyInput.Key == irr::KEY_KEY_E) {
loadNextTexture(-1);
}
else if (event.KeyInput.Key == irr::KEY_KEY_R) {
} else if (event.KeyInput.Key == irr::KEY_KEY_R) {
m_Engine->reloadTexture();
}
else if (event.KeyInput.Key == irr::KEY_KEY_Z) {
} else if (event.KeyInput.Key == irr::KEY_KEY_Z) {
m_Engine->setZUp(true);
}
else if (event.KeyInput.Key == irr::KEY_KEY_Y) {
} else if (event.KeyInput.Key == irr::KEY_KEY_Y) {
m_Engine->setZUp(false);
}
else if (event.KeyInput.Key == irr::KEY_KEY_X) {
} else if (event.KeyInput.Key == irr::KEY_KEY_X) {
// 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);
m_Engine->setMeshDisplayMode(m_WireframeDisplay, m_Lighting, m_TextureInterpolation);
viewMenu->setItemChecked(INDEX_VIEW_TEXTURE_INTERPOLATION, m_TextureInterpolation);
}
else if (event.KeyInput.Char == L'+' || event.KeyInput.Char == L'=') {
} else if (event.KeyInput.Char == L'+' || event.KeyInput.Char == L'=') {
m_Engine->setAnimationFPS(m_Engine->animationFPS() + 5);
}
else if (event.KeyInput.Char == L'-') {
} else if (event.KeyInput.Char == L'-') {
if (m_Engine->animationFPS() > 0) {
m_Engine->setAnimationFPS(m_Engine->animationFPS() - 5);
}
}
else if (event.KeyInput.Char == L' ') {
} else if (event.KeyInput.Char == L' ') {
m_Engine->toggleAnimation();
}
else if (event.KeyInput.Key == irr::KEY_LEFT) {
} else if (event.KeyInput.Key == irr::KEY_LEFT) {
if (this->m_Engine->m_LoadedMesh != nullptr) {
if (m_Engine->isPlaying) m_Engine->toggleAnimation();
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());
}
}
else if (event.KeyInput.Key == irr::KEY_RIGHT) {
} else if (event.KeyInput.Key == irr::KEY_RIGHT) {
if (this->m_Engine->m_LoadedMesh != nullptr) {
if (m_Engine->isPlaying) m_Engine->toggleAnimation();
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());
}
@ -392,12 +402,9 @@ bool UserInterface::OnEvent( const SEvent &event )
m_Engine->KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return true;
}
else if (event.EventType == EET_MOUSE_INPUT_EVENT)
{
} else if (event.EventType == EET_MOUSE_INPUT_EVENT) {
// TODO: improve this copypasta
switch ( event.MouseInput.Event)
{
switch (event.MouseInput.Event) {
case EMIE_LMOUSE_LEFT_UP:
if (m_Engine->LMouseState == 2) {
m_Engine->LMouseState = 3;
@ -422,14 +429,12 @@ bool UserInterface::OnEvent( const SEvent &event )
}
break;
}
}
else if (!(event.EventType == EET_GUI_EVENT))
} else if (!(event.EventType == EET_GUI_EVENT))
return false;
const SEvent::SGUIEvent* ge = &(event.GUIEvent);
switch( ge->Caller->getID() )
{
switch (ge->Caller->getID()) {
case UIE_FILEMENU:
case UIE_VIEWMENU:
// call handler for all menu related actions
@ -437,16 +442,14 @@ bool UserInterface::OnEvent( const SEvent &event )
break;
case UIE_LOADFILEDIALOG:
if( ge->EventType == EGET_FILE_SELECTED )
{
if (ge->EventType == EGET_FILE_SELECTED) {
IGUIFileOpenDialog* fileOpenDialog = static_cast<IGUIFileOpenDialog*>(ge->Caller);
m_Engine->loadMesh(fileOpenDialog->getFileName());
}
break;
case UIE_LOADTEXTUREDIALOG:
if( ge->EventType == EGET_FILE_SELECTED )
{
if (ge->EventType == EGET_FILE_SELECTED) {
IGUIFileOpenDialog* fileOpenDialog = static_cast<IGUIFileOpenDialog*>(ge->Caller);
m_Engine->loadTexture(fileOpenDialog->getFileName());
}

View File

@ -1,14 +1,13 @@
#ifndef USERINTERFACE_H
#define USERINTERFACE_H
#include <irrlicht/irrlicht.h>
#include "extlib/CGUITTFont.h"
#include <irrlicht/irrlicht.h>
// Forward declaration of class Engine
class Engine;
enum UserInterfaceElements
{
enum UserInterfaceElements {
UIE_FILEMENU = 1003,
UIE_LOADFILEDIALOG = 1100,
// UIE_LOADBUTTON = 1101,
@ -25,8 +24,7 @@ enum UserInterfaceElements
UIE_TEXTUREPATHEDITBOX = 3006
};
enum UserInterfaceCommands
{
enum UserInterfaceCommands {
UIC_FILE_LOAD = 1000,
UIC_FILE_QUIT = 1001,
UIC_FILE_LOAD_TEXTURE = 1002,
@ -35,9 +33,9 @@ enum UserInterfaceCommands
UIC_VIEW_TEXTURE_INTERPOLATION = 2003
};
class UserInterface : public irr::IEventReceiver
{
class UserInterface : public irr::IEventReceiver {
private:
irr::s32 spacing_y;
Engine* m_Engine;
irr::gui::IGUIEnvironment* m_Gui;
irr::gui::CGUITTFont* m_GuiFont;
@ -52,6 +50,7 @@ private:
bool m_Lighting;
bool m_TextureInterpolation;
irr::gui::IGUIWindow* playbackWindow;
irr::core::dimension2d<irr::u32> m_WindowSize; // previous size
public:
irr::gui::IGUIContextMenu* menu;
irr::gui::IGUIContextMenu* fileMenu;
@ -66,6 +65,7 @@ public:
irr::u32 INDEX_VIEW_WIREFRAME_MESH;
irr::u32 INDEX_VIEW_LIGHTING;
void snapWidgets();
UserInterface(Engine* device);
~UserInterface();

View File

@ -1,13 +1,13 @@
#include "Utility.h"
#include <string>
#include <iostream>
#include <algorithm>
#include <clocale>
#include <locale>
#include <vector>
#include <cmath>
#include <cwctype> // #include <cwtype>
#include <algorithm>
#include <iostream>
#include <locale>
#include <sstream>
#include <string>
#include <vector>
#include "Debug.h"
@ -16,7 +16,6 @@ using namespace irr::scene;
using namespace irr::video;
using namespace std;
void Utility::dumpVectorToConsole(const vector3df& vector)
{
debug() << "X: " << vector.X << " Y: " << vector.Y << " Z: " << vector.Z << endl;
@ -37,8 +36,7 @@ void Utility::dumpMeshInfoToConsole( IAnimatedMeshSceneNode *node )
debug() << "[MESH]: # of frames : " << mesh->getFrameCount() << endl;
debug() << "[MESH]: # of materials : " << node->getMaterialCount() << endl;
for( irr::u32 matIndex = 0; matIndex < node->getMaterialCount(); matIndex ++ )
{
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;
@ -48,7 +46,8 @@ void Utility::dumpMeshInfoToConsole( IAnimatedMeshSceneNode *node )
// check for # textures
int textures = 0;
for (irr::u32 ti = 0; ti < MATERIAL_MAX_TEXTURES; ti++)
if( material.getTexture( ti ) != nullptr ) textures ++;
if (material.getTexture(ti) != nullptr)
textures++;
debug() << "[MESH]: # of textures : " << textures << endl;
}
}
@ -58,8 +57,7 @@ std::wstring Utility::parentOfPath(const wstring &path)
std::wstring ret = L".";
if (path == L".") {
ret = L"..";
}
else {
} else {
std::wstring::size_type lastSlashPos = path.find_last_of(L"/");
if (lastSlashPos == std::wstring::npos) {
lastSlashPos = path.find_last_of(L"\\");
@ -94,9 +92,10 @@ wstring Utility::withoutExtension(const wstring &path)
lastSlashPos = path.find_last_of(L"\\");
}
if (lastSlashPos != std::wstring::npos) {
if (lastDotPos > lastSlashPos) ret = path.substr(0, lastDotPos);
}
else ret = path.substr(0, lastDotPos);
if (lastDotPos > lastSlashPos)
ret = path.substr(0, lastDotPos);
} else
ret = path.substr(0, lastDotPos);
}
return ret;
}
@ -111,9 +110,10 @@ wstring Utility::extensionOf(const wstring &path)
lastSlashPos = path.find_last_of(L"\\");
}
if (lastSlashPos != std::wstring::npos) {
if (lastDotPos > lastSlashPos) ret = path.substr(lastDotPos + 1);
}
else ret = path.substr(lastDotPos + 1);
if (lastDotPos > lastSlashPos)
ret = path.substr(lastDotPos + 1);
} else
ret = path.substr(lastDotPos + 1);
}
return ret;
}
@ -124,8 +124,7 @@ wstring Utility::delimiter(const wstring &path)
std::wstring::size_type lastSlashPos = path.find_last_of(L"/");
if (lastSlashPos == std::wstring::npos) {
// ret = L"/";
}
else {
} else {
std::wstring::size_type lastSlashPos = path.find_last_of(L"\\");
if (lastSlashPos != std::wstring::npos) {
ret = L"\\";
@ -134,7 +133,8 @@ wstring Utility::delimiter(const wstring &path)
return ret;
}
bool Utility::isFile(const std::string& name) {
bool Utility::isFile(const std::string& name)
{
if (FILE* file = fopen(name.c_str(), "r")) {
fclose(file);
return true;
@ -143,7 +143,8 @@ bool Utility::isFile(const std::string& name) {
}
}
std::string Utility::toString(const std::wstring& ws) {
std::string Utility::toString(const std::wstring& ws)
{
std::string ret;
if (ws.length() > 0) {
// std::string str = "Hello";
@ -170,7 +171,6 @@ std::string Utility::toString(const std::wstring& ws) {
// //std::cout <<"std::string = "<<s<<std::endl;
// ret = s;
// }
// }
//return ret;
}
@ -218,7 +218,8 @@ irr::f32 Utility::toF32(wstring val)
return ret;
}
bool Utility::isFile(const std::wstring& name) {
bool Utility::isFile(const std::wstring& name)
{
std::string name_s = toString(name);
if (FILE* file = fopen(name_s.c_str(), "r")) {
fclose(file);
@ -233,7 +234,6 @@ 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)

View File

@ -5,8 +5,7 @@
#include <irrlicht/irrlicht.h>
class Utility
{
class Utility {
public:
static void dumpVectorToConsole(const irr::core::vector3df& vector);
static void dumpMeshInfoToConsole(irr::scene::IAnimatedMeshSceneNode* node);
@ -28,7 +27,8 @@ public:
// compiler doesn't like template function when class is not a template--instantiate immediately
// see http://processors.wiki.ti.com/index.php/C%2B%2B_Template_Instantiation_Issues
template <typename T>
static bool equalsApprox(T f1, T f2) {
static bool 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>)
}
};

View File

@ -1,6 +1,6 @@
#include "View.h"
#include <iostream>
#include "Engine.h"
#include <iostream>
using namespace irr;
using namespace irr::core;
@ -18,8 +18,7 @@ void View::setNewCameraPosition(bool zUp)
if (zUp) {
camera->setUpVector(vector3df(0, 0, 1));
}
else {
} else {
camera->setUpVector(vector3df(0, 1, 0));
}
@ -47,8 +46,7 @@ void View::setNewCameraPosition(bool zUp)
newCameraPosition.Y = m_CameraDistance * cos(m_Pitch);
newCameraPosition.Z = m_CameraDistance * sin(m_Pitch);
yawMatrix.setRotationRadians(vector3df(0, 0, m_Yaw));
}
else {
} else {
newCameraPosition.X = 0;
newCameraPosition.Y = m_CameraDistance * sin(m_Pitch);
newCameraPosition.Z = m_CameraDistance * cos(m_Pitch);
@ -60,8 +58,7 @@ void View::setNewCameraPosition(bool zUp)
if (zUp) {
//camera->setUpVector(vector3df(0, 0, 1));
//newCameraPosition.Z = oldCamPos.Z;
}
else {
} else {
//camera->setUpVector(vector3df(0, 1, 0));
//newCameraPosition.Y = oldCamPos.Y;
}
@ -103,8 +100,7 @@ View::View( Engine *engine )
vector3df offsetVec3(
engine->m_CamPos.X - engine->m_CamTarget.X,
engine->m_CamPos.Y - engine->m_CamTarget.Y,
engine->m_CamPos.Z-engine->m_CamTarget.Z
);
engine->m_CamPos.Z - engine->m_CamTarget.Z);
m_CameraDistance = offsetVec3.getLength();
// NOTE: rotationToDirection converts a rotation to a vec3 direction
@ -154,38 +150,29 @@ bool View::OnEvent( const SEvent &event )
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;
m_Engine->m_Scene->getActiveCamera()->setAspectRatio(aspectRatio);
}
// Handle mouse event
const SEvent::SMouseInput* mouseEvent = &(event.MouseInput);
if( mouseEvent->Event == EMIE_MMOUSE_PRESSED_DOWN )
{
if (mouseEvent->Event == EMIE_MMOUSE_PRESSED_DOWN) {
m_RotMouse = true;
m_LastMousePosition->X = mouseEvent->X;
m_LastMousePosition->Y = mouseEvent->Y;
}
else if( mouseEvent->Event == EMIE_MMOUSE_LEFT_UP )
{
} else if (mouseEvent->Event == EMIE_MMOUSE_LEFT_UP) {
m_RotMouse = false;
}
else if( mouseEvent->Event == EMIE_MOUSE_WHEEL )
{
} else if (mouseEvent->Event == EMIE_MOUSE_WHEEL) {
f32 distanceDelta = mouseEvent->Wheel / 2.5f;
if (m_CameraDistance - distanceDelta > 0.1f)
m_CameraDistance -= distanceDelta;
setNewCameraPosition();
}
else if( m_RotMouse )
{
} else if (m_RotMouse) {
int dx = mouseEvent->X - m_LastMousePosition->X;
int dy = mouseEvent->Y - m_LastMousePosition->Y;
@ -208,8 +195,7 @@ bool View::OnEvent( const SEvent &event )
forwards = vector3df(0, 1, 0);
dirVec3.rotateYZBy(camRot.X);
dirVec3.rotateXYBy(camRot.Z);
}
else {
} else {
camRot.Z = m_Pitch;
dirVec3.rotateYZBy(camRot.X);
dirVec3.rotateXYBy(camRot.Y);
@ -231,8 +217,7 @@ bool View::OnEvent( const SEvent &event )
if (m_zUp) {
//m_Engine->m_CamPos.Z += yDelta;
//m_Engine->m_CamTarget.Z += yDelta;
}
else {
} else {
//m_Engine->m_CamPos.Y += yDelta;
//m_Engine->m_CamTarget.Y += yDelta;
}
@ -241,15 +226,13 @@ bool View::OnEvent( const SEvent &event )
vector3df offsetVec3(
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
);
m_Engine->m_CamPos.Z - m_Engine->m_CamTarget.Z);
m_CameraDistance = offsetVec3.getLength();
m_Yaw = atan2(offsetVec3.X, offsetVec3.Z);
m_Pitch = asin(-offsetVec3.Y);
setNewCameraPosition();
}
else {
} else {
// Revolve camera around object.
// increments of 120 pixels * PI are equal to 180 deg (PI radians):
f32 pitchDelta = dy / 120.0f;
@ -259,8 +242,10 @@ bool View::OnEvent( const SEvent &event )
m_Pitch += pitchDelta;
float minPitch = -PI / 2.0f + PI / 1000.0f;
float maxPitch = PI / 2.0f - PI / 1000.0f;
if (m_Pitch < minPitch) m_Pitch = minPitch;
else if (m_Pitch > maxPitch) m_Pitch = maxPitch;
if (m_Pitch < minPitch)
m_Pitch = minPitch;
else if (m_Pitch > maxPitch)
m_Pitch = maxPitch;
// std::wcerr << "pitch = " << m_Pitch << endl;
m_Yaw += dx / 120.0f;

3
View.h
View File

@ -5,8 +5,7 @@
class Engine;
class View : public irr::IEventReceiver
{
class View : public irr::IEventReceiver {
private:
Engine* m_Engine;
irr::f32 m_Yaw, m_Pitch, m_CameraDistance;

2
etc/pushtmp.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
clang-format -style=file $1 > $2/$1

43
etc/quality.sh Executable file
View File

@ -0,0 +1,43 @@
#!/bin/sh
customDie() {
echo
echo "ERROR:"
echo "$1"
echo
echo
exit 1
}
project_dir_name=b3view
flag_file=b3view.pro
if [ ! -f $flag_file ]; then
if [ -f ../$flag_file ]; then
cd ..
fi
fi
if [ ! -f $flag_file ]; then
echo "ERROR: There was no $flag_file in working or parent directory."
exit 1
fi
echo "* rewriting .clang-format to avoid clang-format version issues..."
#rewriting avoids the following error:
#YAML:94:22: error: unknown key 'Delimiter'
# - Delimiter: pb
clang-format -style=WebKit -dump-config > .clang-format
dump_dest=/tmp/$project_dir_name
if [ -d "$dump_dest" ]; then
rm -Rf "$dump_dest" || customDie "Cannot remove old $dump_dest"
fi
mkdir "$dump_dest" || customDie "Cannot mkdir $dump_dest"
chmod +x ./etc/pushtmp.sh
echo "* writing $dump_dest using .clang-format..."
find -maxdepth 1 -name "*.cpp" -exec ./etc/pushtmp.sh {} "$dump_dest" \;
find -maxdepth 1 -name "*.h" -exec ./etc/pushtmp.sh {} "$dump_dest" \;
if [ -f "`command -v meld`" ]; then
meld `pwd` "$dump_dest"
else
echo "You do not have meld installed, so you'll have to diff"
echo "against manually to see style issues, such as:"
echo "diff -r \"`pwd`\" \"$dump_dest\""
fi
echo "Done."

View File

@ -1,6 +1,6 @@
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include "Engine.h"
@ -27,8 +27,7 @@ int main( int argc, char **argv )
args = CommandLineToArgvW(GetCommandLineW(), &argc);
argv = (char**)malloc(sizeof(char*) * argc);
for( int index = 0; index < argc; index ++ )
{
for (int index = 0; index < argc; index++) {
int argumentBufferLength = wcslen(args[index]) + 1;
argv[index] = (char*)malloc(sizeof(char) * argumentBufferLength);
sprintf_s(argv[index], argumentBufferLength, "%ws", args[index]);
@ -38,8 +37,7 @@ int main( int argc, char **argv )
#endif
Engine* engine = new Engine();
if( argc >= 2 )
{
if (argc >= 2) {
wchar_t* initialFileName = getWideCharString(argv[1]);
engine->loadMesh(wstring(initialFileName));
free(initialFileName);
@ -69,4 +67,3 @@ wchar_t * getWideCharString( char *str )
return dest;
}