Quantcast

* Fixed the wide-screen issue with arrow models, thanks to Iriel and magic constants

James Whitehead Ii [07-10-07 - 21:34]
* Fixed the wide-screen issue with arrow models, thanks to Iriel and magic constants
Filename
DongleFrames.lua
TomTom.lua
diff --git a/DongleFrames.lua b/DongleFrames.lua
index 9a27dd4..f6bde65 100755
--- a/DongleFrames.lua
+++ b/DongleFrames.lua
@@ -1,165 +1,165 @@
-local major = "DongleFrames-1.0"
-local minor = tonumber(string.match("$Revision: 249 $", "(%d+)") or 1)
-
-assert(DongleStub, string.format("%s requires DongleStub.", major))
-if not DongleStub:IsNewerVersion(major, minor) then return end
-
---[[-------------------------------------------------------------------------
-  Library implementation
----------------------------------------------------------------------------]]
-
-local lib = {}
-
--- Iterator written by Iriel taken from SecureStateHeader.lua
-local function splitNext(sep, body)
-    if (body) then
-        local pre, post = string.split(sep, body, 2)
-        if (post) then
-            return post, pre
-        end
-        return false, body
-    end
-end
-local function commaIterator(str) return splitNext, ",", str end
-local function semicolonIterator(str) return splitNext, ";", str end
-local function poundIterator(str) return splitNext, "#", str end
-
-local function tonumberAll(...)
-    local n = select("#",...)
-    if n < 1 then return
-    elseif n == 1 then return tonumber(...)
-    else return tonumber((...)),tonumberAll(select(2,...)) end
-end
-
-local handlers
-
-local function stripAttribute(name, attribs)
-    local pattern = "#"..name
-    if attribs:match(pattern.."#") or attribs:match(pattern.."$") then
-        attribs = attribs:gsub(pattern,"")
-        return nil,attribs
-    else
-        pattern = pattern.."=([^#]*)"
-        local value = attribs:match(pattern)
-        attribs = attribs:gsub(pattern,"")
-        return value,attribs
-    end
-end
-
-local function parseBaseAttributes(attribs)
-    attribs = attribs:gsub("^#?","#")
-
-    local name,attribs = stripAttribute("n",attribs)
-    local template,attribs = stripAttribute("inh",attribs)
-    local frameType,attribs = stripAttribute("t",attribs)
-    local parent,attribs = stripAttribute("p",attribs)
-    return frameType,parent,name,template,attribs
-end
-
-local function parseHandlerString(frame,handler,value)
-    local t,method,regex = string.split(',',handler,3)
-    if regex then value = value:match(regex) end
-    if t == "number" then value = tonumber(value)
-    elseif t == "bool" then value = value == "true" and true or false
-    elseif t == "true" then value = true
-    elseif t == "false" then value = false
-    elseif t == "global" then value = getfenv(0)[value]
-    end
-    frame[method](frame,value)
-end
-
-function lib:Create(parent,attributes,...)
-    local sp1
-    if type(parent) ~= "table" then
-        sp1 = attributes
-        attributes = parent
-        parent = nil
-    end
-    if type(attributes) ~= "string" then return end
-    local objType,parent2,name,template,attributes = parseBaseAttributes(attributes)
-    parent = parent or parent2
-    if type(parent) == "string" then
-        parent = getfenv(0)[parent]
-    end
-
-    local obj
-    objType = objType and objType:lower() or "frame"
-    if objType == "texture" then
-        if not parent then return end -- TODO: Error here
-        obj = parent:CreateTexture(name,nil,template)
-    elseif objType == "fontstring" then
-        if not parent then return end -- TODO: Error here
-        obj = parent:CreateFontString(name,nil,template)
-    else
-        obj = CreateFrame(objType,name,parent,template)
-    end
-
-    for _,section in poundIterator(attributes) do
-        local attribute,value = section:match("^([^=]+)=?(.*)$")
-        local handler = handlers[attribute]
-        if type(handler) == "function" then handler(obj,value)
-        elseif type(handler) == "string" then
-            for _,handlerString in poundIterator(handler) do
-                parseHandlerString(obj,handlerString,value)
-            end
-        end
-    end
-
-    if sp1 then
-        obj:SetPoint(sp1,...)
-    elseif select("#",...) > 0 then
-        obj:SetPoint(...)
-    end
-    return obj
-end
-
-handlers = {
-    size = "number,SetWidth,(%d+)%s*[%s,]%s*%d+#number,SetHeight,%d+%s*[%s,]%s*(%d+)",
-    w = "number,SetWidth",
-    h = "number,SetHeight",
-    movable = "true,SetMovable",
-    mouse = "true,EnableMouse",
-    hide = "true,Hide",
-    clamp = "true,SetClampedToScreen",
-    mousewheel = "true,EnableMouseWheel",
-    toplevel = "true,SetToplevel",
-    click = "string,RegisterForClicks",
-    drag = "string,RegisterForDrag",
-    strata = "string,SetFrameStrata",
-    level = "number,SetFrameLevel",
-    a = "number,SetAlpha",
-    id = "number,SetID",
-    scale = "number,SetScale",
-    layer = "string,SetDrawLayer",
-    text = "string,SetText",
-	normtex = "string,SetNormalTexture",
-
-    sap = function(frame, value)
-        if value then value = getfenv(0)[value]
-        else value = frame:GetParent() end
-        if not value then return end
-        frame:SetAllPoints(value)
-    end,
-    tex = function(texture,value)
-        local r,g,b,a = value:match("^(%d?%.?%d*)%s*[,%s]%s*(%d?%.?%d*)%s*[,%s]%s*(%d?%.?%d*)$")
-        if not r then
-            r,g,b,a = value:match("^(%d?%.?%d*)%s*[,%s]%s*(%d?%.?%d*)%s*[,%s]%s*(%d?%.?%d*)%s*[,%s]%s*(%d?%.?%d*)$")
-        end
-        if r then
-            texture:SetTexture(tonumberAll(r,g,b),a and tonumber(a))
-        else
-            texture:SetTexture(value)
-        end
-    end,
-    texc = function(texture,value)
-        texture:SetTexCoord(tonumberAll(strsplit(',',value)))
-    end,
-}
-
---[[-------------------------------------------------------------------------
-  Library implementation
----------------------------------------------------------------------------]]
-
-function lib:GetVersion() return major,minor end
-
-DongleStub:Register(lib)
+local major = "DongleFrames-1.0"
+local minor = tonumber(string.match("$Revision: 249 $", "(%d+)") or 1)
+
+assert(DongleStub, string.format("%s requires DongleStub.", major))
+if not DongleStub:IsNewerVersion(major, minor) then return end
+
+--[[-------------------------------------------------------------------------
+  Library implementation
+---------------------------------------------------------------------------]]
+
+local lib = {}
+
+-- Iterator written by Iriel taken from SecureStateHeader.lua
+local function splitNext(sep, body)
+    if (body) then
+        local pre, post = string.split(sep, body, 2)
+        if (post) then
+            return post, pre
+        end
+        return false, body
+    end
+end
+local function commaIterator(str) return splitNext, ",", str end
+local function semicolonIterator(str) return splitNext, ";", str end
+local function poundIterator(str) return splitNext, "#", str end
+
+local function tonumberAll(...)
+    local n = select("#",...)
+    if n < 1 then return
+    elseif n == 1 then return tonumber(...)
+    else return tonumber((...)),tonumberAll(select(2,...)) end
+end
+
+local handlers
+
+local function stripAttribute(name, attribs)
+    local pattern = "#"..name
+    if attribs:match(pattern.."#") or attribs:match(pattern.."$") then
+        attribs = attribs:gsub(pattern,"")
+        return nil,attribs
+    else
+        pattern = pattern.."=([^#]*)"
+        local value = attribs:match(pattern)
+        attribs = attribs:gsub(pattern,"")
+        return value,attribs
+    end
+end
+
+local function parseBaseAttributes(attribs)
+    attribs = attribs:gsub("^#?","#")
+
+    local name,attribs = stripAttribute("n",attribs)
+    local template,attribs = stripAttribute("inh",attribs)
+    local frameType,attribs = stripAttribute("t",attribs)
+    local parent,attribs = stripAttribute("p",attribs)
+    return frameType,parent,name,template,attribs
+end
+
+local function parseHandlerString(frame,handler,value)
+    local t,method,regex = string.split(',',handler,3)
+    if regex then value = value:match(regex) end
+    if t == "number" then value = tonumber(value)
+    elseif t == "bool" then value = value == "true" and true or false
+    elseif t == "true" then value = true
+    elseif t == "false" then value = false
+    elseif t == "global" then value = getfenv(0)[value]
+    end
+    frame[method](frame,value)
+end
+
+function lib:Create(parent,attributes,...)
+    local sp1
+    if type(parent) ~= "table" then
+        sp1 = attributes
+        attributes = parent
+        parent = nil
+    end
+    if type(attributes) ~= "string" then return end
+    local objType,parent2,name,template,attributes = parseBaseAttributes(attributes)
+    parent = parent or parent2
+    if type(parent) == "string" then
+        parent = getfenv(0)[parent]
+    end
+
+    local obj
+    objType = objType and objType:lower() or "frame"
+    if objType == "texture" then
+        if not parent then return end -- TODO: Error here
+        obj = parent:CreateTexture(name,nil,template)
+    elseif objType == "fontstring" then
+        if not parent then return end -- TODO: Error here
+        obj = parent:CreateFontString(name,nil,template)
+    else
+        obj = CreateFrame(objType,name,parent,template)
+    end
+
+    for _,section in poundIterator(attributes) do
+        local attribute,value = section:match("^([^=]+)=?(.*)$")
+        local handler = handlers[attribute]
+        if type(handler) == "function" then handler(obj,value)
+        elseif type(handler) == "string" then
+            for _,handlerString in poundIterator(handler) do
+                parseHandlerString(obj,handlerString,value)
+            end
+        end
+    end
+
+    if sp1 then
+        obj:SetPoint(sp1,...)
+    elseif select("#",...) > 0 then
+        obj:SetPoint(...)
+    end
+    return obj
+end
+
+handlers = {
+    size = "number,SetWidth,(%d+)%s*[%s,]%s*%d+#number,SetHeight,%d+%s*[%s,]%s*(%d+)",
+    w = "number,SetWidth",
+    h = "number,SetHeight",
+    movable = "true,SetMovable",
+    mouse = "true,EnableMouse",
+    hide = "true,Hide",
+    clamp = "true,SetClampedToScreen",
+    mousewheel = "true,EnableMouseWheel",
+    toplevel = "true,SetToplevel",
+    click = "string,RegisterForClicks",
+    drag = "string,RegisterForDrag",
+    strata = "string,SetFrameStrata",
+    level = "number,SetFrameLevel",
+    a = "number,SetAlpha",
+    id = "number,SetID",
+    scale = "number,SetScale",
+    layer = "string,SetDrawLayer",
+    text = "string,SetText",
+	normtex = "string,SetNormalTexture",
+
+    sap = function(frame, value)
+        if value then value = getfenv(0)[value]
+        else value = frame:GetParent() end
+        if not value then return end
+        frame:SetAllPoints(value)
+    end,
+    tex = function(texture,value)
+        local r,g,b,a = value:match("^(%d?%.?%d*)%s*[,%s]%s*(%d?%.?%d*)%s*[,%s]%s*(%d?%.?%d*)$")
+        if not r then
+            r,g,b,a = value:match("^(%d?%.?%d*)%s*[,%s]%s*(%d?%.?%d*)%s*[,%s]%s*(%d?%.?%d*)%s*[,%s]%s*(%d?%.?%d*)$")
+        end
+        if r then
+            texture:SetTexture(tonumberAll(r,g,b),a and tonumber(a))
+        else
+            texture:SetTexture(value)
+        end
+    end,
+    texc = function(texture,value)
+        texture:SetTexCoord(tonumberAll(strsplit(',',value)))
+    end,
+}
+
+--[[-------------------------------------------------------------------------
+  Library implementation
+---------------------------------------------------------------------------]]
+
+function lib:GetVersion() return major,minor end
+
+DongleStub:Register(lib)
diff --git a/TomTom.lua b/TomTom.lua
index e8bd7d6..91a5222 100755
--- a/TomTom.lua
+++ b/TomTom.lua
@@ -252,21 +252,28 @@ end

 local halfpi = math.pi / 2

