diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index 10c6ca5be..6bfff723c 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -139,11 +139,17 @@ Gives you the ability to render text with a custom font. - [outer]WIFALIGN_RIGHT : int - [outer]WIFALIGN_TOP : int - [outer]WIFALIGN_BOTTOM : int +- SetColor(Vector color) +- SetColor(int colorHexCode) +- SetShadowColor(Vector shadowcolor) +- SetShadowColor(int colorHexCode) - GetText() : string result - GetSize() : int result - GetPos() : Vector result - GetSpacing() : Vector result - GetAlign() : WIFALIGN halign,valign +- GetColor() : Vector result +- GetShadowColor() : Vector result - Destroy() ### Sprite diff --git a/WickedEngine/wiFont_BindLua.cpp b/WickedEngine/wiFont_BindLua.cpp index a98548d2c..7aaf9305a 100644 --- a/WickedEngine/wiFont_BindLua.cpp +++ b/WickedEngine/wiFont_BindLua.cpp @@ -13,6 +13,8 @@ Luna::FunctionType wiFont_BindLua::methods[] = { lunamethod(wiFont_BindLua, SetPos), lunamethod(wiFont_BindLua, SetSpacing), lunamethod(wiFont_BindLua, SetAlign), + lunamethod(wiFont_BindLua, SetColor), + lunamethod(wiFont_BindLua, SetShadowColor), lunamethod(wiFont_BindLua, SetStyle), lunamethod(wiFont_BindLua, SetText), @@ -20,6 +22,8 @@ Luna::FunctionType wiFont_BindLua::methods[] = { lunamethod(wiFont_BindLua, GetPos), lunamethod(wiFont_BindLua, GetSpacing), lunamethod(wiFont_BindLua, GetAlign), + lunamethod(wiFont_BindLua, GetColor), + lunamethod(wiFont_BindLua, GetShadowColor), lunamethod(wiFont_BindLua, Destroy), { NULL, NULL } @@ -136,6 +140,50 @@ int wiFont_BindLua::SetAlign(lua_State* L) wiLua::SError(L, "SetAlign(WIFALIGN Halign, opt WIFALIGN Valign) not enough arguments!"); return 0; } +int wiFont_BindLua::SetColor(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Vector_BindLua* param = Luna::lightcheck(L, 1); + if (param != nullptr) + { + XMFLOAT4 unpacked; + XMStoreFloat4(&unpacked, param->vector); + font->params.color = wiColor::fromFloat4(unpacked); + } + else + { + int code = wiLua::SGetInt(L, 1); + font->params.color.rgba = *((uint32_t*)&code); + } + } + else + wiLua::SError(L, "SetColor(Vector pos) not enough arguments!"); + return 0; +} +int wiFont_BindLua::SetShadowColor(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Vector_BindLua* param = Luna::lightcheck(L, 1); + if (param != nullptr) + { + XMFLOAT4 unpacked; + XMStoreFloat4(&unpacked, param->vector); + font->params.shadowColor = wiColor::fromFloat4(unpacked); + } + else + { + int code = wiLua::SGetInt(L, 1); + font->params.shadowColor.rgba = *((uint32_t*)&code); + } + } + else + wiLua::SError(L, "SetShadowColor(Vector pos) not enough arguments!"); + return 0; +} int wiFont_BindLua::GetText(lua_State* L) { @@ -163,6 +211,16 @@ int wiFont_BindLua::GetAlign(lua_State* L) wiLua::SSetInt(L, font->params.v_align); return 2; } +int wiFont_BindLua::GetColor(lua_State* L) +{ + Luna::push(L, new Vector_BindLua(XMLoadFloat4(&font->params.color.toFloat4()))); + return 1; +} +int wiFont_BindLua::GetShadowColor(lua_State* L) +{ + Luna::push(L, new Vector_BindLua(XMLoadFloat4(&font->params.color.toFloat4()))); + return 1; +} int wiFont_BindLua::Destroy(lua_State* L) { diff --git a/WickedEngine/wiFont_BindLua.h b/WickedEngine/wiFont_BindLua.h index 7ad69e09f..802488b74 100644 --- a/WickedEngine/wiFont_BindLua.h +++ b/WickedEngine/wiFont_BindLua.h @@ -23,12 +23,16 @@ public: int SetPos(lua_State* L); int SetSpacing(lua_State* L); int SetAlign(lua_State* L); + int SetColor(lua_State* L); + int SetShadowColor(lua_State* L); int GetText(lua_State* L); int GetSize(lua_State* L); int GetPos(lua_State* L); int GetSpacing(lua_State* L); int GetAlign(lua_State* L); + int GetColor(lua_State* L); + int GetShadowColor(lua_State* L); int Destroy(lua_State* L); diff --git a/WickedEngine/wiSceneSystem_BindLua.cpp b/WickedEngine/wiSceneSystem_BindLua.cpp index 88980aea7..9a70a3668 100644 --- a/WickedEngine/wiSceneSystem_BindLua.cpp +++ b/WickedEngine/wiSceneSystem_BindLua.cpp @@ -82,7 +82,7 @@ int Pick(lua_State* L) return 4; } - wiLua::SError(L, "Pick(Ray ray, opt PICKTYPE pickType, opt uint layerMask) first argument must be of Vector type!"); + wiLua::SError(L, "Pick(Ray ray, opt PICKTYPE pickType, opt uint layerMask) first argument must be of Ray type!"); } else { diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 043f7cecb..de2e85425 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 26; // minor bug fixes, alterations, refactors, updates - const int revision = 8; + const int revision = 9; long GetVersion() diff --git a/scripts/character_controller_tps.lua b/scripts/character_controller_tps.lua index 3feaf74ca..45e74935f 100644 --- a/scripts/character_controller_tps.lua +++ b/scripts/character_controller_tps.lua @@ -6,6 +6,8 @@ -- SHIFT: speed -- SPACE: Jump -- Right Mouse Button: rotate camera +-- Scoll middle mouse: adjust camera distance +-- ESCAPE key: quit local scene = GetScene() @@ -217,6 +219,7 @@ ThirdPersonCamera = { side_offset = 1, height = 0, rest_distance = 6, + rest_distance_new = 6, Create = function(self, character) self.character = character @@ -228,6 +231,11 @@ ThirdPersonCamera = { Update = function(self) if(self.character ~= nil) then + -- Mouse scroll will move the camera distance: + local mouse_scroll = input.GetPointer().GetZ() -- pointer.z is the mouse wheel delta this frame + self.rest_distance_new = math.max(self.rest_distance_new - mouse_scroll, 2) -- do not allow too close using max + self.rest_distance = math.lerp(self.rest_distance, self.rest_distance_new, 0.1) -- lerp will smooth out the zooming + -- We update the scene so that character's target_transform will be using up to date values scene.Update(0) @@ -319,6 +327,14 @@ runProcess(function() path.SetLightShaftsEnabled(true) main.SetActivePath(path) + local font = Font("This script is showcasing how to perform scene collision with raycasts for character and camera.\nControls:\n#####################\n\nWASD/arrows: walk\nSHIFT: movement speed\nSPACE: Jump\nRight Mouse Button: rotate camera\nScoll middle mouse: adjust camera distance\nESCAPE key: quit"); + font.SetSize(38) + font.SetPos(Vector(10, GetScreenHeight() - 10)) + font.SetAlign(WIFALIGN_LEFT, WIFALIGN_BOTTOM) + font.SetColor(0xFFADA3FF) + font.SetShadowColor(Vector(0,0,0,1)) + path.AddFont(font) + LoadModel("../models/playground.wiscene") player:Create(LoadModel("../models/girl.wiscene")) @@ -351,9 +367,7 @@ end) --- Debug draw: - --- Draw Helpers +-- Debug Draw Helper local DrawAxis = function(point,f) DrawLine(point,point:Add(Vector(f,0,0)),Vector(1,0,0,1)) DrawLine(point,point:Add(Vector(0,f,0)),Vector(0,1,0,1)) @@ -364,16 +378,17 @@ end runProcess(function() while true do + + -- Do some debug draw geometry: - while( backlog_isactive() ) do + -- If backlog is opened, skip debug draw: + while(backlog_isactive()) do waitSeconds(1) end local model_transform = scene.Component_GetTransform(player.model) local target_transform = scene.Component_GetTransform(player.target) - -- Drawing additional render data (slow, only for debug purposes) - --velocity DrawLine(target_transform.GetPosition(),target_transform.GetPosition():Add(player.velocity)) --face