From 3809195d2351bc47b0962827cd90c8bdc7926e3f Mon Sep 17 00:00:00 2001 From: turanszkij Date: Sun, 1 May 2016 19:02:57 +0200 Subject: [PATCH] update --- ScriptingAPI-Documentation.md | 18 ++++++++ WickedEngine/MainComponent.cpp | 6 ++- WickedEngine/luminancePass2CS.hlsl | 2 +- WickedEngine/wiGraphicsAPI_DX11.cpp | 2 + WickedEngine/wiInputManager.cpp | 34 ++++++++++++++- WickedEngine/wiInputManager.h | 12 +++--- WickedEngine/wiInputManager_BindLua.cpp | 57 ++++++++++++++++++++++++- WickedEngine/wiInputManager_BindLua.h | 21 ++++++++- WickedEngine/wiRenderer.cpp | 25 ++++++----- WickedEngine/wiVersion.cpp | 2 +- 10 files changed, 156 insertions(+), 23 deletions(-) diff --git a/ScriptingAPI-Documentation.md b/ScriptingAPI-Documentation.md index 6da97250b..6b49961b9 100644 --- a/ScriptingAPI-Documentation.md +++ b/ScriptingAPI-Documentation.md @@ -525,11 +525,29 @@ A TCP client which provides features to communicate with other clients over the ### Input Handling These provide functions to check the state of the input devices. + +#### InputManager +Query input devices - [outer]input : InputManager - [void-constructor]InputManager() - Down(int code, opt int type = KEYBOARD) - Press(int code, opt int type = KEYBOARD) - Hold(int code, opt int duration = 30, opt boolean continuous = false, opt int type = KEYBOARD) +- GetPointer() : Vector result +- SetPointer(Vector pos) +- HidePointer(bool visible) +- GetTouches() : Touch result[] + +#### Touch +Describes a touch contact point +- [constructor]Touch() +- GetState() : TOUCHSTATE result +- GetPos() : Vector result + +#### TOUCHSTATE +- [outer]TOUCHSTATE_PRESSED : int +- [outer]TOUCHSTATE_RELEASED : int +- [outer]TOUCHSTATE_MOVED : int #### Input types - [outer]DIRECTINPUT_JOYPAD : int diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index 5206fd0a0..ad316cf5f 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -101,7 +101,7 @@ void MainComponent::run() Update(); } - getActiveComponent()->FixedUpdate(elapsedTime); + getActiveComponent()->FixedUpdate((float)elapsedTime); Render(); @@ -112,6 +112,8 @@ void MainComponent::run() wiLua::GetGlobal()->RunFile("startup.lua"); startupScriptProcessed = true; } + + wiInputManager::ManageTouches(); } void MainComponent::Update() @@ -211,6 +213,8 @@ bool MainComponent::setWindow(Windows::UI::Core::CoreWindow^ window) screenH = (int)window->Bounds.Height; wiRenderer::InitDevice(window); + this->window = window; + return true; } #endif diff --git a/WickedEngine/luminancePass2CS.hlsl b/WickedEngine/luminancePass2CS.hlsl index 40b1bd7f1..bfc420df6 100644 --- a/WickedEngine/luminancePass2CS.hlsl +++ b/WickedEngine/luminancePass2CS.hlsl @@ -28,5 +28,5 @@ void main( } if (groupIndex != 0) { return; } - tex_accumulator[uint2(0,0)] = lerp(tex_accumulator.Load(uint2(0,0)), accumulator[0], 0.04f); + tex_accumulator[uint2(0,0)] = lerp(tex_accumulator.Load(uint2(0,0)), accumulator[0], 0.08f); } diff --git a/WickedEngine/wiGraphicsAPI_DX11.cpp b/WickedEngine/wiGraphicsAPI_DX11.cpp index e69ed798a..fdbf977f0 100644 --- a/WickedEngine/wiGraphicsAPI_DX11.cpp +++ b/WickedEngine/wiGraphicsAPI_DX11.cpp @@ -19,7 +19,9 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(Windows::UI::Core::CoreWindow^ window) UINT createDeviceFlags = 0; #ifdef _DEBUG +#ifndef WINSTORE_SUPPORT createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; +#endif #endif D3D_DRIVER_TYPE driverTypes[] = diff --git a/WickedEngine/wiInputManager.cpp b/WickedEngine/wiInputManager.cpp index 301771905..a74215dec 100644 --- a/WickedEngine/wiInputManager.cpp +++ b/WickedEngine/wiInputManager.cpp @@ -7,6 +7,7 @@ wiXInput* wiInputManager::xinput = nullptr; wiDirectInput* wiInputManager::dinput = nullptr; wiRawInput* wiInputManager::rawinput = nullptr; wiInputManager::InputCollection wiInputManager::inputs; +vector wiInputManager::touches; #ifndef WINSTORE_SUPPORT #define KEY_DOWN(vk_code) (GetAsyncKeyState(vk_code) < 0) @@ -159,23 +160,43 @@ using namespace Windows::ApplicationModel::Activation; using namespace Windows::UI::Core; using namespace Windows::UI::Input; using namespace Windows::System; -using namespace Windows::Foundation; +using namespace Windows::Foundation; + +void AddTouch(const wiInputManager::Touch& touch) +{ + wiInputManager::touches.push_back(touch); +} void _OnPointerPressed(CoreWindow^ window, PointerEventArgs^ pointer) { auto p = pointer->CurrentPoint; + + wiInputManager::Touch touch; + touch.state = wiInputManager::Touch::TOUCHSTATE_PRESSED; + touch.pos = XMFLOAT2(p->Position.X, p->Position.Y); + AddTouch(touch); } void _OnPointerReleased(CoreWindow^ window, PointerEventArgs^ pointer) { auto p = pointer->CurrentPoint; + + wiInputManager::Touch touch; + touch.state = wiInputManager::Touch::TOUCHSTATE_RELEASED; + touch.pos = XMFLOAT2(p->Position.X, p->Position.Y); + AddTouch(touch); } void _OnPointerMoved(CoreWindow^ window, PointerEventArgs^ pointer) { auto p = pointer->CurrentPoint; + + wiInputManager::Touch touch; + touch.state = wiInputManager::Touch::TOUCHSTATE_MOVED; + touch.pos = XMFLOAT2(p->Position.X, p->Position.Y); + AddTouch(touch); } #endif // WINSTORE_SUPPORT -wiInputManager::Touch wiInputManager::touch() +vector wiInputManager::getTouches() { static bool isRegisteredTouch = false; if (!isRegisteredTouch) @@ -187,5 +208,14 @@ wiInputManager::Touch wiInputManager::touch() window->PointerReleased += ref new TypedEventHandler(_OnPointerReleased); window->PointerMoved += ref new TypedEventHandler(_OnPointerMoved); #endif // WINSTORE_SUPPORT + + isRegisteredTouch = true; } + + return touches; +} + +void wiInputManager::ManageTouches() +{ + touches.clear(); } diff --git a/WickedEngine/wiInputManager.h b/WickedEngine/wiInputManager.h index 0cd9b4f59..98a780265 100644 --- a/WickedEngine/wiInputManager.h +++ b/WickedEngine/wiInputManager.h @@ -72,12 +72,14 @@ public: } state; // current position of touch XMFLOAT2 pos; - // velocity of swipe - XMFLOAT2 delta; - // true if two touches occured in a rapid succession in the same spot - bool doubleClick; }; - static Touch touch(); + static vector getTouches(); + static void ManageTouches(); + +private: + static vector touches; + + friend void AddTouch(const wiInputManager::Touch& touch); }; diff --git a/WickedEngine/wiInputManager_BindLua.cpp b/WickedEngine/wiInputManager_BindLua.cpp index 3f798633c..f8965ccd2 100644 --- a/WickedEngine/wiInputManager_BindLua.cpp +++ b/WickedEngine/wiInputManager_BindLua.cpp @@ -1,5 +1,4 @@ #include "wiInputManager_BindLua.h" -#include "wiInputManager.h" #include "Vector_BindLua.h" const char wiInputManager_BindLua::className[] = "InputManager"; @@ -11,13 +10,13 @@ Luna::FunctionType wiInputManager_BindLua::methods[] = { lunamethod(wiInputManager_BindLua, GetPointer), lunamethod(wiInputManager_BindLua, SetPointer), lunamethod(wiInputManager_BindLua, HidePointer), + lunamethod(wiInputManager_BindLua, GetTouches), { NULL, NULL } }; Luna::PropertyType wiInputManager_BindLua::properties[] = { { NULL, NULL } }; - int wiInputManager_BindLua::Down(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -117,6 +116,15 @@ int wiInputManager_BindLua::HidePointer(lua_State* L) wiLua::SError(L, "HidePointer(bool value) not enough arguments!"); return 0; } +int wiInputManager_BindLua::GetTouches(lua_State* L) +{ + auto& touches = wiInputManager::getTouches(); + for (auto& touch : touches) + { + Luna::push(L, new Touch_BindLua(touch)); + } + return touches.size(); +} void wiInputManager_BindLua::Bind() { @@ -159,5 +167,50 @@ void wiInputManager_BindLua::Bind() wiLua::GetGlobal()->RunText("VK_LBUTTON = 0x01"); wiLua::GetGlobal()->RunText("VK_MBUTTON = 0x04"); wiLua::GetGlobal()->RunText("VK_RBUTTON = 0x02"); + + //Touch + wiLua::GetGlobal()->RunText("TOUCHSTATE_PRESSED = 0"); + wiLua::GetGlobal()->RunText("TOUCHSTATE_RELEASED = 1"); + wiLua::GetGlobal()->RunText("TOUCHSTATE_MOVED = 2"); + } + + Touch_BindLua::Bind(); +} + + + + + + + +const char Touch_BindLua::className[] = "Touch"; + +Luna::FunctionType Touch_BindLua::methods[] = { + lunamethod(Touch_BindLua, GetState), + lunamethod(Touch_BindLua, GetPos), + { NULL, NULL } +}; +Luna::PropertyType Touch_BindLua::properties[] = { + { NULL, NULL } +}; + +int Touch_BindLua::GetState(lua_State* L) +{ + wiLua::SSetInt(L, (int)touch.state); + return 1; +} +int Touch_BindLua::GetPos(lua_State* L) +{ + Luna::push(L, new Vector_BindLua(XMLoadFloat2(&touch.pos))); + return 1; +} + +void Touch_BindLua::Bind() +{ + static bool initialized = false; + if (!initialized) + { + initialized = true; + Luna::Register(wiLua::GetGlobal()->GetLuaState()); } } diff --git a/WickedEngine/wiInputManager_BindLua.h b/WickedEngine/wiInputManager_BindLua.h index 7b4f27463..abda3a317 100644 --- a/WickedEngine/wiInputManager_BindLua.h +++ b/WickedEngine/wiInputManager_BindLua.h @@ -1,6 +1,7 @@ #pragma once #include "wiLua.h" #include "wiLuna.h" +#include "wiInputManager.h" class wiInputManager_BindLua { @@ -18,7 +19,25 @@ public: int GetPointer(lua_State* L); int SetPointer(lua_State* L); int HidePointer(lua_State* L); - + int GetTouches(lua_State* L); + + static void Bind(); +}; + +class Touch_BindLua +{ +public: + wiInputManager::Touch touch; + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + Touch_BindLua(lua_State* L) {} + Touch_BindLua(const wiInputManager::Touch& touch) :touch(touch) {} + ~Touch_BindLua() {} + + int GetState(lua_State* L); + int GetPos(lua_State* L); static void Bind(); }; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 13598051a..3eb31d52f 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -3041,7 +3041,7 @@ void wiRenderer::RayIntersectMeshes(const RAY& ray, const CulledList& culledObje } XMVECTOR& rayOrigin = XMLoadFloat3(&ray.origin); - XMVECTOR& rayDirection = XMLoadFloat3(&ray.direction); + XMVECTOR& rayDirection = XMVector3Normalize(XMLoadFloat3(&ray.direction)); for (Cullable* culled : culledObjects){ Object* object = (Object*)culled; @@ -3072,23 +3072,28 @@ void wiRenderer::RayIntersectMeshes(const RAY& ray, const CulledList& culledObje Mesh* mesh = object->mesh; XMMATRIX& objectMat = XMLoadFloat4x4(&object->world); + XMMATRIX objectMat_Inverse = XMMatrixInverse(nullptr, objectMat); + + XMVECTOR& rayOrigin_local = XMVector3Transform(rayOrigin, objectMat_Inverse); + XMVECTOR& rayDirection_local = XMVector3Normalize(XMVector3TransformNormal(rayDirection, objectMat_Inverse)); for (unsigned int i = 0; iindices.size(); i += 3){ int i0 = mesh->indices[i], i1 = mesh->indices[i + 1], i2 = mesh->indices[i + 2]; - Vertex& v0 = mesh->skinnedVertices[i0], v1 = mesh->skinnedVertices[i1], v2 = mesh->skinnedVertices[i2]; - XMVECTOR& V0 = - XMVector4Transform(XMLoadFloat4(&v0.pos), objectMat) - , V1 = XMVector4Transform(XMLoadFloat4(&v1.pos), objectMat) - , V2 = XMVector4Transform(XMLoadFloat4(&v2.pos), objectMat); + Vertex& v0 = mesh->skinnedVertices[i0]; + Vertex& v1 = mesh->skinnedVertices[i1]; + Vertex& v2 = mesh->skinnedVertices[i2]; + XMVECTOR& V0 = XMLoadFloat4(&v0.pos); + XMVECTOR& V1 = XMLoadFloat4(&v1.pos); + XMVECTOR& V2 = XMLoadFloat4(&v2.pos); float distance = 0; - if (TriangleTests::Intersects(rayOrigin, rayDirection, V0, V1, V2, distance)){ - XMVECTOR& pos = XMVectorAdd(rayOrigin, rayDirection*distance); - XMVECTOR& nor = XMVector3Normalize(XMVector3Cross(XMVectorSubtract(V2, V1), XMVectorSubtract(V1, V0))); + if (TriangleTests::Intersects(rayOrigin_local, rayDirection_local, V0, V1, V2, distance)){ + XMVECTOR& pos = XMVector3Transform(XMVectorAdd(rayOrigin_local, rayDirection_local*distance), objectMat); + XMVECTOR& nor = XMVector3TransformNormal(XMVector3Normalize(XMVector3Cross(XMVectorSubtract(V2, V1), XMVectorSubtract(V1, V0))), objectMat); Picked picked = Picked(); picked.object = object; XMStoreFloat3(&picked.position, pos); XMStoreFloat3(&picked.normal, nor); - picked.distance = distance; + picked.distance = wiMath::Distance(pos, rayOrigin); points.push_back(picked); } } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 18c5731a8..7e1fd8c15 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -7,7 +7,7 @@ namespace wiVersion // minor features, major bug fixes const int minor = 7; // minor bug fixes, alterations, refactors - const int revision = 5; + const int revision = 6; long GetVersion()