-local constant1,constant2
-local sw,sh = math.floor(GetScreenWidth()), math.floor(GetScreenHeight())
-local ratio = sw / sh
-if ratio > 1.32 and ratio < 1.34 then
-	-- At 1.33 aspect ratio
-	constant1 = 0.04575
-	constant2 = 0.05475
-elseif ratio > 1.59 and ratio < 1.61 then
-	-- At 1.6 aspect ratio
-	constant1 = 0.03875
-	constant2 = 0.04875
-else
-	-- Fallback
-	constant1 = 0.03875
-	constant2 = 0.04875
+-- The magic number which represents the ratio of model position pixels to
+-- logical screen pixels. I suspect this is really based on some property of the
+-- model itself, but I figured it out through interpolation given 3 ratios
+-- 4:3 5:4 16:10
+local MAGIC_ARROW_NUMBER  = 0.000723339
+
+-- Calculation to determine the actual offset factor for the screen ratio, I dont
+-- know where the 1/3 rationally comes from, but it works, there's probably some
+-- odd logic within the client somewhere.
+--
+-- 70.4 is half the width of the frame so we move to the center
+local ofs = MAGIC_ARROW_NUMBER * (GetScreenHeight()/GetScreenWidth() + 1/3) * 70.4;
+-- The divisor here puts the arrow where the original magic number pair had it
+local radius = ofs / 1.166666666666667;
+
+local function gomove(model,angle)
+    model:SetFacing(angle);
+    -- The 137/140 simply adjusts for the fact that the textured
+    -- border around the minimap isn't exactly centered
+    model:SetPosition(ofs * (137 / 140) - radius * math.sin(angle),
+                      ofs               + radius * math.cos(angle),
+                      0);
 end

 -- For animating the arrow
