|
@@ -0,0 +1,269 @@
|
|
|
|
|
+#include "pch.h"
|
|
|
|
|
+
|
|
|
|
|
+#include "Camera3D.h"
|
|
|
|
|
+#include "CppUnitTest.h"
|
|
|
|
|
+#include "DX12GraphicsApi.h"
|
|
|
|
|
+#include "Globals.h"
|
|
|
|
|
+#include "Model3D.h"
|
|
|
|
|
+#include "RenderThread.h"
|
|
|
|
|
+#include "Screen.h"
|
|
|
|
|
+#include "Window.h"
|
|
|
|
|
+#include "World3D.h"
|
|
|
|
|
+
|
|
|
|
|
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
|
|
|
+
|
|
|
|
|
+namespace FrameworkTests
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+ TEST_CLASS (Cam3Tests)
|
|
|
|
|
+ {
|
|
|
|
|
+ public:
|
|
|
|
|
+ TEST_METHOD (TestProjection)
|
|
|
|
|
+ {
|
|
|
|
|
+ Framework::Cam3D cam;
|
|
|
|
|
+ cam.setPosition(Framework::Vec3<float>(0, 0, 0));
|
|
|
|
|
+ cam.setRotation(Framework::Vec3<float>(0, 0, 0));
|
|
|
|
|
+ Framework::Vec3<float> target(0, 1000, 0);
|
|
|
|
|
+ cam.setViewDirection(target);
|
|
|
|
|
+ Framework::Mat4<float> projection = cam.getProjectionMatrix();
|
|
|
|
|
+ Framework::Mat4<float> inverse = cam.getInverseProjectionMatrix();
|
|
|
|
|
+ Framework::Mat4<float> view = cam.getViewMatrix();
|
|
|
|
|
+ Framework::Mat4<float> iView = cam.getInverseViewMatrix();
|
|
|
|
|
+ for (int i = 0; i < 10; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (int j = 0; j < 10; j++)
|
|
|
|
|
+ {
|
|
|
|
|
+ Framework::Vec4<float> origin(0, 0, 0, 1.f);
|
|
|
|
|
+ Framework::Vec4<float> target(
|
|
|
|
|
+ i / 5.f - 1.f, j / 5.f - 1.f, -1.f, 1.f);
|
|
|
|
|
+ Framework::Vec4<float> transformedOrigin = iView * origin;
|
|
|
|
|
+ Framework::Vec4<float> transformedTarget
|
|
|
|
|
+ = iView * (inverse * target);
|
|
|
|
|
+ Framework::Vec4<float> transformedDirection
|
|
|
|
|
+ = transformedTarget - transformedOrigin;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ TEST_METHOD (TestRaytracing)
|
|
|
|
|
+ {
|
|
|
|
|
+ Framework::initFramework();
|
|
|
|
|
+ Framework::setDebugDX(1);
|
|
|
|
|
+ Framework::NativeWindow window;
|
|
|
|
|
+ WNDCLASS wc = Framework::F_Normal(GetModuleHandle(0));
|
|
|
|
|
+ wc.lpszClassName = "Factory Craft";
|
|
|
|
|
+ window.create(WS_POPUPWINDOW, wc);
|
|
|
|
|
+ Framework::Monitor m = Framework::getMonitor(0);
|
|
|
|
|
+ window.setBounds(Framework::Point(m.x, m.y),
|
|
|
|
|
+ Framework::Point(m.width, m.height));
|
|
|
|
|
+ window.setDisplayMode(SW_SHOWNORMAL);
|
|
|
|
|
+ window.setPreCloseAction([&window](void* p, void* f) {
|
|
|
|
|
+ Framework::StopMessageLoop(window.getWindowHandle());
|
|
|
|
|
+ });
|
|
|
|
|
+ window.setMouseAction(Framework::_ret1ME);
|
|
|
|
|
+ window.setKeyboardAction(Framework::_ret1TE);
|
|
|
|
|
+ Framework::Screen3D screen(
|
|
|
|
|
+ dynamic_cast<Framework::NativeWindow*>(window.getThis()),
|
|
|
|
|
+ new Framework::DirectX12());
|
|
|
|
|
+ screen.setHandleUserInputsOnTick(0);
|
|
|
|
|
+ window.setScreen(
|
|
|
|
|
+ dynamic_cast<Framework::Screen*>(screen.getThis()));
|
|
|
|
|
+ screen.setFillColor(0);
|
|
|
|
|
+ screen.setTestRend(0);
|
|
|
|
|
+
|
|
|
|
|
+ Framework::Cam3D cam;
|
|
|
|
|
+ cam.setPosition({0.f, 0.f, 0.f});
|
|
|
|
|
+ Framework::Vec3<float> target(0, 1000, 0);
|
|
|
|
|
+ cam.setViewDirection(target);
|
|
|
|
|
+ Framework::World3D world;
|
|
|
|
|
+
|
|
|
|
|
+ Framework::Model3D cube;
|
|
|
|
|
+ Framework::Model3DData* data
|
|
|
|
|
+ = screen.zGraphicsApi()->createModel("cube");
|
|
|
|
|
+ data->setAmbientFactor(0.f);
|
|
|
|
|
+ data->setDiffusFactor(1.f);
|
|
|
|
|
+ data->setSpecularFactor(0.f);
|
|
|
|
|
+ float size = 1;
|
|
|
|
|
+ float left, right, top, bottom;
|
|
|
|
|
+ // Calculate the screen coordinates of the left side of the bitmap.
|
|
|
|
|
+ right = (float)((-size / 2.0));
|
|
|
|
|
+ // Calculate the screen coordinates of the right side of the bitmap.
|
|
|
|
|
+ left = right + (float)size;
|
|
|
|
|
+ // Calculate the screen coordinates of the top of the bitmap.
|
|
|
|
|
+ top = (float)(size / 2.0);
|
|
|
|
|
+ // Calculate the screen coordinates of the bottom of the bitmap.
|
|
|
|
|
+ bottom = top - (float)size;
|
|
|
|
|
+ float front = -size / 2;
|
|
|
|
|
+ float back = front + size;
|
|
|
|
|
+
|
|
|
|
|
+ Framework::Vertex3D* vertecies = new Framework::Vertex3D[24];
|
|
|
|
|
+ for (int i = 0; i < 24; i++)
|
|
|
|
|
+ vertecies[i].knochenId = 0;
|
|
|
|
|
+ // front side
|
|
|
|
|
+ vertecies[0].pos = Framework::Vec3<float>(left, front, top);
|
|
|
|
|
+ vertecies[0].tPos = Framework::Vec2<float>(0.f, 0.f);
|
|
|
|
|
+ vertecies[1].pos = Framework::Vec3<float>(right, front, top);
|
|
|
|
|
+ vertecies[1].tPos = Framework::Vec2<float>(1.f, 0.f);
|
|
|
|
|
+ vertecies[2].pos = Framework::Vec3<float>(left, front, bottom);
|
|
|
|
|
+ vertecies[2].tPos = Framework::Vec2<float>(0.f, 1.f);
|
|
|
|
|
+ vertecies[3].pos = Framework::Vec3<float>(right, front, bottom);
|
|
|
|
|
+ vertecies[3].tPos = Framework::Vec2<float>(1.f, 1.f);
|
|
|
|
|
+ // back side
|
|
|
|
|
+ vertecies[4].pos = Framework::Vec3<float>(right, back, top);
|
|
|
|
|
+ vertecies[4].tPos = Framework::Vec2<float>(0.0f, 0.0f);
|
|
|
|
|
+ vertecies[5].pos = Framework::Vec3<float>(left, back, top);
|
|
|
|
|
+ vertecies[5].tPos = Framework::Vec2<float>(1.0f, 0.0f);
|
|
|
|
|
+ vertecies[6].pos = Framework::Vec3<float>(right, back, bottom);
|
|
|
|
|
+ vertecies[6].tPos = Framework::Vec2<float>(0.0f, 1.0f);
|
|
|
|
|
+ vertecies[7].pos = Framework::Vec3<float>(left, back, bottom);
|
|
|
|
|
+ vertecies[7].tPos = Framework::Vec2<float>(1.0f, 1.0f);
|
|
|
|
|
+ // left side
|
|
|
|
|
+ vertecies[8].pos = Framework::Vec3<float>(left, back, top);
|
|
|
|
|
+ vertecies[8].tPos = Framework::Vec2<float>(0.f, 0.f);
|
|
|
|
|
+ vertecies[9].pos = Framework::Vec3<float>(left, front, top);
|
|
|
|
|
+ vertecies[9].tPos = Framework::Vec2<float>(1.f, 0.f);
|
|
|
|
|
+ vertecies[10].pos = Framework::Vec3<float>(left, back, bottom);
|
|
|
|
|
+ vertecies[10].tPos = Framework::Vec2<float>(0.f, 1.f);
|
|
|
|
|
+ vertecies[11].pos = Framework::Vec3<float>(left, front, bottom);
|
|
|
|
|
+ vertecies[11].tPos = Framework::Vec2<float>(1.f, 1.f);
|
|
|
|
|
+ // right side
|
|
|
|
|
+ vertecies[12].pos = Framework::Vec3<float>(right, front, top);
|
|
|
|
|
+ vertecies[12].tPos = Framework::Vec2<float>(0.0f, 0.0f);
|
|
|
|
|
+ vertecies[13].pos = Framework::Vec3<float>(right, back, top);
|
|
|
|
|
+ vertecies[13].tPos = Framework::Vec2<float>(1.0f, 0.0f);
|
|
|
|
|
+ vertecies[14].pos = Framework::Vec3<float>(right, front, bottom);
|
|
|
|
|
+ vertecies[14].tPos = Framework::Vec2<float>(0.0f, 1.0f);
|
|
|
|
|
+ vertecies[15].pos = Framework::Vec3<float>(right, back, bottom);
|
|
|
|
|
+ vertecies[15].tPos = Framework::Vec2<float>(1.0f, 1.0f);
|
|
|
|
|
+ // top side
|
|
|
|
|
+ vertecies[16].pos = Framework::Vec3<float>(left, back, top);
|
|
|
|
|
+ vertecies[16].tPos = Framework::Vec2<float>(0.f, 0.f);
|
|
|
|
|
+ vertecies[17].pos = Framework::Vec3<float>(right, back, top);
|
|
|
|
|
+ vertecies[17].tPos = Framework::Vec2<float>(1.f, 0.f);
|
|
|
|
|
+ vertecies[18].pos = Framework::Vec3<float>(left, front, top);
|
|
|
|
|
+ vertecies[18].tPos = Framework::Vec2<float>(0.f, 1.f);
|
|
|
|
|
+ vertecies[19].pos = Framework::Vec3<float>(right, front, top);
|
|
|
|
|
+ vertecies[19].tPos = Framework::Vec2<float>(1.f, 1.f);
|
|
|
|
|
+ // botom side
|
|
|
|
|
+ vertecies[20].pos = Framework::Vec3<float>(left, front, bottom);
|
|
|
|
|
+ vertecies[20].tPos = Framework::Vec2<float>(0.0f, 0.0f);
|
|
|
|
|
+ vertecies[21].pos = Framework::Vec3<float>(right, front, bottom);
|
|
|
|
|
+ vertecies[21].tPos = Framework::Vec2<float>(1.0f, 0.0f);
|
|
|
|
|
+ vertecies[22].pos = Framework::Vec3<float>(left, back, bottom);
|
|
|
|
|
+ vertecies[22].tPos = Framework::Vec2<float>(0.0f, 1.0f);
|
|
|
|
|
+ vertecies[23].pos = Framework::Vec3<float>(right, back, bottom);
|
|
|
|
|
+ vertecies[23].tPos = Framework::Vec2<float>(1.0f, 1.0f);
|
|
|
|
|
+
|
|
|
|
|
+ data->setVertecies(vertecies, 24);
|
|
|
|
|
+ // the order of the polygons has to be NORTH (front), EAST (left),
|
|
|
|
|
+ // SOUTH (back), WEST (right), TOP, BOTTOM according to the Area
|
|
|
|
|
+ // definition front side
|
|
|
|
|
+ Framework::Polygon3D* p
|
|
|
|
|
+ = new Framework::Polygon3D(); // looking from (0,0,0) to (1,0,0)
|
|
|
|
|
+ // to see this side
|
|
|
|
|
+ p->indexAnz = 6;
|
|
|
|
|
+ p->indexList = new int[p->indexAnz];
|
|
|
|
|
+ p->indexList[0] = 0;
|
|
|
|
|
+ p->indexList[1] = 1;
|
|
|
|
|
+ p->indexList[2] = 2;
|
|
|
|
|
+ p->indexList[3] = 1;
|
|
|
|
|
+ p->indexList[4] = 3;
|
|
|
|
|
+ p->indexList[5] = 2;
|
|
|
|
|
+ data->addPolygon(p);
|
|
|
|
|
+ // left side
|
|
|
|
|
+ p = new Framework::Polygon3D(); // looking from (0,0,0) to (0,1,0)
|
|
|
|
|
+ // to see this
|
|
|
|
|
+ // side
|
|
|
|
|
+ p->indexAnz = 6;
|
|
|
|
|
+ p->indexList = new int[p->indexAnz];
|
|
|
|
|
+ p->indexList[0] = 0 + 8;
|
|
|
|
|
+ p->indexList[1] = 1 + 8;
|
|
|
|
|
+ p->indexList[2] = 2 + 8;
|
|
|
|
|
+ p->indexList[3] = 1 + 8;
|
|
|
|
|
+ p->indexList[4] = 3 + 8;
|
|
|
|
|
+ p->indexList[5] = 2 + 8;
|
|
|
|
|
+ data->addPolygon(p);
|
|
|
|
|
+ // back side
|
|
|
|
|
+ p = new Framework::Polygon3D(); // looking from (0,0,0) to (-1,0,0)
|
|
|
|
|
+ // to see this
|
|
|
|
|
+ // side
|
|
|
|
|
+ p->indexAnz = 6;
|
|
|
|
|
+ p->indexList = new int[p->indexAnz];
|
|
|
|
|
+ p->indexList[0] = 0 + 4;
|
|
|
|
|
+ p->indexList[1] = 1 + 4;
|
|
|
|
|
+ p->indexList[2] = 2 + 4;
|
|
|
|
|
+ p->indexList[3] = 1 + 4;
|
|
|
|
|
+ p->indexList[4] = 3 + 4;
|
|
|
|
|
+ p->indexList[5] = 2 + 4;
|
|
|
|
|
+ data->addPolygon(p);
|
|
|
|
|
+ // right side
|
|
|
|
|
+ p = new Framework::Polygon3D(); // looking from (0,0,0) to (0,-1,0)
|
|
|
|
|
+ // to see this
|
|
|
|
|
+ // side
|
|
|
|
|
+ p->indexAnz = 6;
|
|
|
|
|
+ p->indexList = new int[p->indexAnz];
|
|
|
|
|
+ p->indexList[0] = 0 + 12;
|
|
|
|
|
+ p->indexList[1] = 1 + 12;
|
|
|
|
|
+ p->indexList[2] = 2 + 12;
|
|
|
|
|
+ p->indexList[3] = 1 + 12;
|
|
|
|
|
+ p->indexList[4] = 3 + 12;
|
|
|
|
|
+ p->indexList[5] = 2 + 12;
|
|
|
|
|
+ data->addPolygon(p);
|
|
|
|
|
+ // top side
|
|
|
|
|
+ p = new Framework::Polygon3D(); // looking from (0,0,0) to (0,0,-1)
|
|
|
|
|
+ // to see this
|
|
|
|
|
+ // side
|
|
|
|
|
+ p->indexAnz = 6;
|
|
|
|
|
+ p->indexList = new int[p->indexAnz];
|
|
|
|
|
+ p->indexList[0] = 0 + 16;
|
|
|
|
|
+ p->indexList[1] = 1 + 16;
|
|
|
|
|
+ p->indexList[2] = 2 + 16;
|
|
|
|
|
+ p->indexList[3] = 1 + 16;
|
|
|
|
|
+ p->indexList[4] = 3 + 16;
|
|
|
|
|
+ p->indexList[5] = 2 + 16;
|
|
|
|
|
+ data->addPolygon(p);
|
|
|
|
|
+ // botom side
|
|
|
|
|
+ p = new Framework::Polygon3D(); // looking from (0,0,0) to (0,0,1)
|
|
|
|
|
+ // to see this
|
|
|
|
|
+ // side
|
|
|
|
|
+ p->indexAnz = 6;
|
|
|
|
|
+ p->indexList = new int[p->indexAnz];
|
|
|
|
|
+ p->indexList[0] = 0 + 20;
|
|
|
|
|
+ p->indexList[1] = 1 + 20;
|
|
|
|
|
+ p->indexList[2] = 2 + 20;
|
|
|
|
|
+ p->indexList[3] = 1 + 20;
|
|
|
|
|
+ p->indexList[4] = 3 + 20;
|
|
|
|
|
+ p->indexList[5] = 2 + 20;
|
|
|
|
|
+ data->addPolygon(p);
|
|
|
|
|
+ data->calculateNormals();
|
|
|
|
|
+ cube.setModelData(data);
|
|
|
|
|
+ cube.setPosition(0, 100, 0);
|
|
|
|
|
+ cube.setSize(50);
|
|
|
|
|
+ cube.setRotation(0.5, 0.5, 0.5);
|
|
|
|
|
+ cube.tick(0.1);
|
|
|
|
|
+ world.addDrawable(
|
|
|
|
|
+ dynamic_cast<Framework::Model3D*>(cube.getThis()));
|
|
|
|
|
+
|
|
|
|
|
+ cam.setWorld(dynamic_cast<Framework::World3D*>(world.getThis()));
|
|
|
|
|
+ cam.addStyle(Framework::Cam3D::Style::Movable
|
|
|
|
|
+ | Framework::Cam3D::Style::Rotatable
|
|
|
|
|
+ | Framework::Cam3D::Style::Zoomable
|
|
|
|
|
+ | Framework::Cam3D::Style::Tick);
|
|
|
|
|
+ screen.addKamera(dynamic_cast<Framework::Cam3D*>(cam.getThis()));
|
|
|
|
|
+
|
|
|
|
|
+ Framework::RenderTh rTh;
|
|
|
|
|
+ rTh.setMaxFps(-1);
|
|
|
|
|
+ rTh.setQuiet(0);
|
|
|
|
|
+ rTh.setScreen(dynamic_cast<Framework::Screen*>(screen.getThis()));
|
|
|
|
|
+ rTh.setTickFunktion([&cube](void* p, void* f, double tick) {
|
|
|
|
|
+ cube.setRotationX(cube.getXRotation() + tick);
|
|
|
|
|
+ cube.setRotationY(cube.getXRotation() + tick / 10);
|
|
|
|
|
+ cube.setRotationZ(cube.getXRotation() + tick / 50);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ rTh.beginn();
|
|
|
|
|
+ Framework::StartMessageLoop();
|
|
|
|
|
+ rTh.terminate();
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+} // namespace FrameworkTests
|