Compare commits
No commits in common. "5f6608e1d83156a05d10bb4ca89238187ec63c0c" and "432bf9919cdcb79de553cab75e93c9cd674658c8" have entirely different histories.
5f6608e1d8
...
432bf9919c
|
@ -1,3 +0,0 @@
|
||||||
[submodule "extern/assimp/assimp"]
|
|
||||||
path = extern/assimp/assimp
|
|
||||||
url = https://github.com/assimp/assimp.git
|
|
200
CMakeLists.txt
200
CMakeLists.txt
|
@ -3,7 +3,7 @@
|
||||||
## ##
|
## ##
|
||||||
## Project for working with OpenGL and Qt6 widgets ##
|
## Project for working with OpenGL and Qt6 widgets ##
|
||||||
################################################################################
|
################################################################################
|
||||||
cmake_minimum_required(VERSION 3.2)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
project(
|
project(
|
||||||
#[[NAME]] Qtk
|
#[[NAME]] Qtk
|
||||||
|
@ -16,190 +16,72 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
set(CMAKE_AUTOUIC ON)
|
set(CMAKE_AUTOUIC ON)
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
set(CMAKE_AUTORCC ON)
|
set(CMAKE_AUTORCC ON)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
# Qtk build options
|
|
||||||
option(QTK_DEBUG "Enable debugger" ON)
|
|
||||||
option(BUILD_SHARED_LIBS "Build shared library" ON)
|
|
||||||
option(UPDATE_SUBMODULES "Update external project (assimp) git submodule" ON)
|
|
||||||
|
|
||||||
# Qt options
|
|
||||||
set(QT_DIR "$ENV{HOME}/Code/Clones/Qt/6.3.1/gcc_64/" CACHE PATH "Path to Qt6")
|
|
||||||
|
|
||||||
# Options for bringing your own assimp installation; Otherwise not needed
|
|
||||||
set(ASSIMP_DIR "" CACHE PATH "Path to local installation of assimp")
|
|
||||||
option(ASSIMP_NEW_INTERFACE "Use the assimp::assimp interface (WIN / OSX)" OFF)
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# External Libraries
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# For CLion builds, point CMAKE_PREFIX_PATH to Qt6 install directory
|
# For CLion builds, point CMAKE_PREFIX_PATH to Qt6 install directory
|
||||||
# + QtCreator will handle this for you if that is used instead
|
list(APPEND CMAKE_PREFIX_PATH $ENV{HOME}/Code/Clones/Qt/6.3.1/gcc_64/)
|
||||||
list(APPEND CMAKE_PREFIX_PATH "${QT_DIR}")
|
|
||||||
|
|
||||||
# Find Qt
|
|
||||||
find_package(Qt6 COMPONENTS OpenGLWidgets)
|
find_package(Qt6 COMPONENTS OpenGLWidgets)
|
||||||
if (NOT Qt6_FOUND)
|
if (NOT Qt6_FOUND)
|
||||||
message(SEND_ERROR "Unable to find Qt6 at CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
|
message(SEND_ERROR "Unable to find Qt6 at CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
|
||||||
message(FATAL_ERROR "Specify path to Qt6 with `cmake -DCMAKE_PREFIX_PATH=/path/to/Qt/6.x.x/gcc_64 -S /path/to/qtk -B /path/to/qtk/build && cmake --build /path/to/qtk/build -j $(nprocs)`")
|
message(FATAL_ERROR "Specify path to Qt6 with `cmake -DCMAKE_PREFIX_PATH=/path/to/Qt/6.x.x/gcc_64 -S /path/to/qtk -B /path/to/qtk/build && cmake --build /path/to/qtk/build -j $(nprocs)`")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (UPDATE_SUBMODULES)
|
|
||||||
include("${CMAKE_SOURCE_DIR}/cmake/include/git_submodule.cmake")
|
|
||||||
submodule_update(extern/assimp/assimp/)
|
|
||||||
add_subdirectory(extern/assimp/assimp)
|
|
||||||
else()
|
|
||||||
if (ASSIMP_DIR)
|
|
||||||
message(STATUS "Using custom ASSIMP_DIR: ${ASSIMP_DIR}")
|
|
||||||
list(APPEND CMAKE_PREFIX_PATH "${ASSIMP_DIR}")
|
|
||||||
endif()
|
|
||||||
find_package(assimp REQUIRED)
|
|
||||||
if (assimp_FOUND)
|
|
||||||
message(STATUS "Found assimp: ${assimp_DIR}")
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Could not find assimp at: ${CMAKE_PREFIX_PATH}")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Qtk
|
# External Libraries
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
set(PUBLIC_HEADERS
|
# https://github.com/assimp/assimp/commit/6ac8279977c3a54118551e549d77329497116f66
|
||||||
src/mainwidget.h
|
find_package(assimp REQUIRED)
|
||||||
src/abstractscene.h
|
option(ASSIMP_NEW_INTERFACE "Use assimp::assimp as target instead of assimp" OFF)
|
||||||
src/camera3d.h
|
|
||||||
src/mesh.h
|
|
||||||
src/meshrenderer.h
|
|
||||||
src/model.h
|
|
||||||
src/object.h
|
|
||||||
src/skybox.h
|
|
||||||
src/texture.h
|
|
||||||
src/transform3D.h
|
|
||||||
)
|
|
||||||
|
|
||||||
set(SOURCE_FILES
|
|
||||||
src/mainwidget.cpp
|
|
||||||
src/abstractscene.cpp
|
|
||||||
src/camera3d.cpp
|
|
||||||
src/input.cpp
|
|
||||||
src/input.h
|
|
||||||
src/mesh.cpp
|
|
||||||
src/meshrenderer.cpp
|
|
||||||
src/model.cpp
|
|
||||||
src/object.cpp
|
|
||||||
src/qtkapi.h
|
|
||||||
src/skybox.cpp
|
|
||||||
src/texture.cpp
|
|
||||||
src/transform3D.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
include(GenerateExportHeader)
|
include(GenerateExportHeader)
|
||||||
qt_add_library(qtk-widget STATIC ${PUBLIC_HEADERS} ${SOURCE_FILES})
|
|
||||||
target_include_directories(qtk-widget PRIVATE src/ app/)
|
|
||||||
generate_export_header(qtk-widget)
|
|
||||||
|
|
||||||
set_target_properties(qtk-widget PROPERTIES
|
|
||||||
PUBLIC_HEADER "${PUBLIC_HEADERS}"
|
|
||||||
VERSION ${PROJECT_VERSION}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(qtk-widget PUBLIC Qt6::OpenGLWidgets)
|
|
||||||
|
|
||||||
if ((UPDATE_SUBMODULES AND NOT ASSIMP_DIR) OR NOT ASSIMP_NEW_INTERFACE)
|
|
||||||
target_link_libraries(qtk-widget PRIVATE assimp)
|
|
||||||
elseif(ASSIMP_NEW_INTERFACE)
|
|
||||||
target_link_libraries(qtk-widget PRIVATE assimp::assimp)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(QTK_DEBUG)
|
|
||||||
target_compile_definitions(qtk-widget PUBLIC QTK_DEBUG)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
find_package(OpenGL REQUIRED)
|
|
||||||
target_link_libraries(qtk-widget PUBLIC OpenGL::GL)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Install files
|
|
||||||
install(TARGETS qtk-widget
|
|
||||||
# Associate qtk-widget target with qtk-export
|
|
||||||
EXPORT qtk-export
|
|
||||||
# <prefix>/bin on DLL systems and <prefix>/lib on non-dll systems
|
|
||||||
LIBRARY DESTINATION lib
|
|
||||||
ARCHIVE DESTINATION lib/static
|
|
||||||
RUNTIME DESTINATION bin
|
|
||||||
PUBLIC_HEADER DESTINATION include
|
|
||||||
)
|
|
||||||
|
|
||||||
# Install export
|
|
||||||
# qtkTargets.cmake will only be installed when one of the CONFIGURATIONS is installed
|
|
||||||
# + The generated import will only reference that qtk configuration
|
|
||||||
install(EXPORT qtk-export
|
|
||||||
FILE qtkTargets.cmake
|
|
||||||
CONFIGURATIONS Debug|Release
|
|
||||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake
|
|
||||||
)
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Final Application
|
# Final Application
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/resources.h "#ifndef QTK_RESOURCES_H\n#define QTK_RESOURCES_H\n#define QTK_RESOURCES_DIR \"${CMAKE_SOURCE_DIR}/resources\"\n#endif\n")
|
|
||||||
|
|
||||||
# Add our Qt resources.qrc file to our application
|
# Add our Qt resources.qrc file to our application
|
||||||
set(QTK_APP_SOURCES app/main.cpp
|
set(SOURCES app/main.cpp)
|
||||||
app/mainwindow.cpp app/mainwindow.h app/mainwindow.ui
|
qt6_add_big_resources(SOURCES resources.qrc)
|
||||||
app/scene.cpp app/scene.h
|
qt_add_executable(qtk ${SOURCES})
|
||||||
app/resourcemanager.cpp app/resourcemanager.h
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/resources.h
|
set(SOURCES
|
||||||
|
src/mainwidget.cpp src/mainwidget.h
|
||||||
|
src/mainwindow.cpp src/mainwindow.h src/mainwindow.ui
|
||||||
|
src/input.cpp src/input.h
|
||||||
|
src/mesh.cpp src/mesh.h
|
||||||
|
src/texture.cpp src/texture.h
|
||||||
|
src/object.cpp src/object.h
|
||||||
|
src/meshrenderer.cpp src/meshrenderer.h
|
||||||
|
src/camera3d.cpp src/camera3d.h
|
||||||
|
src/skybox.cpp src/skybox.h
|
||||||
|
src/transform3D.cpp src/transform3D.h
|
||||||
|
src/model.cpp src/model.h
|
||||||
|
src/scene.cpp src/scene.h
|
||||||
|
src/resourcemanager.cpp src/resourcemanager.h
|
||||||
)
|
)
|
||||||
qt6_add_big_resources(QTK_APP_SOURCES resources.qrc)
|
qt_add_library(main-widget STATIC ${SOURCES})
|
||||||
|
|
||||||
qt_add_executable(qtk-main ${QTK_APP_SOURCES})
|
target_include_directories(main-widget PUBLIC src/)
|
||||||
target_include_directories(qtk-main PRIVATE src/ app/)
|
if(ASSIMP_NEW_INTERFACE)
|
||||||
|
target_link_libraries(main-widget PRIVATE assimp::assimp)
|
||||||
|
else()
|
||||||
|
target_link_libraries(main-widget PRIVATE assimp)
|
||||||
|
endif()
|
||||||
|
target_link_libraries(main-widget PUBLIC Qt6::OpenGLWidgets)
|
||||||
|
if(WIN32)
|
||||||
|
find_package(OpenGL REQUIRED)
|
||||||
|
target_link_libraries(main-widget PUBLIC OpenGL::GL)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Link qtk-main executable to main qtk-widget library
|
target_link_libraries(qtk PUBLIC main-widget)
|
||||||
target_link_libraries(qtk-main PRIVATE qtk-widget)
|
|
||||||
|
|
||||||
set_target_properties(qtk-main PROPERTIES
|
# Link qtk executable to main main-widget library
|
||||||
|
set_target_properties(qtk PROPERTIES
|
||||||
WIN32_EXECUTABLE TRUE
|
WIN32_EXECUTABLE TRUE
|
||||||
MACOSX_BUNDLE TRUE
|
MACOSX_BUNDLE TRUE
|
||||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||||
)
|
)
|
||||||
install(TARGETS qtk-main
|
|
||||||
BUNDLE DESTINATION .
|
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
if(WIN32)
|
generate_export_header(main-widget)
|
||||||
get_target_property(_qt6_qmake_location Qt6::qmake IMPORTED_LOCATION)
|
|
||||||
execute_process(COMMAND "${_qt6_qmake_location}" -query QT_INSTALL_PREFIX RESULT_VARIABLE return_code OUTPUT_VARIABLE qt6_install_prefix OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
file(TO_NATIVE_PATH "${qt6_install_prefix}/bin" qt6_install_prefix)
|
|
||||||
if(TARGET Qt6::windeployqt)
|
|
||||||
add_custom_command(TARGET qtk-main
|
|
||||||
POST_BUILD
|
|
||||||
COMMAND set PATH=%PATH%$<SEMICOLON>${qt6_install_prefix}
|
|
||||||
COMMAND Qt6::windeployqt --dir "${CMAKE_BINARY_DIR}/windeployqt" "$<TARGET_FILE_DIR:qtk-main>/$<TARGET_FILE_NAME:qtk-main>"
|
|
||||||
)
|
|
||||||
install(DIRECTORY "${CMAKE_BINARY_DIR}/windeployqt/" DESTINATION bin)
|
|
||||||
endif()
|
|
||||||
if(MSVC AND TARGET Qt6::qmake)
|
|
||||||
set(VSUSER_FILE ${CMAKE_CURRENT_BINARY_DIR}/qtk-main.vcxproj.user)
|
|
||||||
file(TO_NATIVE_PATH "${ASSIMP_INSTALL_DIR}/bin" assimp_bin)
|
|
||||||
file(WRITE ${VSUSER_FILE} "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
|
||||||
file(APPEND ${VSUSER_FILE} "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n")
|
|
||||||
file(APPEND ${VSUSER_FILE} " <PropertyGroup>\n")
|
|
||||||
file(APPEND ${VSUSER_FILE} " <LocalDebuggerEnvironment>Path=$(SolutionDir)\\lib\\$(Configuration);${qt6_install_prefix};${assimp_bin};$(Path)\n")
|
|
||||||
file(APPEND ${VSUSER_FILE} "$(LocalDebuggerEnvironment)</LocalDebuggerEnvironment>\n")
|
|
||||||
file(APPEND ${VSUSER_FILE} " <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>\n")
|
|
||||||
file(APPEND ${VSUSER_FILE} " </PropertyGroup>\n")
|
|
||||||
file(APPEND ${VSUSER_FILE} "</Project>\n")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
################################################################################
|
|
||||||
## Author: Shaun Reed | Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
|
|
||||||
## ##
|
|
||||||
## CMake function to update git submodules ##
|
|
||||||
################################################################################
|
|
||||||
include_guard()
|
|
||||||
|
|
||||||
find_package(Git)
|
|
||||||
|
|
||||||
# _PATH: Path to git submodule location that we want to update
|
|
||||||
# + submodule_update(extern/assimp)
|
|
||||||
function(submodule_update _PATH)
|
|
||||||
if (NOT UPDATE_SUBMODULES)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (NOT GIT_FOUND)
|
|
||||||
message(FATAL_ERROR "Error: No git executable found")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
message(STATUS "${_PATH}")
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${GIT_EXECUTABLE} submodule update --init "${_PATH}"
|
|
||||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
||||||
RESULT_VARIABLE result
|
|
||||||
)
|
|
||||||
|
|
||||||
if (NOT result EQUAL 0)
|
|
||||||
message(FATAL_ERROR "Error: Unable to update git submodule at ${_PATH}")
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit bd64cc88dff17f118ecf32ebcbacaf566f6b6449
|
|
|
@ -1,48 +0,0 @@
|
||||||
/*##############################################################################
|
|
||||||
## Author: Shaun Reed ##
|
|
||||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
|
||||||
## About: Classes for managing objects and data within a scene ##
|
|
||||||
## ##
|
|
||||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
||||||
##############################################################################*/
|
|
||||||
|
|
||||||
#include <abstractscene.h>
|
|
||||||
#include <camera3d.h>
|
|
||||||
#include <resourcemanager.h>
|
|
||||||
#include <texture.h>
|
|
||||||
|
|
||||||
using namespace Qtk;
|
|
||||||
|
|
||||||
Camera3D Scene::mCamera;
|
|
||||||
QMatrix4x4 Scene::mProjection;
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Constructors, Destructors
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
Scene::Scene()
|
|
||||||
{
|
|
||||||
mCamera.transform().setTranslation(0.0f, 0.0f, 20.0f);
|
|
||||||
mCamera.transform().setRotation(-5.0f, 0.0f, 1.0f, 0.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
Scene::~Scene()
|
|
||||||
{
|
|
||||||
for (auto & mesh : mMeshes) delete mesh;
|
|
||||||
for (auto & model : mModels) delete model;
|
|
||||||
if (mSkybox != Q_NULLPTR) delete mSkybox;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scene::privDraw()
|
|
||||||
{
|
|
||||||
if (!mInit) {
|
|
||||||
initializeOpenGLFunctions();
|
|
||||||
init();
|
|
||||||
mInit = true;
|
|
||||||
}
|
|
||||||
if (mSkybox != Q_NULLPTR) mSkybox->draw();
|
|
||||||
for (auto & model : mModels) model->draw();
|
|
||||||
for (const auto & mesh : mMeshes) mesh->draw();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
/*##############################################################################
|
|
||||||
## Author: Shaun Reed ##
|
|
||||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
|
||||||
## About: Classes for managing objects and data within a scene ##
|
|
||||||
## ##
|
|
||||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
||||||
##############################################################################*/
|
|
||||||
|
|
||||||
#ifndef QTK_SCENE_H
|
|
||||||
#define QTK_SCENE_H
|
|
||||||
|
|
||||||
#include <camera3d.h>
|
|
||||||
#include <meshrenderer.h>
|
|
||||||
#include <model.h>
|
|
||||||
#include <skybox.h>
|
|
||||||
|
|
||||||
#include <QMatrix4x4>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Qtk {
|
|
||||||
class Scene : protected QOpenGLFunctions {
|
|
||||||
friend class MainWidget;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Scene();
|
|
||||||
~Scene();
|
|
||||||
|
|
||||||
virtual void init() = 0;
|
|
||||||
virtual void draw() { privDraw(); };
|
|
||||||
virtual void update() = 0;
|
|
||||||
|
|
||||||
static Camera3D & Camera() { return mCamera;}
|
|
||||||
static QMatrix4x4 View() { return mCamera.toMatrix();}
|
|
||||||
static QMatrix4x4 & Projection() { return mProjection;}
|
|
||||||
|
|
||||||
inline Skybox * getSkybox() {return mSkybox;}
|
|
||||||
inline void setSkybox(Skybox * skybox) {
|
|
||||||
mSkybox = skybox;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
static Camera3D mCamera;
|
|
||||||
static QMatrix4x4 mProjection;
|
|
||||||
bool mInit = false;
|
|
||||||
|
|
||||||
void privDraw();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Skybox * mSkybox;
|
|
||||||
std::vector<MeshRenderer *> mMeshes;
|
|
||||||
std::vector<Model *> mModels;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // QTK_SCENE_H
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#include <camera3d.h>
|
#include <camera3d.h>
|
||||||
|
|
||||||
using namespace Qtk;
|
|
||||||
|
|
||||||
const QVector3D Camera3D::LocalForward(0.0f, 0.0f, -1.0f);
|
const QVector3D Camera3D::LocalForward(0.0f, 0.0f, -1.0f);
|
||||||
const QVector3D Camera3D::LocalUp(0.0f, 1.0f, 0.0f);
|
const QVector3D Camera3D::LocalUp(0.0f, 1.0f, 0.0f);
|
||||||
|
|
|
@ -12,11 +12,10 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <transform3D.h>
|
#include <transform3D.h>
|
||||||
#include <qtkapi.h>
|
|
||||||
|
|
||||||
namespace Qtk {
|
|
||||||
class QTKAPI Camera3D {
|
class Camera3D {
|
||||||
public:
|
public:
|
||||||
// Constants
|
// Constants
|
||||||
static const QVector3D LocalForward;
|
static const QVector3D LocalForward;
|
||||||
static const QVector3D LocalUp;
|
static const QVector3D LocalUp;
|
||||||
|
@ -38,7 +37,7 @@ namespace Qtk {
|
||||||
inline QVector3D up() const
|
inline QVector3D up() const
|
||||||
{ return mTransform.rotation().rotatedVector(LocalUp);}
|
{ return mTransform.rotation().rotatedVector(LocalUp);}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Transform3D mTransform;
|
Transform3D mTransform;
|
||||||
QMatrix4x4 mWorld;
|
QMatrix4x4 mWorld;
|
||||||
|
|
||||||
|
@ -46,19 +45,18 @@ namespace Qtk {
|
||||||
friend QDataStream & operator<<(QDataStream & out, Camera3D & transform);
|
friend QDataStream & operator<<(QDataStream & out, Camera3D & transform);
|
||||||
friend QDataStream & operator>>(QDataStream & in, Camera3D & transform);
|
friend QDataStream & operator>>(QDataStream & in, Camera3D & transform);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_TYPEINFO(Camera3D, Q_MOVABLE_TYPE);
|
||||||
|
|
||||||
// Qt Streams
|
// Qt Streams
|
||||||
#ifndef QT_NO_DATASTREAM
|
#ifndef QT_NO_DATASTREAM
|
||||||
QDataStream & operator<<(QDataStream & out, const Camera3D & transform);
|
QDataStream & operator<<(QDataStream & out, const Camera3D & transform);
|
||||||
QDataStream & operator>>(QDataStream & in, Camera3D & transform);
|
QDataStream & operator>>(QDataStream & in, Camera3D & transform);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG_STREAM
|
#ifndef QT_NO_DEBUG_STREAM
|
||||||
QDebug operator<<(QDebug dbg, const Camera3D & transform);
|
QDebug operator<<(QDebug dbg, const Camera3D & transform);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
Q_DECLARE_TYPEINFO(Qtk::Camera3D, Q_MOVABLE_TYPE);
|
|
||||||
|
|
||||||
#endif // QTK_CAMERA3D_H
|
#endif // QTK_CAMERA3D_H
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
|
|
||||||
#include <input.h>
|
#include <input.h>
|
||||||
|
|
||||||
using namespace Qtk;
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Static Helper Structs
|
* Static Helper Structs
|
||||||
|
|
13
src/input.h
13
src/input.h
|
@ -12,12 +12,11 @@
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
|
|
||||||
#include <qtkapi.h>
|
|
||||||
|
|
||||||
namespace Qtk {
|
class Input {
|
||||||
class QTKAPI Input {
|
|
||||||
friend class MainWidget;
|
friend class MainWidget;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Possible key states
|
// Possible key states
|
||||||
enum InputState
|
enum InputState
|
||||||
{
|
{
|
||||||
|
@ -50,7 +49,8 @@ namespace Qtk {
|
||||||
static QPoint mousePosition();
|
static QPoint mousePosition();
|
||||||
static QPoint mouseDelta();
|
static QPoint mouseDelta();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// State updating
|
// State updating
|
||||||
static void update();
|
static void update();
|
||||||
static void registerKeyPress(int key);
|
static void registerKeyPress(int key);
|
||||||
|
@ -58,7 +58,6 @@ namespace Qtk {
|
||||||
static void registerMousePress(Qt::MouseButton button);
|
static void registerMousePress(Qt::MouseButton button);
|
||||||
static void registerMouseRelease(Qt::MouseButton button);
|
static void registerMouseRelease(Qt::MouseButton button);
|
||||||
static void reset();
|
static void reset();
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
#endif // QTOPENGL_INPUT_H
|
#endif // QTOPENGL_INPUT_H
|
||||||
|
|
|
@ -9,30 +9,30 @@
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
|
||||||
#include <input.h>
|
#include <input.h>
|
||||||
#include <mainwidget.h>
|
|
||||||
#include <mesh.h>
|
#include <mesh.h>
|
||||||
#include <abstractscene.h>
|
#include <object.h>
|
||||||
|
#include <scene.h>
|
||||||
|
|
||||||
|
#include <mainwidget.h>
|
||||||
|
|
||||||
using namespace Qtk;
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Constructors, Destructors
|
* Constructors, Destructors
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
MainWidget::MainWidget() : mScene(Q_NULLPTR), mDebugLogger(Q_NULLPTR)
|
MainWidget::MainWidget() : mDebugLogger(Q_NULLPTR)
|
||||||
{
|
{
|
||||||
initializeWidget();
|
initializeWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor for using this widget in QtDesigner
|
// Constructor for using this widget in QtDesigner
|
||||||
MainWidget::MainWidget(QWidget *parent) : QOpenGLWidget(parent),
|
MainWidget::MainWidget(QWidget *parent) : QOpenGLWidget(parent), mDebugLogger(Q_NULLPTR)
|
||||||
mScene(Q_NULLPTR), mDebugLogger(Q_NULLPTR)
|
|
||||||
{
|
{
|
||||||
initializeWidget();
|
initializeWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWidget::MainWidget(const QSurfaceFormat &format)
|
MainWidget::MainWidget(const QSurfaceFormat &format)
|
||||||
: mScene(Q_NULLPTR), mDebugLogger(Q_NULLPTR)
|
: mDebugLogger(Q_NULLPTR)
|
||||||
{
|
{
|
||||||
setFormat(format);
|
setFormat(format);
|
||||||
setFocusPolicy(Qt::ClickFocus);
|
setFocusPolicy(Qt::ClickFocus);
|
||||||
|
@ -54,6 +54,49 @@ void MainWidget::teardownGL()
|
||||||
// Nothing to teardown yet...
|
// Nothing to teardown yet...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWidget::initObjects()
|
||||||
|
{
|
||||||
|
mScene = new Scene;
|
||||||
|
|
||||||
|
// Drawing a primitive object using Qt and OpenGL
|
||||||
|
// The Object class only stores basic QOpenGL* members and shape data
|
||||||
|
// + Within mainwidget, mObject serves as a basic QOpenGL example
|
||||||
|
mObject = new Object("testObject");
|
||||||
|
mObject->setVertices(Cube(QTK_DRAW_ELEMENTS).vertices());
|
||||||
|
mObject->setIndices(Cube(QTK_DRAW_ELEMENTS).indices());
|
||||||
|
mObject->mProgram.create();
|
||||||
|
mObject->mProgram.addShaderFromSourceFile(QOpenGLShader::Vertex,
|
||||||
|
":/solid-ambient.vert");
|
||||||
|
mObject->mProgram.addShaderFromSourceFile(QOpenGLShader::Fragment,
|
||||||
|
":/solid-ambient.frag");
|
||||||
|
mObject->mProgram.link();
|
||||||
|
mObject->mProgram.bind();
|
||||||
|
|
||||||
|
mObject->mVAO.create();
|
||||||
|
mObject->mVAO.bind();
|
||||||
|
|
||||||
|
mObject->mVBO.create();
|
||||||
|
mObject->mVBO.setUsagePattern(QOpenGLBuffer::StaticDraw);
|
||||||
|
mObject->mVBO.bind();
|
||||||
|
|
||||||
|
mObject->mVBO.allocate(mObject->vertices().data(),
|
||||||
|
mObject->vertices().size()
|
||||||
|
* sizeof(mObject->vertices()[0]));
|
||||||
|
|
||||||
|
mObject->mProgram.enableAttributeArray(0);
|
||||||
|
mObject->mProgram.setAttributeBuffer(0, GL_FLOAT, 0,
|
||||||
|
3, sizeof(mObject->vertices()[0]));
|
||||||
|
mObject->mProgram.setUniformValue("uColor", QVector3D(1.0f, 0.0f, 0.0f));
|
||||||
|
mObject->mProgram.setUniformValue("uLightColor", WHITE);
|
||||||
|
mObject->mProgram.setUniformValue("uAmbientStrength", 0.75f);
|
||||||
|
|
||||||
|
mObject->mVBO.release();
|
||||||
|
mObject->mVAO.release();
|
||||||
|
mObject->mProgram.release();
|
||||||
|
|
||||||
|
mObject->mTransform.setTranslation(13.0f, 0.0f, -2.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Inherited Virtual Member Functions
|
* Inherited Virtual Member Functions
|
||||||
|
@ -65,7 +108,18 @@ void MainWidget::paintGL()
|
||||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
// Draw the scene first, since it handles drawing our skybox
|
// Draw the scene first, since it handles drawing our skybox
|
||||||
if (mScene != Q_NULLPTR) mScene->draw();
|
mScene->draw();
|
||||||
|
|
||||||
|
// Draw any additional objects within mainwidget manually
|
||||||
|
mObject->mProgram.bind();
|
||||||
|
mObject->mVAO.bind();
|
||||||
|
mObject->mProgram.setUniformValue("uModel", mObject->mTransform.toMatrix());
|
||||||
|
mObject->mProgram.setUniformValue("uView", Scene::Camera().toMatrix());
|
||||||
|
mObject->mProgram.setUniformValue("uProjection", Scene::Projection());
|
||||||
|
glDrawElements(GL_TRIANGLES, mObject->indices().size(),
|
||||||
|
GL_UNSIGNED_INT, mObject->indices().data());
|
||||||
|
mObject->mVAO.release();
|
||||||
|
mObject->mProgram.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::initializeGL()
|
void MainWidget::initializeGL()
|
||||||
|
@ -96,6 +150,9 @@ void MainWidget::initializeGL()
|
||||||
glClearDepth(1.0f);
|
glClearDepth(1.0f);
|
||||||
glClearColor(0.0f, 0.25f, 0.0f, 0.0f);
|
glClearColor(0.0f, 0.25f, 0.0f, 0.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Initialize default objects within the scene
|
||||||
|
initObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::resizeGL(int width, int height)
|
void MainWidget::resizeGL(int width, int height)
|
||||||
|
@ -115,7 +172,7 @@ void MainWidget::update()
|
||||||
{
|
{
|
||||||
updateCameraInput();
|
updateCameraInput();
|
||||||
|
|
||||||
if (mScene != Q_NULLPTR) mScene->update();
|
mScene->update();
|
||||||
|
|
||||||
QWidget::update();
|
QWidget::update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,61 +15,57 @@
|
||||||
#include <QOpenGLFunctions>
|
#include <QOpenGLFunctions>
|
||||||
#include <QOpenGLWidget>
|
#include <QOpenGLWidget>
|
||||||
|
|
||||||
#include <qtkapi.h>
|
#define QTK_DEBUG
|
||||||
#include <abstractscene.h>
|
|
||||||
|
|
||||||
|
class MeshRenderer;
|
||||||
|
class Model;
|
||||||
|
class Object;
|
||||||
|
class Scene;
|
||||||
|
class Skybox;
|
||||||
|
class Texture;
|
||||||
|
|
||||||
namespace Qtk {
|
class MainWidget : public QOpenGLWidget,
|
||||||
class QTKAPI MainWidget : public QOpenGLWidget,
|
|
||||||
protected QOpenGLFunctions {
|
protected QOpenGLFunctions {
|
||||||
Q_OBJECT;
|
Q_OBJECT;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructors
|
// Constructors
|
||||||
MainWidget();
|
MainWidget();
|
||||||
explicit MainWidget(QWidget *parent);
|
explicit MainWidget(QWidget *parent);
|
||||||
explicit MainWidget(const QSurfaceFormat &format);
|
explicit MainWidget(const QSurfaceFormat &format);
|
||||||
~MainWidget() override;
|
~MainWidget() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void teardownGL();
|
void teardownGL();
|
||||||
|
void initObjects();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Inherited virtual Members
|
// Inherited virtual Members
|
||||||
void paintGL() override;
|
void paintGL() override;
|
||||||
void initializeGL() override;
|
void initializeGL() override;
|
||||||
void resizeGL(int width, int height) override;
|
void resizeGL(int width, int height) override;
|
||||||
|
|
||||||
inline Scene * getScene() {return mScene;}
|
protected slots:
|
||||||
inline void setScene(Scene * scene) {
|
|
||||||
if (mScene != Q_NULLPTR) delete mScene;
|
|
||||||
mScene = scene;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected slots:
|
|
||||||
void update();
|
void update();
|
||||||
#ifdef QTK_DEBUG
|
|
||||||
void messageLogged(const QOpenGLDebugMessage &msg);
|
void messageLogged(const QOpenGLDebugMessage &msg);
|
||||||
#endif
|
|
||||||
|
|
||||||
// Protected Helpers
|
// Protected Helpers
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
void keyReleaseEvent(QKeyEvent *event);
|
void keyReleaseEvent(QKeyEvent *event);
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
void mouseReleaseEvent(QMouseEvent *event);
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Private helpers
|
// Private helpers
|
||||||
void initializeWidget();
|
void initializeWidget();
|
||||||
|
void printContextInformation();
|
||||||
void updateCameraInput();
|
void updateCameraInput();
|
||||||
|
|
||||||
Scene * mScene;
|
Scene * mScene;
|
||||||
#ifdef QTK_DEBUG
|
Object * mObject;
|
||||||
void printContextInformation();
|
|
||||||
QOpenGLDebugLogger * mDebugLogger;
|
QOpenGLDebugLogger * mDebugLogger;
|
||||||
#endif
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // QTK_MAINWIDGET_H
|
#endif // QTK_MAINWIDGET_H
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
#include <mainwindow.h>
|
#include "mainwindow.h"
|
||||||
#include <ui_mainwindow.h>
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow)
|
ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
mScene = new ExampleScene();
|
|
||||||
ui->openGLWidget->setScene(mScene);
|
|
||||||
setWindowIcon(QIcon("../resources/icon.png"));
|
setWindowIcon(QIcon("../resources/icon.png"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,13 @@
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
#include <qtk-widget_export.h>
|
#include "main-widget_export.h"
|
||||||
#include <scene.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
class QTK_WIDGET_EXPORT MainWindow : public QMainWindow
|
class MAIN_WIDGET_EXPORT MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -21,7 +19,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
Qtk::Scene * mScene;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
|
@ -14,7 +14,7 @@
|
||||||
<string>Qtk - MainWindow</string>
|
<string>Qtk - MainWindow</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<widget class="Qtk::MainWidget" name="openGLWidget" native="true">
|
<widget class="MainWidget" name="openGLWidget">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>10</x>
|
<x>10</x>
|
||||||
|
@ -94,8 +94,8 @@
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>Qtk::MainWidget</class>
|
<class>MainWidget</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QOpenGLWidget</extends>
|
||||||
<header>mainwidget.h</header>
|
<header>mainwidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#include <mesh.h>
|
#include <mesh.h>
|
||||||
|
|
||||||
using namespace Qtk;
|
|
||||||
|
|
||||||
Cube::Cube(DrawMode mode)
|
Cube::Cube(DrawMode mode)
|
||||||
{
|
{
|
||||||
|
|
56
src/mesh.h
56
src/mesh.h
|
@ -12,27 +12,25 @@
|
||||||
#include <QVector2D>
|
#include <QVector2D>
|
||||||
#include <QVector3D>
|
#include <QVector3D>
|
||||||
|
|
||||||
#include <qtkapi.h>
|
|
||||||
#include <transform3D.h>
|
#include <transform3D.h>
|
||||||
|
|
||||||
namespace Qtk {
|
class MeshRenderer;
|
||||||
class MeshRenderer;
|
class Object;
|
||||||
class Object;
|
|
||||||
|
|
||||||
// Define vertices for drawing a cube using two faces (8 vertex points)
|
// Define vertices for drawing a cube using two faces (8 vertex points)
|
||||||
// Front Vertices
|
// Front Vertices
|
||||||
#define VERTEX_FTR QVector3D( 0.5f, 0.5f, 0.5f) // 1
|
#define VERTEX_FTR QVector3D( 0.5f, 0.5f, 0.5f) // 1
|
||||||
#define VERTEX_FTL QVector3D(-0.5f, 0.5f, 0.5f) // 2
|
#define VERTEX_FTL QVector3D(-0.5f, 0.5f, 0.5f) // 2
|
||||||
#define VERTEX_FBL QVector3D(-0.5f, -0.5f, 0.5f) // 3
|
#define VERTEX_FBL QVector3D(-0.5f, -0.5f, 0.5f) // 3
|
||||||
#define VERTEX_FBR QVector3D( 0.5f, -0.5f, 0.5f) // 4
|
#define VERTEX_FBR QVector3D( 0.5f, -0.5f, 0.5f) // 4
|
||||||
|
|
||||||
// Back Vertices
|
// Back Vertices
|
||||||
#define VERTEX_BTR QVector3D( 0.5f, 0.5f, -0.5f) // 5
|
#define VERTEX_BTR QVector3D( 0.5f, 0.5f, -0.5f) // 5
|
||||||
#define VERTEX_BTL QVector3D(-0.5f, 0.5f, -0.5f) // 6
|
#define VERTEX_BTL QVector3D(-0.5f, 0.5f, -0.5f) // 6
|
||||||
#define VERTEX_BBL QVector3D(-0.5f, -0.5f, -0.5f) // 7
|
#define VERTEX_BBL QVector3D(-0.5f, -0.5f, -0.5f) // 7
|
||||||
#define VERTEX_BBR QVector3D( 0.5f, -0.5f, -0.5f) // 8
|
#define VERTEX_BBR QVector3D( 0.5f, -0.5f, -0.5f) // 8
|
||||||
|
|
||||||
// Direction vectors
|
// Direction vectors
|
||||||
#define VECTOR_UP QVector3D(0.0f, 1.0f, 0.0f)
|
#define VECTOR_UP QVector3D(0.0f, 1.0f, 0.0f)
|
||||||
#define VECTOR_DOWN QVector3D(0.0f, -1.0f, 0.0f)
|
#define VECTOR_DOWN QVector3D(0.0f, -1.0f, 0.0f)
|
||||||
#define VECTOR_LEFT QVector3D(-1.0f, 0.0f, 0.0f)
|
#define VECTOR_LEFT QVector3D(-1.0f, 0.0f, 0.0f)
|
||||||
|
@ -40,11 +38,11 @@ namespace Qtk {
|
||||||
#define VECTOR_FORWARD QVector3D(0.0f, 0.0f, 1.0f)
|
#define VECTOR_FORWARD QVector3D(0.0f, 0.0f, 1.0f)
|
||||||
#define VECTOR_BACK QVector3D(0.0f, 0.0f, -1.0f)
|
#define VECTOR_BACK QVector3D(0.0f, 0.0f, -1.0f)
|
||||||
|
|
||||||
// Identity and zero vectors
|
// Identity and zero vectors
|
||||||
#define VECTOR_ONE QVector3D(1.0f, 1.0f, 1.0f)
|
#define VECTOR_ONE QVector3D(1.0f, 1.0f, 1.0f)
|
||||||
#define VECTOR_ZERO QVector3D(0.0f, 0.0f, 0.0f)
|
#define VECTOR_ZERO QVector3D(0.0f, 0.0f, 0.0f)
|
||||||
|
|
||||||
// A series of direction vectors to represent cube face normal
|
// A series of direction vectors to represent cube face normal
|
||||||
#define FACE_TOP VECTOR_UP, VECTOR_UP, VECTOR_UP, \
|
#define FACE_TOP VECTOR_UP, VECTOR_UP, VECTOR_UP, \
|
||||||
VECTOR_UP, VECTOR_UP, VECTOR_UP
|
VECTOR_UP, VECTOR_UP, VECTOR_UP
|
||||||
#define FACE_BOTTOM VECTOR_DOWN, VECTOR_DOWN, VECTOR_DOWN, \
|
#define FACE_BOTTOM VECTOR_DOWN, VECTOR_DOWN, VECTOR_DOWN, \
|
||||||
|
@ -58,7 +56,7 @@ namespace Qtk {
|
||||||
#define FACE_BACK VECTOR_BACK, VECTOR_BACK, VECTOR_BACK, \
|
#define FACE_BACK VECTOR_BACK, VECTOR_BACK, VECTOR_BACK, \
|
||||||
VECTOR_BACK, VECTOR_BACK, VECTOR_BACK
|
VECTOR_BACK, VECTOR_BACK, VECTOR_BACK
|
||||||
|
|
||||||
// Colors using QVector3Ds as RGB values
|
// Colors using QVector3Ds as RGB values
|
||||||
#define WHITE VECTOR_ONE
|
#define WHITE VECTOR_ONE
|
||||||
#define BLACK VECTOR_ZERO
|
#define BLACK VECTOR_ZERO
|
||||||
#define RED QVector3D(1.0f, 0.0f, 0.0f)
|
#define RED QVector3D(1.0f, 0.0f, 0.0f)
|
||||||
|
@ -73,15 +71,16 @@ namespace Qtk {
|
||||||
#define UV_RIGHT QVector2D(0.0f, 1.0f)
|
#define UV_RIGHT QVector2D(0.0f, 1.0f)
|
||||||
#define UV_CORNER QVector2D(1.0f, 1.0f)
|
#define UV_CORNER QVector2D(1.0f, 1.0f)
|
||||||
|
|
||||||
typedef std::vector<QVector3D> Vertices;
|
|
||||||
typedef std::vector<QVector3D> Colors;
|
|
||||||
typedef std::vector<GLuint> Indices;
|
|
||||||
typedef std::vector<QVector2D> TexCoords;
|
|
||||||
typedef std::vector<QVector3D> Normals;
|
|
||||||
|
|
||||||
enum DrawMode { QTK_DRAW_ARRAYS, QTK_DRAW_ELEMENTS, QTK_DRAW_ELEMENTS_NORMALS };
|
typedef std::vector<QVector3D> Vertices;
|
||||||
|
typedef std::vector<QVector3D> Colors;
|
||||||
|
typedef std::vector<GLuint> Indices;
|
||||||
|
typedef std::vector<QVector2D> TexCoords;
|
||||||
|
typedef std::vector<QVector3D> Normals;
|
||||||
|
|
||||||
struct QTKAPI ShapeBase {
|
enum DrawMode { QTK_DRAW_ARRAYS, QTK_DRAW_ELEMENTS, QTK_DRAW_ELEMENTS_NORMALS };
|
||||||
|
|
||||||
|
struct ShapeBase {
|
||||||
ShapeBase(DrawMode mode=QTK_DRAW_ARRAYS, Vertices v={},Indices i={}, Colors c={},
|
ShapeBase(DrawMode mode=QTK_DRAW_ARRAYS, Vertices v={},Indices i={}, Colors c={},
|
||||||
TexCoords t={}, Normals n={})
|
TexCoords t={}, Normals n={})
|
||||||
: mVertices(v), mColors(c), mIndices(i), mTexCoords(t), mNormals(n)
|
: mVertices(v), mColors(c), mIndices(i), mTexCoords(t), mNormals(n)
|
||||||
|
@ -93,7 +92,7 @@ namespace Qtk {
|
||||||
inline const TexCoords & texCoords() const { return mTexCoords;}
|
inline const TexCoords & texCoords() const { return mTexCoords;}
|
||||||
inline const Normals & normals() const { return mNormals;}
|
inline const Normals & normals() const { return mNormals;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DrawMode mDrawMode;
|
DrawMode mDrawMode;
|
||||||
|
|
||||||
Vertices mVertices;
|
Vertices mVertices;
|
||||||
|
@ -101,9 +100,9 @@ namespace Qtk {
|
||||||
Indices mIndices;
|
Indices mIndices;
|
||||||
TexCoords mTexCoords;
|
TexCoords mTexCoords;
|
||||||
Normals mNormals;
|
Normals mNormals;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Shape : public ShapeBase {
|
struct Shape : public ShapeBase {
|
||||||
friend MeshRenderer;
|
friend MeshRenderer;
|
||||||
friend Object;
|
friend Object;
|
||||||
Shape () {}
|
Shape () {}
|
||||||
|
@ -115,20 +114,19 @@ namespace Qtk {
|
||||||
virtual inline void setTexCoords(const TexCoords & value) {mTexCoords = value;}
|
virtual inline void setTexCoords(const TexCoords & value) {mTexCoords = value;}
|
||||||
virtual inline void setNormals(const Normals & value) {mNormals = value;}
|
virtual inline void setNormals(const Normals & value) {mNormals = value;}
|
||||||
virtual inline void setShape(const Shape & value) { *this = value;}
|
virtual inline void setShape(const Shape & value) { *this = value;}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Primitives inherit from ShapeBase, does not allow setting of shape values
|
// Primitives inherit from ShapeBase, does not allow setting of shape values
|
||||||
class QTKAPI Mesh {
|
class Mesh {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QTKAPI Cube : public ShapeBase {
|
struct Cube : public ShapeBase {
|
||||||
Cube(DrawMode mode=QTK_DRAW_ARRAYS);
|
Cube(DrawMode mode=QTK_DRAW_ARRAYS);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QTKAPI Triangle : public ShapeBase {
|
struct Triangle : public ShapeBase {
|
||||||
Triangle(DrawMode mode=QTK_DRAW_ARRAYS);
|
Triangle(DrawMode mode=QTK_DRAW_ARRAYS);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
#endif // QTK_MESH_H
|
#endif // QTK_MESH_H
|
||||||
|
|
|
@ -8,14 +8,14 @@
|
||||||
|
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
|
|
||||||
#include <abstractscene.h>
|
#include <scene.h>
|
||||||
#include <meshrenderer.h>
|
|
||||||
#include <texture.h>
|
#include <texture.h>
|
||||||
|
|
||||||
using namespace Qtk;
|
#include <meshrenderer.h>
|
||||||
|
|
||||||
|
|
||||||
// Static QHash that holds all MeshRenderer instances using their mName as keys
|
// Static QHash that holds all MeshRenderer instances using their mName as keys
|
||||||
Qtk::MeshRenderer::MeshManager Qtk::MeshRenderer::sInstances;
|
MeshRenderer::MeshManager MeshRenderer::sInstances;
|
||||||
|
|
||||||
MeshRenderer::MeshRenderer(const char * name, const ShapeBase & shape)
|
MeshRenderer::MeshRenderer(const char * name, const ShapeBase & shape)
|
||||||
: Object(name, shape), mVertexShader(":/multi-color.vert"),
|
: Object(name, shape), mVertexShader(":/multi-color.vert"),
|
||||||
|
|
|
@ -10,12 +10,10 @@
|
||||||
|
|
||||||
#include <mesh.h>
|
#include <mesh.h>
|
||||||
#include <object.h>
|
#include <object.h>
|
||||||
#include <qtkapi.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Qtk {
|
class MeshRenderer : public Object {
|
||||||
class QTKAPI MeshRenderer : public Object {
|
public:
|
||||||
public:
|
|
||||||
// Delegate constructors
|
// Delegate constructors
|
||||||
MeshRenderer(const char * name, Vertices vertices, Indices indices,
|
MeshRenderer(const char * name, Vertices vertices, Indices indices,
|
||||||
DrawMode mode=QTK_DRAW_ARRAYS)
|
DrawMode mode=QTK_DRAW_ARRAYS)
|
||||||
|
@ -68,13 +66,12 @@ namespace Qtk {
|
||||||
|
|
||||||
// Static QHash of all mesh objects within the scene
|
// Static QHash of all mesh objects within the scene
|
||||||
typedef QHash<QString, MeshRenderer *> MeshManager;
|
typedef QHash<QString, MeshRenderer *> MeshManager;
|
||||||
private:
|
private:
|
||||||
static MeshManager sInstances;
|
static MeshManager sInstances;
|
||||||
|
|
||||||
int mDrawType;
|
int mDrawType;
|
||||||
bool mHasTexture;
|
bool mHasTexture;
|
||||||
std::string mVertexShader, mFragmentShader;
|
std::string mVertexShader, mFragmentShader;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
#endif // QTK_MESHRENDERER_H
|
#endif // QTK_MESHRENDERER_H
|
||||||
|
|
|
@ -9,12 +9,12 @@
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
#include <abstractscene.h>
|
#include <scene.h>
|
||||||
#include <model.h>
|
|
||||||
#include <resourcemanager.h>
|
|
||||||
#include <texture.h>
|
#include <texture.h>
|
||||||
|
#include <resourcemanager.h>
|
||||||
|
|
||||||
|
#include <model.h>
|
||||||
|
|
||||||
using namespace Qtk;
|
|
||||||
|
|
||||||
Model::ModelManager Model::mManager;
|
Model::ModelManager Model::mManager;
|
||||||
|
|
||||||
|
|
35
src/model.h
35
src/model.h
|
@ -16,6 +16,7 @@
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QOpenGLTexture>
|
#include <QOpenGLTexture>
|
||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
|
#include <QOpenGLFunctions>
|
||||||
|
|
||||||
// Assimp
|
// Assimp
|
||||||
#include <assimp/Importer.hpp>
|
#include <assimp/Importer.hpp>
|
||||||
|
@ -23,29 +24,28 @@
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
|
|
||||||
// QTK
|
// QTK
|
||||||
#include <qtkapi.h>
|
|
||||||
#include <transform3D.h>
|
#include <transform3D.h>
|
||||||
|
|
||||||
namespace Qtk {
|
|
||||||
struct QTKAPI ModelVertex {
|
struct ModelVertex {
|
||||||
QVector3D mPosition;
|
QVector3D mPosition;
|
||||||
QVector3D mNormal;
|
QVector3D mNormal;
|
||||||
QVector3D mTangent;
|
QVector3D mTangent;
|
||||||
QVector3D mBitangent;
|
QVector3D mBitangent;
|
||||||
QVector2D mTextureCoord;
|
QVector2D mTextureCoord;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QTKAPI ModelTexture {
|
struct ModelTexture {
|
||||||
GLuint mID;
|
GLuint mID;
|
||||||
QOpenGLTexture * mTexture;
|
QOpenGLTexture * mTexture;
|
||||||
std::string mType;
|
std::string mType;
|
||||||
std::string mPath;
|
std::string mPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Model;
|
class Model;
|
||||||
|
|
||||||
class QTKAPI ModelMesh : protected QOpenGLFunctions {
|
class ModelMesh : protected QOpenGLFunctions {
|
||||||
public:
|
public:
|
||||||
friend Model;
|
friend Model;
|
||||||
typedef std::vector<ModelVertex> Vertices;
|
typedef std::vector<ModelVertex> Vertices;
|
||||||
typedef std::vector<GLuint> Indices;
|
typedef std::vector<GLuint> Indices;
|
||||||
|
@ -65,7 +65,7 @@ namespace Qtk {
|
||||||
{ initMesh(vertexShader, fragmentShader);}
|
{ initMesh(vertexShader, fragmentShader);}
|
||||||
~ModelMesh() {}
|
~ModelMesh() {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initMesh(const char * vert, const char * frag);
|
void initMesh(const char * vert, const char * frag);
|
||||||
|
|
||||||
// ModelMesh Private Members
|
// ModelMesh Private Members
|
||||||
|
@ -73,7 +73,7 @@ namespace Qtk {
|
||||||
QOpenGLVertexArrayObject * mVAO;
|
QOpenGLVertexArrayObject * mVAO;
|
||||||
QOpenGLShaderProgram * mProgram;
|
QOpenGLShaderProgram * mProgram;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline void draw() { draw(*mProgram);}
|
inline void draw() { draw(*mProgram);}
|
||||||
void draw(QOpenGLShaderProgram & shader);
|
void draw(QOpenGLShaderProgram & shader);
|
||||||
|
|
||||||
|
@ -82,13 +82,13 @@ namespace Qtk {
|
||||||
Indices mIndices;
|
Indices mIndices;
|
||||||
Textures mTextures;
|
Textures mTextures;
|
||||||
Transform3D mTransform;
|
Transform3D mTransform;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class QTKAPI Model : public QObject {
|
class Model : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Model(const char * name, const char * path,
|
inline Model(const char * name, const char * path,
|
||||||
const char * vertexShader=":/model-basic.vert",
|
const char * vertexShader=":/model-basic.vert",
|
||||||
const char * fragmentShader=":/model-basic.frag")
|
const char * fragmentShader=":/model-basic.frag")
|
||||||
|
@ -120,7 +120,7 @@ namespace Qtk {
|
||||||
static Model * getInstance(const char * name);
|
static Model * getInstance(const char * name);
|
||||||
|
|
||||||
typedef QHash<QString, Model *> ModelManager;
|
typedef QHash<QString, Model *> ModelManager;
|
||||||
private:
|
private:
|
||||||
static ModelManager mManager;
|
static ModelManager mManager;
|
||||||
void loadModel(const std::string & path);
|
void loadModel(const std::string & path);
|
||||||
void processNode(aiNode * node, const aiScene * scene);
|
void processNode(aiNode * node, const aiScene * scene);
|
||||||
|
@ -135,7 +135,6 @@ namespace Qtk {
|
||||||
std::vector<ModelMesh> mMeshes;
|
std::vector<ModelMesh> mMeshes;
|
||||||
std::string mDirectory;
|
std::string mDirectory;
|
||||||
const char * mVertexShader, * mFragmentShader, * mName;
|
const char * mVertexShader, * mFragmentShader, * mName;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
#endif // QTK_MODEL_H
|
#endif // QTK_MODEL_H
|
||||||
|
|
|
@ -7,5 +7,3 @@
|
||||||
##############################################################################*/
|
##############################################################################*/
|
||||||
|
|
||||||
#include <object.h>
|
#include <object.h>
|
||||||
|
|
||||||
using namespace Qtk;
|
|
||||||
|
|
14
src/object.h
14
src/object.h
|
@ -14,13 +14,12 @@
|
||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
|
|
||||||
#include <mesh.h>
|
#include <mesh.h>
|
||||||
#include <qtkapi.h>
|
|
||||||
|
|
||||||
namespace Qtk {
|
|
||||||
class QTKAPI Object : public QObject {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
class Object : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
friend MeshRenderer;
|
friend MeshRenderer;
|
||||||
// Initialize an object with no shape data assigned
|
// Initialize an object with no shape data assigned
|
||||||
Object(const char * name)
|
Object(const char * name)
|
||||||
|
@ -55,9 +54,8 @@ namespace Qtk {
|
||||||
Shape mShape;
|
Shape mShape;
|
||||||
|
|
||||||
const char * mName;
|
const char * mName;
|
||||||
private:
|
private:
|
||||||
QOpenGLTexture * mTexture;
|
QOpenGLTexture * mTexture;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
#endif // QTK_OBJECT_H
|
#endif // QTK_OBJECT_H
|
||||||
|
|
23
src/qtkapi.h
23
src/qtkapi.h
|
@ -1,23 +0,0 @@
|
||||||
/*##############################################################################
|
|
||||||
## Author: Shaun Reed ##
|
|
||||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
|
||||||
## About: Main window for Qt6 OpenGL widget application ##
|
|
||||||
## ##
|
|
||||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
||||||
##############################################################################*/
|
|
||||||
#ifndef QTK_QTKAPI_H
|
|
||||||
#define QTK_QTKAPI_H
|
|
||||||
|
|
||||||
#include <QtCore/QtGlobal>
|
|
||||||
|
|
||||||
#ifdef QTK_SHARED
|
|
||||||
# if defined(QTK_EXPORT)
|
|
||||||
# define QTKAPI Q_DECL_EXPORT
|
|
||||||
# else
|
|
||||||
# define QTKAPI Q_DECL_IMPORT
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
# define QTKAPI
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif //QTK_QTKAPI_H
|
|
|
@ -6,4 +6,19 @@
|
||||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||||
##############################################################################*/
|
##############################################################################*/
|
||||||
|
|
||||||
#include <resourcemanager.h>
|
#include "resourcemanager.h"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <string>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
static std::string nixPath(std::string path)
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
std::replace(path.begin(), path.end(), '\\', '/');
|
||||||
|
#endif
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string RM::resourcesDir =
|
||||||
|
std::string(__FILE__).substr(0, nixPath(__FILE__).find("src/"))
|
||||||
|
+ "resources/";
|
|
@ -8,8 +8,6 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <resources.h>
|
|
||||||
|
|
||||||
#ifndef QTK_RESOURCEMANAGER_H
|
#ifndef QTK_RESOURCEMANAGER_H
|
||||||
#define QTK_RESOURCEMANAGER_H
|
#define QTK_RESOURCEMANAGER_H
|
||||||
|
|
||||||
|
@ -28,8 +26,10 @@ public:
|
||||||
*/
|
*/
|
||||||
static std::string getPath(const std::string & path) {
|
static std::string getPath(const std::string & path) {
|
||||||
// Only construct qtk resource path if in qrc format; else return it as-is
|
// Only construct qtk resource path if in qrc format; else return it as-is
|
||||||
return path[0] == ':' ? QTK_RESOURCES_DIR + path.substr(1) : path;
|
return path[0] == ':' ? resourcesDir + path.substr(2) : path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string resourcesDir;
|
||||||
} RM;
|
} RM;
|
||||||
|
|
||||||
#endif //QTK_RESOURCEMANAGER_H
|
#endif //QTK_RESOURCEMANAGER_H
|
|
@ -6,27 +6,32 @@
|
||||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||||
##############################################################################*/
|
##############################################################################*/
|
||||||
|
|
||||||
#include <abstractscene.h>
|
|
||||||
#include <camera3d.h>
|
#include <camera3d.h>
|
||||||
|
#include <texture.h>
|
||||||
#include <meshrenderer.h>
|
#include <meshrenderer.h>
|
||||||
#include <model.h>
|
#include <model.h>
|
||||||
#include <resourcemanager.h>
|
#include <resourcemanager.h>
|
||||||
#include <scene.h>
|
|
||||||
#include <texture.h>
|
|
||||||
|
|
||||||
using namespace Qtk;
|
#include <scene.h>
|
||||||
|
|
||||||
|
|
||||||
|
Camera3D Scene::mCamera;
|
||||||
|
QMatrix4x4 Scene::mProjection;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Constructors, Destructors
|
* Constructors, Destructors
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
ExampleScene::ExampleScene()
|
Scene::Scene()
|
||||||
{
|
{
|
||||||
Camera().transform().setTranslation(0.0f, 0.0f, 20.0f);
|
mCamera.transform().setTranslation(0.0f, 0.0f, 20.0f);
|
||||||
Camera().transform().setRotation(-5.0f, 0.0f, 1.0f, 0.0f);
|
mCamera.transform().setRotation(-5.0f, 0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
ExampleScene::~ExampleScene()
|
Scene::~Scene()
|
||||||
{
|
{
|
||||||
delete mTestPhong;
|
delete mTestPhong;
|
||||||
delete mTestSpecular;
|
delete mTestSpecular;
|
||||||
|
@ -34,7 +39,6 @@ ExampleScene::~ExampleScene()
|
||||||
delete mTestAmbient;
|
delete mTestAmbient;
|
||||||
for (auto & mesh : mMeshes) delete mesh;
|
for (auto & mesh : mMeshes) delete mesh;
|
||||||
for (auto & model : mModels) delete model;
|
for (auto & model : mModels) delete model;
|
||||||
delete mSkybox;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,13 +46,10 @@ ExampleScene::~ExampleScene()
|
||||||
* Public Member Functions
|
* Public Member Functions
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
void ExampleScene::init()
|
void Scene::init()
|
||||||
{
|
{
|
||||||
Qtk::Skybox * sb = new Qtk::Skybox("Skybox");
|
|
||||||
setSkybox(sb);
|
|
||||||
|
|
||||||
// Initialize Phong example cube
|
// Initialize Phong example cube
|
||||||
mTestPhong = new Qtk::MeshRenderer("phong", Qtk::Cube());
|
mTestPhong = new MeshRenderer("phong", Cube());
|
||||||
mTestPhong->mTransform.setTranslation(3.0f, 0.0f, -2.0f);
|
mTestPhong->mTransform.setTranslation(3.0f, 0.0f, -2.0f);
|
||||||
mTestPhong->setShaders(":/solid-phong.vert", ":/solid-phong.frag");
|
mTestPhong->setShaders(":/solid-phong.vert", ":/solid-phong.frag");
|
||||||
mTestPhong->init();
|
mTestPhong->init();
|
||||||
|
@ -75,7 +76,7 @@ void ExampleScene::init()
|
||||||
|
|
||||||
|
|
||||||
// Initialize Ambient example cube
|
// Initialize Ambient example cube
|
||||||
mTestAmbient = new Qtk::MeshRenderer("ambient", Cube());
|
mTestAmbient = new MeshRenderer("ambient", Cube());
|
||||||
mTestAmbient->mTransform.setTranslation(7.0f, 0.0f, -2.0f);
|
mTestAmbient->mTransform.setTranslation(7.0f, 0.0f, -2.0f);
|
||||||
mTestAmbient->setShaders(":/solid-ambient.vert", ":/solid-ambient.frag");
|
mTestAmbient->setShaders(":/solid-ambient.vert", ":/solid-ambient.frag");
|
||||||
mTestAmbient->init();
|
mTestAmbient->init();
|
||||||
|
@ -99,7 +100,7 @@ void ExampleScene::init()
|
||||||
mTestAmbient->mProgram.release();
|
mTestAmbient->mProgram.release();
|
||||||
|
|
||||||
// Initialize Diffuse example cube
|
// Initialize Diffuse example cube
|
||||||
mTestDiffuse = new Qtk::MeshRenderer("diffuse", Cube());
|
mTestDiffuse = new MeshRenderer("diffuse", Cube());
|
||||||
mTestDiffuse->mTransform.setTranslation(9.0f, 0.0f, -2.0f);
|
mTestDiffuse->mTransform.setTranslation(9.0f, 0.0f, -2.0f);
|
||||||
mTestDiffuse->setShaders(":/solid-diffuse.vert", ":/solid-diffuse.frag");
|
mTestDiffuse->setShaders(":/solid-diffuse.vert", ":/solid-diffuse.frag");
|
||||||
mTestDiffuse->init();
|
mTestDiffuse->init();
|
||||||
|
@ -123,7 +124,7 @@ void ExampleScene::init()
|
||||||
mTestDiffuse->mProgram.release();
|
mTestDiffuse->mProgram.release();
|
||||||
|
|
||||||
// Initialize Specular example cube
|
// Initialize Specular example cube
|
||||||
mTestSpecular = new Qtk::MeshRenderer("specular", Cube());
|
mTestSpecular = new MeshRenderer("specular", Cube());
|
||||||
mTestSpecular->mTransform.setTranslation(11.0f, 0.0f, -2.0f);
|
mTestSpecular->mTransform.setTranslation(11.0f, 0.0f, -2.0f);
|
||||||
mTestSpecular->setShaders(":/solid-specular.vert", ":/solid-specular.frag");
|
mTestSpecular->setShaders(":/solid-specular.vert", ":/solid-specular.frag");
|
||||||
mTestSpecular->init();
|
mTestSpecular->init();
|
||||||
|
@ -151,31 +152,31 @@ void ExampleScene::init()
|
||||||
//
|
//
|
||||||
// Model loading
|
// Model loading
|
||||||
|
|
||||||
mModels.push_back(new Qtk::Model("backpack", ":/models/backpack/backpack.obj"));
|
mModels.push_back(new Model("backpack", ":/models/backpack/backpack.obj"));
|
||||||
// Sometimes model textures need flipped in certain directions
|
// Sometimes model textures need flipped in certain directions
|
||||||
mModels.back()->flipTexture("diffuse.jpg", false, true);
|
mModels.back()->flipTexture("diffuse.jpg", false, true);
|
||||||
mModels.back()->mTransform.setTranslation(0.0f, 0.0f, -10.0f);
|
mModels.back()->mTransform.setTranslation(0.0f, 0.0f, -10.0f);
|
||||||
|
|
||||||
mModels.push_back(new Qtk::Model("bird", ":/models/bird/bird.obj"));
|
mModels.push_back(new Model("bird", ":/models/bird/bird.obj"));
|
||||||
mModels.back()->mTransform.setTranslation(2.0f, 2.0f, -10.0f);
|
mModels.back()->mTransform.setTranslation(2.0f, 2.0f, -10.0f);
|
||||||
// Sometimes the models are very large
|
// Sometimes the models are very large
|
||||||
mModels.back()->mTransform.scale(0.0025f);
|
mModels.back()->mTransform.scale(0.0025f);
|
||||||
mModels.back()->mTransform.rotate(-110.0f, 0.0f, 1.0f, 0.0f);
|
mModels.back()->mTransform.rotate(-110.0f, 0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
mModels.push_back(new Qtk::Model("lion", ":/models/lion/lion.obj"));
|
mModels.push_back(new Model("lion", ":/models/lion/lion.obj"));
|
||||||
mModels.back()->mTransform.setTranslation(-3.0f, -1.0f, -10.0f);
|
mModels.back()->mTransform.setTranslation(-3.0f, -1.0f, -10.0f);
|
||||||
mModels.back()->mTransform.scale(0.15f);
|
mModels.back()->mTransform.scale(0.15f);
|
||||||
|
|
||||||
mModels.push_back(new Qtk::Model("alien", ":/models/alien-hominid/alien.obj"));
|
mModels.push_back(new Model("alien", ":/models/alien-hominid/alien.obj"));
|
||||||
mModels.back()->mTransform.setTranslation(2.0f, -1.0f, -5.0f);
|
mModels.back()->mTransform.setTranslation(2.0f, -1.0f, -5.0f);
|
||||||
mModels.back()->mTransform.scale(0.15f);
|
mModels.back()->mTransform.scale(0.15f);
|
||||||
|
|
||||||
mModels.push_back(new Qtk::Model("scythe", ":/models/scythe/scythe.obj"));
|
mModels.push_back(new Model("scythe", ":/models/scythe/scythe.obj"));
|
||||||
mModels.back()->mTransform.setTranslation(-6.0f, 0.0f, -10.0f);
|
mModels.back()->mTransform.setTranslation(-6.0f, 0.0f, -10.0f);
|
||||||
mModels.back()->mTransform.rotate(-90.0f, 1.0f, 0.0f, 0.0f);
|
mModels.back()->mTransform.rotate(-90.0f, 1.0f, 0.0f, 0.0f);
|
||||||
mModels.back()->mTransform.rotate(90.0f, 0.0f, 1.0f, 0.0f);
|
mModels.back()->mTransform.rotate(90.0f, 0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
mModels.push_back(new Qtk::Model("masterChief", ":/models/spartan/spartan.obj"));
|
mModels.push_back(new Model("masterChief", ":/models/spartan/spartan.obj"));
|
||||||
mModels.back()->mTransform.setTranslation(-1.5f, 0.5f, -2.0f);
|
mModels.back()->mTransform.setTranslation(-1.5f, 0.5f, -2.0f);
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,7 +186,7 @@ void ExampleScene::init()
|
||||||
// Render an alien with specular
|
// Render an alien with specular
|
||||||
// Test alien Model with phong lighting and specular mapping
|
// Test alien Model with phong lighting and specular mapping
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("alienTestLight", Triangle(Qtk::QTK_DRAW_ELEMENTS)));
|
new MeshRenderer("alienTestLight", Triangle(QTK_DRAW_ELEMENTS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(4.0f, 1.5f, 10.0f);
|
mMeshes.back()->mTransform.setTranslation(4.0f, 1.5f, 10.0f);
|
||||||
mMeshes.back()->mTransform.scale(0.25f);
|
mMeshes.back()->mTransform.scale(0.25f);
|
||||||
// This function changes values we have allocated in a buffer, so init() after
|
// This function changes values we have allocated in a buffer, so init() after
|
||||||
|
@ -193,7 +194,7 @@ void ExampleScene::init()
|
||||||
mMeshes.back()->init();
|
mMeshes.back()->init();
|
||||||
|
|
||||||
mModels.push_back(
|
mModels.push_back(
|
||||||
new Qtk::Model("alienTest", ":/models/alien-hominid/alien.obj",
|
new Model("alienTest", ":/models/alien-hominid/alien.obj",
|
||||||
":/model-specular.vert", ":/model-specular.frag")
|
":/model-specular.vert", ":/model-specular.frag")
|
||||||
);
|
);
|
||||||
mModels.back()->mTransform.setTranslation(3.0f, -1.0f, 10.0f);
|
mModels.back()->mTransform.setTranslation(3.0f, -1.0f, 10.0f);
|
||||||
|
@ -213,7 +214,7 @@ void ExampleScene::init()
|
||||||
|
|
||||||
// Test spartan Model with phong lighting, specular and normal mapping
|
// Test spartan Model with phong lighting, specular and normal mapping
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("spartanTestLight", Triangle(QTK_DRAW_ELEMENTS))
|
new MeshRenderer("spartanTestLight", Triangle(QTK_DRAW_ELEMENTS))
|
||||||
);
|
);
|
||||||
mMeshes.back()->mTransform.setTranslation(1.0f, 1.5f, 10.0f);
|
mMeshes.back()->mTransform.setTranslation(1.0f, 1.5f, 10.0f);
|
||||||
mMeshes.back()->mTransform.scale(0.25f);
|
mMeshes.back()->mTransform.scale(0.25f);
|
||||||
|
@ -222,7 +223,7 @@ void ExampleScene::init()
|
||||||
mMeshes.back()->init();
|
mMeshes.back()->init();
|
||||||
|
|
||||||
mModels.push_back(
|
mModels.push_back(
|
||||||
new Qtk::Model("spartanTest", ":/models/spartan/spartan.obj",
|
new Model("spartanTest", ":/models/spartan/spartan.obj",
|
||||||
":/model-normals.vert", ":/model-normals.frag")
|
":/model-normals.vert", ":/model-normals.frag")
|
||||||
);
|
);
|
||||||
mModels.back()->mTransform.setTranslation(0.0f, -1.0f, 10.0f);
|
mModels.back()->mTransform.setTranslation(0.0f, -1.0f, 10.0f);
|
||||||
|
@ -241,7 +242,7 @@ void ExampleScene::init()
|
||||||
|
|
||||||
// Test basic cube with phong.vert and phong.frag shaders
|
// Test basic cube with phong.vert and phong.frag shaders
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("testLight", Triangle(QTK_DRAW_ELEMENTS)));
|
new MeshRenderer("testLight", Triangle(QTK_DRAW_ELEMENTS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(5.0f, 1.25f, 10.0f);
|
mMeshes.back()->mTransform.setTranslation(5.0f, 1.25f, 10.0f);
|
||||||
mMeshes.back()->mTransform.scale(0.25f);
|
mMeshes.back()->mTransform.scale(0.25f);
|
||||||
mMeshes.back()->setDrawType(GL_LINE_LOOP);
|
mMeshes.back()->setDrawType(GL_LINE_LOOP);
|
||||||
|
@ -250,7 +251,7 @@ void ExampleScene::init()
|
||||||
mMeshes.back()->init();
|
mMeshes.back()->init();
|
||||||
|
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("testPhong", Cube(QTK_DRAW_ARRAYS)));
|
new MeshRenderer("testPhong", Cube(QTK_DRAW_ARRAYS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(5.0f, 0.0f, 10.0f);
|
mMeshes.back()->mTransform.setTranslation(5.0f, 0.0f, 10.0f);
|
||||||
mMeshes.back()->setShaders(":/phong.vert", ":/phong.frag");
|
mMeshes.back()->setShaders(":/phong.vert", ":/phong.frag");
|
||||||
mMeshes.back()->setColor(QVector3D(0.0f, 0.25f, 0.0f));
|
mMeshes.back()->setColor(QVector3D(0.0f, 0.25f, 0.0f));
|
||||||
|
@ -290,25 +291,25 @@ void ExampleScene::init()
|
||||||
// Create simple shapes using MeshRenderer class and data in mesh.h
|
// Create simple shapes using MeshRenderer class and data in mesh.h
|
||||||
|
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("rightTriangle", Triangle(QTK_DRAW_ELEMENTS)));
|
new MeshRenderer("rightTriangle", Triangle(QTK_DRAW_ELEMENTS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(-5.0f, 0.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(-5.0f, 0.0f, -2.0f);
|
||||||
|
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("centerCube", Cube(QTK_DRAW_ELEMENTS)));
|
new MeshRenderer("centerCube", Cube(QTK_DRAW_ELEMENTS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(-7.0f, 0.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(-7.0f, 0.0f, -2.0f);
|
||||||
|
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("leftTriangle", Triangle(QTK_DRAW_ELEMENTS)));
|
new MeshRenderer("leftTriangle", Triangle(QTK_DRAW_ELEMENTS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(-9.0f, 0.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(-9.0f, 0.0f, -2.0f);
|
||||||
mMeshes.back()->setDrawType(GL_LINE_LOOP);
|
mMeshes.back()->setDrawType(GL_LINE_LOOP);
|
||||||
|
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("topTriangle", Triangle(QTK_DRAW_ELEMENTS)));
|
new MeshRenderer("topTriangle", Triangle(QTK_DRAW_ELEMENTS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(-7.0f, 2.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(-7.0f, 2.0f, -2.0f);
|
||||||
mMeshes.back()->mTransform.scale(0.25f);
|
mMeshes.back()->mTransform.scale(0.25f);
|
||||||
|
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("bottomTriangle", Triangle(QTK_DRAW_ELEMENTS)));
|
new MeshRenderer("bottomTriangle", Triangle(QTK_DRAW_ELEMENTS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(-7.0f, -2.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(-7.0f, -2.0f, -2.0f);
|
||||||
mMeshes.back()->mTransform.scale(0.25f);
|
mMeshes.back()->mTransform.scale(0.25f);
|
||||||
mMeshes.back()->setDrawType(GL_LINE_LOOP);
|
mMeshes.back()->setDrawType(GL_LINE_LOOP);
|
||||||
|
@ -321,7 +322,7 @@ void ExampleScene::init()
|
||||||
|
|
||||||
// RGB Normals cube to show normals are correct with QTK_DRAW_ARRAYS
|
// RGB Normals cube to show normals are correct with QTK_DRAW_ARRAYS
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("rgbNormalsCubeArraysTest", Cube(QTK_DRAW_ARRAYS)));
|
new MeshRenderer("rgbNormalsCubeArraysTest", Cube(QTK_DRAW_ARRAYS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(5.0f, 0.0f, 4.0f);
|
mMeshes.back()->mTransform.setTranslation(5.0f, 0.0f, 4.0f);
|
||||||
mMeshes.back()->setShaders(":/rgb-normals.vert", ":/rgb-normals.frag");
|
mMeshes.back()->setShaders(":/rgb-normals.vert", ":/rgb-normals.frag");
|
||||||
mMeshes.back()->init();
|
mMeshes.back()->init();
|
||||||
|
@ -343,7 +344,7 @@ void ExampleScene::init()
|
||||||
|
|
||||||
// RGB Normals cube to show normals are correct with QTK_DRAW_ELEMENTS_NORMALS
|
// RGB Normals cube to show normals are correct with QTK_DRAW_ELEMENTS_NORMALS
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("rgbNormalsCubeElementsTest", Cube(QTK_DRAW_ELEMENTS_NORMALS)));
|
new MeshRenderer("rgbNormalsCubeElementsTest", Cube(QTK_DRAW_ELEMENTS_NORMALS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(5.0f, 0.0f, 2.0f);
|
mMeshes.back()->mTransform.setTranslation(5.0f, 0.0f, 2.0f);
|
||||||
mMeshes.back()->setShaders(":/rgb-normals.vert", ":/rgb-normals.frag");
|
mMeshes.back()->setShaders(":/rgb-normals.vert", ":/rgb-normals.frag");
|
||||||
mMeshes.back()->init();
|
mMeshes.back()->init();
|
||||||
|
@ -368,7 +369,7 @@ void ExampleScene::init()
|
||||||
// + UVs required duplicating element position data from QTK_DRAW_ELEMENTS
|
// + UVs required duplicating element position data from QTK_DRAW_ELEMENTS
|
||||||
// + This is because the same position must use different UV coordinates
|
// + This is because the same position must use different UV coordinates
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("uvCubeArraysTest", Cube(QTK_DRAW_ARRAYS)));
|
new MeshRenderer("uvCubeArraysTest", Cube(QTK_DRAW_ARRAYS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(-3.0f, 0.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(-3.0f, 0.0f, -2.0f);
|
||||||
mMeshes.back()->setShaders(":/texture2d.vert", ":/texture2d.frag");
|
mMeshes.back()->setShaders(":/texture2d.vert", ":/texture2d.frag");
|
||||||
mMeshes.back()->init();
|
mMeshes.back()->init();
|
||||||
|
@ -396,7 +397,7 @@ void ExampleScene::init()
|
||||||
|
|
||||||
// Test drawing a cube with texture coordinates using glDrawElements
|
// Test drawing a cube with texture coordinates using glDrawElements
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("uvCubeElementsTest", Cube(QTK_DRAW_ELEMENTS_NORMALS)));
|
new MeshRenderer("uvCubeElementsTest", Cube(QTK_DRAW_ELEMENTS_NORMALS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(-1.7f, 0.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(-1.7f, 0.0f, -2.0f);
|
||||||
mMeshes.back()->setShaders(":/texture2d.vert", ":/texture2d.frag");
|
mMeshes.back()->setShaders(":/texture2d.vert", ":/texture2d.frag");
|
||||||
mMeshes.back()->init();
|
mMeshes.back()->init();
|
||||||
|
@ -422,7 +423,7 @@ void ExampleScene::init()
|
||||||
// Texturing a cube using a cube map
|
// Texturing a cube using a cube map
|
||||||
// + Cube map texturing works with both QTK_DRAW_ARRAYS and QTK_DRAW_ELEMENTS
|
// + Cube map texturing works with both QTK_DRAW_ARRAYS and QTK_DRAW_ELEMENTS
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("testCubeMap", Cube(QTK_DRAW_ELEMENTS)));
|
new MeshRenderer("testCubeMap", Cube(QTK_DRAW_ELEMENTS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(-3.0f, 1.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(-3.0f, 1.0f, -2.0f);
|
||||||
mMeshes.back()->mTransform.setRotation(45.0f, 0.0f, 1.0f, 0.0f);
|
mMeshes.back()->mTransform.setRotation(45.0f, 0.0f, 1.0f, 0.0f);
|
||||||
mMeshes.back()->setShaders(":/texture-cubemap.vert", ":/texture-cubemap.frag");
|
mMeshes.back()->setShaders(":/texture-cubemap.vert", ":/texture-cubemap.frag");
|
||||||
|
@ -449,7 +450,7 @@ void ExampleScene::init()
|
||||||
// Create a cube with custom shaders
|
// Create a cube with custom shaders
|
||||||
// + Apply RGB normals shader and spin the cube for a neat effect
|
// + Apply RGB normals shader and spin the cube for a neat effect
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("rgbNormalsCube", Cube(QTK_DRAW_ARRAYS)));
|
new MeshRenderer("rgbNormalsCube", Cube(QTK_DRAW_ARRAYS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(5.0f, 2.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(5.0f, 2.0f, -2.0f);
|
||||||
mMeshes.back()->setShaders(":/rgb-normals.vert", ":/rgb-normals.frag");
|
mMeshes.back()->setShaders(":/rgb-normals.vert", ":/rgb-normals.frag");
|
||||||
mMeshes.back()->init();
|
mMeshes.back()->init();
|
||||||
|
@ -471,7 +472,7 @@ void ExampleScene::init()
|
||||||
|
|
||||||
// RGB Normals triangle to show normals are correct with QTK_DRAW_ARRAYS
|
// RGB Normals triangle to show normals are correct with QTK_DRAW_ARRAYS
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("rgbTriangleArraysTest", Triangle(QTK_DRAW_ARRAYS)));
|
new MeshRenderer("rgbTriangleArraysTest", Triangle(QTK_DRAW_ARRAYS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(7.0f, 0.0f, 2.0f);
|
mMeshes.back()->mTransform.setTranslation(7.0f, 0.0f, 2.0f);
|
||||||
mMeshes.back()->setShaders(":/rgb-normals.vert", ":/rgb-normals.frag");
|
mMeshes.back()->setShaders(":/rgb-normals.vert", ":/rgb-normals.frag");
|
||||||
mMeshes.back()->init();
|
mMeshes.back()->init();
|
||||||
|
@ -492,7 +493,7 @@ void ExampleScene::init()
|
||||||
|
|
||||||
// RGB Normals triangle to show normals are correct with QTK_DRAW_ELEMENTS
|
// RGB Normals triangle to show normals are correct with QTK_DRAW_ELEMENTS
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("rgbTriangleElementsTest",
|
new MeshRenderer("rgbTriangleElementsTest",
|
||||||
Triangle(QTK_DRAW_ELEMENTS_NORMALS)));
|
Triangle(QTK_DRAW_ELEMENTS_NORMALS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(7.0f, 0.0f, 4.0f);
|
mMeshes.back()->mTransform.setTranslation(7.0f, 0.0f, 4.0f);
|
||||||
mMeshes.back()->setShaders(":/rgb-normals.vert", ":/rgb-normals.frag");
|
mMeshes.back()->setShaders(":/rgb-normals.vert", ":/rgb-normals.frag");
|
||||||
|
@ -514,7 +515,7 @@ void ExampleScene::init()
|
||||||
|
|
||||||
// Test drawing triangle with glDrawArrays with texture coordinates
|
// Test drawing triangle with glDrawArrays with texture coordinates
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("testTriangleArraysUV", Triangle(QTK_DRAW_ARRAYS)));
|
new MeshRenderer("testTriangleArraysUV", Triangle(QTK_DRAW_ARRAYS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(-3.0f, 2.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(-3.0f, 2.0f, -2.0f);
|
||||||
mMeshes.back()->setShaders(":/texture2d.vert", ":/texture2d.frag");
|
mMeshes.back()->setShaders(":/texture2d.vert", ":/texture2d.frag");
|
||||||
mMeshes.back()->init();
|
mMeshes.back()->init();
|
||||||
|
@ -542,7 +543,7 @@ void ExampleScene::init()
|
||||||
|
|
||||||
// Test drawing triangle with glDrawElements with texture coordinates
|
// Test drawing triangle with glDrawElements with texture coordinates
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("testTriangleElementsUV",
|
new MeshRenderer("testTriangleElementsUV",
|
||||||
Triangle(QTK_DRAW_ELEMENTS_NORMALS)));
|
Triangle(QTK_DRAW_ELEMENTS_NORMALS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(-2.5f, 0.0f, -1.0f);
|
mMeshes.back()->mTransform.setTranslation(-2.5f, 0.0f, -1.0f);
|
||||||
mMeshes.back()->setShaders(":/texture2d.vert", ":/texture2d.frag");
|
mMeshes.back()->setShaders(":/texture2d.vert", ":/texture2d.frag");
|
||||||
|
@ -574,7 +575,7 @@ void ExampleScene::init()
|
||||||
|
|
||||||
// Example of a cube with no lighting applied
|
// Example of a cube with no lighting applied
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("noLight", Cube(QTK_DRAW_ELEMENTS)));
|
new MeshRenderer("noLight", Cube(QTK_DRAW_ELEMENTS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(5.0f, 0.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(5.0f, 0.0f, -2.0f);
|
||||||
mMeshes.back()->setShaders(":/solid-perspective.vert",
|
mMeshes.back()->setShaders(":/solid-perspective.vert",
|
||||||
":/solid-perspective.frag");
|
":/solid-perspective.frag");
|
||||||
|
@ -585,24 +586,28 @@ void ExampleScene::init()
|
||||||
|
|
||||||
// Create objects that represent light sources for lighting examples
|
// Create objects that represent light sources for lighting examples
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("phongLight", Triangle(QTK_DRAW_ELEMENTS)));
|
new MeshRenderer("phongLight", Triangle(QTK_DRAW_ELEMENTS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(3.0f, 2.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(3.0f, 2.0f, -2.0f);
|
||||||
mMeshes.back()->mTransform.scale(0.25f);
|
mMeshes.back()->mTransform.scale(0.25f);
|
||||||
|
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("diffuseLight", Triangle(QTK_DRAW_ELEMENTS)));
|
new MeshRenderer("diffuseLight", Triangle(QTK_DRAW_ELEMENTS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(9.0f, 2.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(9.0f, 2.0f, -2.0f);
|
||||||
mMeshes.back()->mTransform.scale(0.25f);
|
mMeshes.back()->mTransform.scale(0.25f);
|
||||||
|
|
||||||
mMeshes.push_back(
|
mMeshes.push_back(
|
||||||
new Qtk::MeshRenderer("specularLight", Triangle(QTK_DRAW_ELEMENTS)));
|
new MeshRenderer("specularLight", Triangle(QTK_DRAW_ELEMENTS)));
|
||||||
mMeshes.back()->mTransform.setTranslation(11.0f, 2.0f, -2.0f);
|
mMeshes.back()->mTransform.setTranslation(11.0f, 2.0f, -2.0f);
|
||||||
mMeshes.back()->mTransform.scale(0.25f);
|
mMeshes.back()->mTransform.scale(0.25f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExampleScene::draw()
|
void Scene::draw()
|
||||||
{
|
{
|
||||||
Scene::draw();
|
mSkybox.draw();
|
||||||
|
|
||||||
|
for (auto & model : mModels) model->draw();
|
||||||
|
|
||||||
|
for (const auto &mesh : mMeshes) mesh->draw();
|
||||||
|
|
||||||
mTestPhong->mProgram.bind();
|
mTestPhong->mProgram.bind();
|
||||||
mTestPhong->setUniform("uModelInverseTransposed",
|
mTestPhong->setUniform("uModelInverseTransposed",
|
||||||
|
@ -611,13 +616,13 @@ void ExampleScene::draw()
|
||||||
"uLightPosition",
|
"uLightPosition",
|
||||||
MeshRenderer::getInstance("phongLight")->mTransform.translation());
|
MeshRenderer::getInstance("phongLight")->mTransform.translation());
|
||||||
mTestPhong->setUniform("uCameraPosition",
|
mTestPhong->setUniform("uCameraPosition",
|
||||||
ExampleScene::Camera().transform().translation());
|
Scene::Camera().transform().translation());
|
||||||
mTestPhong->mProgram.release();
|
mTestPhong->mProgram.release();
|
||||||
mTestPhong->draw();
|
mTestPhong->draw();
|
||||||
|
|
||||||
mTestAmbient->mProgram.bind();
|
mTestAmbient->mProgram.bind();
|
||||||
mTestAmbient->setUniform("uCameraPosition",
|
mTestAmbient->setUniform("uCameraPosition",
|
||||||
ExampleScene::Camera().transform().translation());
|
Scene::Camera().transform().translation());
|
||||||
mTestAmbient->mProgram.release();
|
mTestAmbient->mProgram.release();
|
||||||
mTestAmbient->draw();
|
mTestAmbient->draw();
|
||||||
|
|
||||||
|
@ -627,7 +632,7 @@ void ExampleScene::draw()
|
||||||
mTestDiffuse->setUniform(
|
mTestDiffuse->setUniform(
|
||||||
"uLightPosition",
|
"uLightPosition",
|
||||||
MeshRenderer::getInstance("diffuseLight")->mTransform.translation());
|
MeshRenderer::getInstance("diffuseLight")->mTransform.translation());
|
||||||
mTestDiffuse->setUniform("uCameraPosition", ExampleScene::Camera().transform().translation());
|
mTestDiffuse->setUniform("uCameraPosition", Scene::Camera().transform().translation());
|
||||||
mTestDiffuse->mProgram.release();
|
mTestDiffuse->mProgram.release();
|
||||||
mTestDiffuse->draw();
|
mTestDiffuse->draw();
|
||||||
|
|
||||||
|
@ -638,43 +643,43 @@ void ExampleScene::draw()
|
||||||
mTestSpecular->setUniform(
|
mTestSpecular->setUniform(
|
||||||
"uLightPosition",
|
"uLightPosition",
|
||||||
MeshRenderer::getInstance("specularLight")->mTransform.translation());
|
MeshRenderer::getInstance("specularLight")->mTransform.translation());
|
||||||
mTestSpecular->setUniform("uCameraPosition", ExampleScene::Camera().transform().translation());
|
mTestSpecular->setUniform("uCameraPosition", Scene::Camera().transform().translation());
|
||||||
mTestSpecular->mProgram.release();
|
mTestSpecular->mProgram.release();
|
||||||
mTestSpecular->draw();
|
mTestSpecular->draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExampleScene::update()
|
void Scene::update()
|
||||||
{
|
{
|
||||||
auto position = MeshRenderer::getInstance("alienTestLight")->mTransform.translation();
|
auto position = MeshRenderer::getInstance("alienTestLight")->mTransform.translation();
|
||||||
Model::getInstance("alienTest")->setUniform(
|
Model::getInstance("alienTest")->setUniform(
|
||||||
"uLight.position", position);
|
"uLight.position", position);
|
||||||
Model::getInstance("alienTest")->setUniform(
|
Model::getInstance("alienTest")->setUniform(
|
||||||
"uCameraPosition", ExampleScene::Camera().transform().translation());
|
"uCameraPosition", Scene::Camera().transform().translation());
|
||||||
auto posMatrix = Model::getInstance("alienTest")->mTransform.toMatrix();
|
auto posMatrix = Model::getInstance("alienTest")->mTransform.toMatrix();
|
||||||
Model::getInstance("alienTest")->setUniform(
|
Model::getInstance("alienTest")->setUniform(
|
||||||
"uMVP.normalMatrix", posMatrix.normalMatrix());
|
"uMVP.normalMatrix", posMatrix.normalMatrix());
|
||||||
Model::getInstance("alienTest")->setUniform(
|
Model::getInstance("alienTest")->setUniform(
|
||||||
"uMVP.model", posMatrix);
|
"uMVP.model", posMatrix);
|
||||||
Model::getInstance("alienTest")->setUniform(
|
Model::getInstance("alienTest")->setUniform(
|
||||||
"uMVP.view", ExampleScene::Camera().toMatrix());
|
"uMVP.view", Scene::Camera().toMatrix());
|
||||||
Model::getInstance("alienTest")->setUniform(
|
Model::getInstance("alienTest")->setUniform(
|
||||||
"uMVP.projection", ExampleScene::Projection());
|
"uMVP.projection", Scene::Projection());
|
||||||
Model::getInstance("alienTest")->mTransform.rotate(0.75f, 0.0f, 1.0f, 0.0f);
|
Model::getInstance("alienTest")->mTransform.rotate(0.75f, 0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
position = MeshRenderer::getInstance("spartanTestLight")->mTransform.translation();
|
position = MeshRenderer::getInstance("spartanTestLight")->mTransform.translation();
|
||||||
Model::getInstance("spartanTest")->setUniform(
|
Model::getInstance("spartanTest")->setUniform(
|
||||||
"uLight.position", position);
|
"uLight.position", position);
|
||||||
Model::getInstance("spartanTest")->setUniform(
|
Model::getInstance("spartanTest")->setUniform(
|
||||||
"uCameraPosition", ExampleScene::Camera().transform().translation());
|
"uCameraPosition", Scene::Camera().transform().translation());
|
||||||
posMatrix = Model::getInstance("spartanTest")->mTransform.toMatrix();
|
posMatrix = Model::getInstance("spartanTest")->mTransform.toMatrix();
|
||||||
Model::getInstance("spartanTest")->setUniform(
|
Model::getInstance("spartanTest")->setUniform(
|
||||||
"uMVP.normalMatrix", posMatrix.normalMatrix());
|
"uMVP.normalMatrix", posMatrix.normalMatrix());
|
||||||
Model::getInstance("spartanTest")->setUniform(
|
Model::getInstance("spartanTest")->setUniform(
|
||||||
"uMVP.model", posMatrix);
|
"uMVP.model", posMatrix);
|
||||||
Model::getInstance("spartanTest")->setUniform(
|
Model::getInstance("spartanTest")->setUniform(
|
||||||
"uMVP.view", ExampleScene::Camera().toMatrix());
|
"uMVP.view", Scene::Camera().toMatrix());
|
||||||
Model::getInstance("spartanTest")->setUniform(
|
Model::getInstance("spartanTest")->setUniform(
|
||||||
"uMVP.projection", ExampleScene::Projection());
|
"uMVP.projection", Scene::Projection());
|
||||||
Model::getInstance("spartanTest")->mTransform.rotate(0.75f, 0.0f, 1.0f, 0.0f);
|
Model::getInstance("spartanTest")->mTransform.rotate(0.75f, 0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
|
|
||||||
|
@ -686,16 +691,16 @@ void ExampleScene::update()
|
||||||
MeshRenderer::getInstance("testPhong")->setUniform(
|
MeshRenderer::getInstance("testPhong")->setUniform(
|
||||||
"uLight.position", position);
|
"uLight.position", position);
|
||||||
MeshRenderer::getInstance("testPhong")->setUniform(
|
MeshRenderer::getInstance("testPhong")->setUniform(
|
||||||
"uCameraPosition", ExampleScene::Camera().transform().translation());
|
"uCameraPosition", Scene::Camera().transform().translation());
|
||||||
posMatrix = MeshRenderer::getInstance("testPhong")->mTransform.toMatrix();
|
posMatrix = MeshRenderer::getInstance("testPhong")->mTransform.toMatrix();
|
||||||
MeshRenderer::getInstance("testPhong")->setUniform(
|
MeshRenderer::getInstance("testPhong")->setUniform(
|
||||||
"uMVP.normalMatrix", posMatrix.normalMatrix());
|
"uMVP.normalMatrix", posMatrix.normalMatrix());
|
||||||
MeshRenderer::getInstance("testPhong")->setUniform(
|
MeshRenderer::getInstance("testPhong")->setUniform(
|
||||||
"uMVP.model", posMatrix);
|
"uMVP.model", posMatrix);
|
||||||
MeshRenderer::getInstance("testPhong")->setUniform(
|
MeshRenderer::getInstance("testPhong")->setUniform(
|
||||||
"uMVP.view", ExampleScene::Camera().toMatrix());
|
"uMVP.view", Scene::Camera().toMatrix());
|
||||||
MeshRenderer::getInstance("testPhong")->setUniform(
|
MeshRenderer::getInstance("testPhong")->setUniform(
|
||||||
"uMVP.projection", ExampleScene::Projection());
|
"uMVP.projection", Scene::Projection());
|
||||||
MeshRenderer::getInstance("testPhong")->mProgram.release();
|
MeshRenderer::getInstance("testPhong")->mProgram.release();
|
||||||
|
|
||||||
// Rotate lighting example cubes
|
// Rotate lighting example cubes
|
|
@ -6,32 +6,40 @@
|
||||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||||
##############################################################################*/
|
##############################################################################*/
|
||||||
|
|
||||||
#ifndef QTK_EXAMPLE_SCENE_H
|
#ifndef QTK_SCENE_H
|
||||||
#define QTK_EXAMPLE_SCENE_H
|
#define QTK_SCENE_H
|
||||||
|
|
||||||
#include <abstractscene.h>
|
|
||||||
#include <camera3d.h>
|
#include <camera3d.h>
|
||||||
#include <skybox.h>
|
#include <skybox.h>
|
||||||
|
|
||||||
#include <QMatrix4x4>
|
#include <QMatrix4x4>
|
||||||
|
|
||||||
|
class MeshRenderer;
|
||||||
|
class Model;
|
||||||
|
|
||||||
class ExampleScene : public Qtk::Scene {
|
class Scene {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ExampleScene();
|
Scene();
|
||||||
~ExampleScene();
|
~Scene();
|
||||||
|
|
||||||
virtual void init();
|
void init();
|
||||||
virtual void draw() override;
|
void draw();
|
||||||
virtual void update();
|
void update();
|
||||||
|
|
||||||
|
static Camera3D & Camera() { return mCamera;}
|
||||||
|
static QMatrix4x4 View() { return mCamera.toMatrix();}
|
||||||
|
static QMatrix4x4 & Projection() { return mProjection;}
|
||||||
private:
|
private:
|
||||||
|
static Camera3D mCamera;
|
||||||
|
static QMatrix4x4 mProjection;
|
||||||
|
|
||||||
Qtk::MeshRenderer * mTestPhong;
|
Skybox mSkybox;
|
||||||
Qtk::MeshRenderer * mTestSpecular;
|
MeshRenderer * mTestPhong;
|
||||||
Qtk::MeshRenderer * mTestDiffuse;
|
MeshRenderer * mTestSpecular;
|
||||||
Qtk::MeshRenderer * mTestAmbient;
|
MeshRenderer * mTestDiffuse;
|
||||||
|
MeshRenderer * mTestAmbient;
|
||||||
|
std::vector<MeshRenderer *> mMeshes;
|
||||||
|
std::vector<Model *> mModels;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QTK_EXAMPLE_SCENE_H
|
#endif // QTK_SCENE_H
|
|
@ -6,25 +6,23 @@
|
||||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||||
##############################################################################*/
|
##############################################################################*/
|
||||||
|
|
||||||
#include <abstractscene.h>
|
#include <scene.h>
|
||||||
#include <skybox.h>
|
|
||||||
#include <texture.h>
|
#include <texture.h>
|
||||||
|
|
||||||
using namespace Qtk;
|
#include <skybox.h>
|
||||||
|
|
||||||
|
|
||||||
Skybox::Skybox(std::string right, std::string top, std::string front,
|
Skybox::Skybox(std::string right, std::string top, std::string front,
|
||||||
std::string left, std::string bottom, std::string back,
|
std::string left, std::string bottom, std::string back,
|
||||||
const std::string & name)
|
const std::string & name)
|
||||||
: mVBO(QOpenGLBuffer::VertexBuffer),
|
: mCubeMap(Texture::initCubeMap(
|
||||||
mVertices(Cube(QTK_DRAW_ELEMENTS).vertices()),
|
|
||||||
mIndices(Cube(QTK_DRAW_ELEMENTS).indices())
|
|
||||||
{
|
|
||||||
init();
|
|
||||||
mCubeMap = Texture::initCubeMap(
|
|
||||||
QImage(right.c_str()).mirrored(), QImage(top.c_str()),
|
QImage(right.c_str()).mirrored(), QImage(top.c_str()),
|
||||||
QImage(front.c_str()), QImage(left.c_str()),
|
QImage(front.c_str()), QImage(left.c_str()),
|
||||||
QImage(bottom.c_str()), QImage(back.c_str()));
|
QImage(bottom.c_str()), QImage(back.c_str()))),
|
||||||
}
|
mVBO(QOpenGLBuffer::VertexBuffer),
|
||||||
|
mVertices(Cube(QTK_DRAW_ELEMENTS).vertices()),
|
||||||
|
mIndices(Cube(QTK_DRAW_ELEMENTS).indices())
|
||||||
|
{ init();}
|
||||||
|
|
||||||
Skybox::Skybox(std::string name)
|
Skybox::Skybox(std::string name)
|
||||||
: Skybox(":/right.png", ":/top.png", ":/front.png",
|
: Skybox(":/right.png", ":/top.png", ":/front.png",
|
||||||
|
@ -89,11 +87,13 @@ void Skybox::init()
|
||||||
mVBO.setUsagePattern(QOpenGLBuffer::StaticDraw);
|
mVBO.setUsagePattern(QOpenGLBuffer::StaticDraw);
|
||||||
mVBO.bind();
|
mVBO.bind();
|
||||||
// Allocate vertex positions into VBO
|
// Allocate vertex positions into VBO
|
||||||
mVBO.allocate(mVertices.data(), mVertices.size() * sizeof(mVertices[0]));
|
mVBO.allocate(mVertices.data(),
|
||||||
|
mVertices.size() * sizeof(mVertices[0]));
|
||||||
|
|
||||||
// Enable attribute array for vertex positions
|
// Enable attribute array for vertex positions
|
||||||
mProgram.enableAttributeArray(0);
|
mProgram.enableAttributeArray(0);
|
||||||
mProgram.setAttributeBuffer(0, GL_FLOAT, 0, 3, sizeof(QVector3D));
|
mProgram.setAttributeBuffer(0, GL_FLOAT, 0,
|
||||||
|
3, sizeof(QVector3D));
|
||||||
// Set shader texture unit to 0
|
// Set shader texture unit to 0
|
||||||
mProgram.setUniformValue("uTexture", 0);
|
mProgram.setUniformValue("uTexture", 0);
|
||||||
|
|
||||||
|
|
13
src/skybox.h
13
src/skybox.h
|
@ -10,19 +10,17 @@
|
||||||
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QOpenGLBuffer>
|
#include <QOpenGLBuffer>
|
||||||
#include <QOpenGLFunctions>
|
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QOpenGLTexture>
|
#include <QOpenGLTexture>
|
||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
|
#include <QOpenGLFunctions>
|
||||||
|
|
||||||
#include <camera3d.h>
|
#include <camera3d.h>
|
||||||
#include <mesh.h>
|
#include <mesh.h>
|
||||||
#include <qtkapi.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Qtk {
|
class Skybox : protected QOpenGLFunctions {
|
||||||
class QTKAPI Skybox : protected QOpenGLFunctions {
|
public:
|
||||||
public:
|
|
||||||
// Delegate this constructor to use default skybox images
|
// Delegate this constructor to use default skybox images
|
||||||
// + This allows creating a skybox with no arguments ( auto s = new Skybox; )
|
// + This allows creating a skybox with no arguments ( auto s = new Skybox; )
|
||||||
explicit Skybox(std::string name="Skybox");
|
explicit Skybox(std::string name="Skybox");
|
||||||
|
@ -35,7 +33,7 @@ namespace Qtk {
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
Vertices mVertices;
|
Vertices mVertices;
|
||||||
|
@ -45,7 +43,6 @@ namespace Qtk {
|
||||||
QOpenGLVertexArrayObject mVAO;
|
QOpenGLVertexArrayObject mVAO;
|
||||||
QOpenGLBuffer mVBO;
|
QOpenGLBuffer mVBO;
|
||||||
QOpenGLTexture * mCubeMap;
|
QOpenGLTexture * mCubeMap;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
#endif // QTK_SKYBOX_H
|
#endif // QTK_SKYBOX_H
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
#include <texture.h>
|
#include <texture.h>
|
||||||
|
|
||||||
using namespace Qtk;
|
|
||||||
|
|
||||||
QImage * Texture::initImage(const char * image, bool flipX, bool flipY)
|
QImage * Texture::initImage(const char * image, bool flipX, bool flipY)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,11 +11,9 @@
|
||||||
|
|
||||||
#include <QOpenGLTexture>
|
#include <QOpenGLTexture>
|
||||||
|
|
||||||
#include <qtkapi.h>
|
|
||||||
|
|
||||||
namespace Qtk {
|
class Texture {
|
||||||
class QTKAPI Texture {
|
public:
|
||||||
public:
|
|
||||||
~Texture() {}
|
~Texture() {}
|
||||||
|
|
||||||
// QImage
|
// QImage
|
||||||
|
@ -36,10 +34,9 @@ namespace Qtk {
|
||||||
const char * front, const char * left,
|
const char * front, const char * left,
|
||||||
const char * bottom, const char * back);
|
const char * bottom, const char * back);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Private ctor to prevent creating instances of this class
|
// Private ctor to prevent creating instances of this class
|
||||||
Texture() {}
|
Texture() {}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
#endif // QTOPENGL_TEXTURE_H
|
#endif // QTOPENGL_TEXTURE_H
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
#include <transform3D.h>
|
#include <transform3D.h>
|
||||||
|
|
||||||
using namespace Qtk;
|
|
||||||
|
|
||||||
const QVector3D Transform3D::LocalForward(0.0f, 0.0f, 1.0f);
|
const QVector3D Transform3D::LocalForward(0.0f, 0.0f, 1.0f);
|
||||||
const QVector3D Transform3D::LocalUp(0.0f, 1.0f, 0.0f);
|
const QVector3D Transform3D::LocalUp(0.0f, 1.0f, 0.0f);
|
||||||
|
@ -111,10 +110,8 @@ QVector3D Transform3D::right() const
|
||||||
* QT Streams
|
* QT Streams
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
namespace Qtk {
|
QDebug operator<<(QDebug dbg, const Transform3D & transform)
|
||||||
#ifndef QT_NO_DEBUG_STREAM
|
{
|
||||||
QDebug operator<<(QDebug dbg, const Transform3D & transform)
|
|
||||||
{
|
|
||||||
dbg << "Transform3D\n{\n";
|
dbg << "Transform3D\n{\n";
|
||||||
dbg << "Position: <" << transform.translation().x() << ", "
|
dbg << "Position: <" << transform.translation().x() << ", "
|
||||||
<< transform.translation().y() << ", "
|
<< transform.translation().y() << ", "
|
||||||
|
@ -128,24 +125,20 @@ namespace Qtk {
|
||||||
transform.rotation().scalar() << ">\n}";
|
transform.rotation().scalar() << ">\n}";
|
||||||
return dbg;
|
return dbg;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef QT_NO_DATASTREAM
|
QDataStream & operator<<(QDataStream & out, const Transform3D & transform)
|
||||||
QDataStream & operator<<(QDataStream & out, const Transform3D & transform)
|
{
|
||||||
{
|
|
||||||
out << transform.mTranslation;
|
out << transform.mTranslation;
|
||||||
out << transform.mScale;
|
out << transform.mScale;
|
||||||
out << transform.mRotation;
|
out << transform.mRotation;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream & operator>>(QDataStream & in, Transform3D & transform)
|
QDataStream & operator>>(QDataStream & in, Transform3D & transform)
|
||||||
{
|
{
|
||||||
in >> transform.mTranslation;
|
in >> transform.mTranslation;
|
||||||
in >> transform.mScale;
|
in >> transform.mScale;
|
||||||
in >> transform.mRotation;
|
in >> transform.mRotation;
|
||||||
transform.m_dirty = true;
|
transform.m_dirty = true;
|
||||||
return in;
|
return in;
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,20 +10,15 @@
|
||||||
#ifndef QTK_TRANSFORM3D_H
|
#ifndef QTK_TRANSFORM3D_H
|
||||||
#define QTK_TRANSFORM3D_H
|
#define QTK_TRANSFORM3D_H
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QMatrix4x4>
|
#include <QMatrix4x4>
|
||||||
#include <QQuaternion>
|
#include <QQuaternion>
|
||||||
#include <QVector3D>
|
#include <QVector3D>
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG_STREAM
|
|
||||||
#include <QDebug>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <qtkapi.h>
|
class Transform3D
|
||||||
|
{
|
||||||
namespace Qtk {
|
public:
|
||||||
class QTKAPI Transform3D
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// Constructors
|
// Constructors
|
||||||
inline Transform3D() : m_dirty(true),
|
inline Transform3D() : m_dirty(true),
|
||||||
mScale(1.0f, 1.0f, 1.0f),
|
mScale(1.0f, 1.0f, 1.0f),
|
||||||
|
@ -93,7 +88,7 @@ namespace Qtk {
|
||||||
|
|
||||||
static const QVector3D LocalForward, LocalUp, LocalRight;
|
static const QVector3D LocalForward, LocalUp, LocalRight;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector3D mTranslation;
|
QVector3D mTranslation;
|
||||||
QQuaternion mRotation;
|
QQuaternion mRotation;
|
||||||
QVector3D mScale;
|
QVector3D mScale;
|
||||||
|
@ -101,25 +96,22 @@ namespace Qtk {
|
||||||
|
|
||||||
bool m_dirty;
|
bool m_dirty;
|
||||||
|
|
||||||
|
|
||||||
#ifndef QT_NO_DATASTREAM
|
#ifndef QT_NO_DATASTREAM
|
||||||
friend QDataStream &operator<<(QDataStream & out, const Transform3D & transform);
|
friend QDataStream &operator<<(QDataStream & out, const Transform3D & transform);
|
||||||
friend QDataStream &operator>>(QDataStream & in, Transform3D & transform);
|
friend QDataStream &operator>>(QDataStream & in, Transform3D & transform);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_TYPEINFO(Transform3D, Q_MOVABLE_TYPE);
|
||||||
|
|
||||||
// Qt Streams
|
// Qt Streams
|
||||||
#ifndef QT_NO_DEBUG_STREAM
|
#ifndef QT_NO_DEBUG_STREAM
|
||||||
QDebug operator<<(QDebug dbg, const Transform3D & transform);
|
QDebug operator<<(QDebug dbg, const Transform3D & transform);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef QT_NO_DATASTREAM
|
#ifndef QT_NO_DATASTREAM
|
||||||
QDataStream &operator<<(QDataStream & out, const Transform3D & transform);
|
QDataStream &operator<<(QDataStream & out, const Transform3D & transform);
|
||||||
QDataStream &operator>>(QDataStream & in, Transform3D & transform);
|
QDataStream &operator>>(QDataStream & in, Transform3D & transform);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
Q_DECLARE_TYPEINFO(Qtk::Transform3D, Q_MOVABLE_TYPE);
|
|
||||||
|
|
||||||
#endif // QTK_TRANSFORM3D_H
|
#endif // QTK_TRANSFORM3D_H
|
||||||
|
|
Loading…
Reference in New Issue