@@ -275,15 +282,7 @@ local function MinimapIcon_UpdateArrow(self, elapsed)
 	local icon = self.parent
 	local angle = Astrolabe:GetDirectionToIcon(icon)

-	local x = constant1 * math.cos(angle + halfpi) + constant2
-	local y = constant1 * math.sin(angle + halfpi) + constant2
-	self:SetPosition(x,y,0)
-	self:SetFacing(angle)
-
-	--angle = angle + 0.075
-	--if angle > math.pi * 2 then
-	--	angle = 0
-	--end
+	gomove(self, angle)
 end

 local function MinimapIcon_OnUpdate(self, elapsed)
@@ -362,6 +361,11 @@ function TomTom:CreateMinimapIcon(label, x, y)
 	icon:SetScript("OnUpdate", MinimapIcon_OnUpdate)
 	icon:SetScript("OnClick", MinimapIcon_OnClick)

+	-- Golden Arrow Information:
+	-- Facing: 0.50088876485825
+	-- Light: 0,1,0,0,0,1,1,1,1,1,1,1,1
+	-- Position: 0.029919292777777, 0.08267530053854, 0
+
 	local model = CreateFrame("Model", nil, icon)
 	model:SetHeight(140.8)
 	model:SetWidth(140.8)
@@ -373,6 +377,8 @@ function TomTom:CreateMinimapIcon(label, x, y)
 --	model:SetFogNear(0)
 --	model:SetLight(0,1,0,0,0,1,1,1,1,1,1,1,1)
 --	model:SetLight(1, 0, 0, -0.707, -0.707, 0.7, 1.0, 1.0, 1.0, 0.8, 1.0, 1.0, 0.8)
+--  Model:SetLight (enabled[,omni,dirX,dirY,dirZ,ambIntensity[,ambR,ambG,ambB [,dirIntensity[,dirR,dirG,dirB]]]])
+	model:SetLight(0,1,0,0,0,1,1,1,1,1,1,1,1)
 	model:SetModelScale(.600000023841879)

 	model.parent = icon