WoW:API Model SetPosition: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
m (Move page script moved page API Model SetPosition to WoW:API Model SetPosition without leaving a redirect)
 
(2 intermediate revisions by 2 users not shown)
Line 2: Line 2:


== Syntax ==
== Syntax ==
SetPosition( x, y, z );
SetPosition( x, y, z );


== Parameters ==
== Parameters ==
=== Arguments ===
=== Arguments ===
 
* x (float) - sets the x-value of the model position
:; x : float - sets the x-value of the model position
* y (float) - sets the y-value of the model position
:; y : float - sets the y-value of the model position
* z (float) - sets the z-value of the model position
:; z : float - sets the z-value of the model position
 


: positive values of x will move the model right, negative will move it left
: positive values of x will move the model right, negative will move it left
Line 19: Line 15:


=== Returns ===
=== Returns ===
 
* nil
: unknown, probably nil


==Notes==
==Notes==


The width and height of the Model frame affect the outcome of this function. ie the effect of calling
The bottom left corner of the Model frame will always have coordinates (0,0,0). However, the top right corner's coordinate depends upon the width and height of the Model frame, as well as the screen resolution returned by [[API GetScreenWidth|GetScreenWidth]]/[[API GetScreenHeight|GetScreenHeight]].  The following formula determines the Model-relative coordinate that corresponds to the top-right of the Model frame (''CoordRight'',''CoordTop'',0):
SetPosition( 0.01, 0.01, 1 ) on a Model frame with width 200px and height 200px, will be different
to calling SetPosition( 0.01, 0.01, 1 ) on a Model frame with width 150px and height 150px


Changing the scale of the Model does not seem to change the effect of this function.
local Scale = UIParent:GetEffectiveScale();
local Hypotenuse = ( ( GetScreenWidth() * Scale ) ^ 2 + ( GetScreenHeight() * Scale ) ^ 2 ) ^ 0.5;
local CoordRight = ( ''MyModelFrame'':GetRight() - ''MyModelFrame'':GetLeft() ) / Hypotenuse; -- X
local CoordTop = ( ''MyModelFrame'':GetTop() - ''MyModelFrame'':GetBottom() ) / Hypotenuse; -- Y

Latest revision as of 04:46, 15 August 2023

Widget API ← Model < SetPosition

Syntax

SetPosition( x, y, z );

Parameters

Arguments

  • x (float) - sets the x-value of the model position
  • y (float) - sets the y-value of the model position
  • z (float) - sets the z-value of the model position
positive values of x will move the model right, negative will move it left
positive values of y will move the model up, negative will move it down
positive values of z will bring the model nearer to you, negative will bring it away

Returns

  • nil

Notes

The bottom left corner of the Model frame will always have coordinates (0,0,0). However, the top right corner's coordinate depends upon the width and height of the Model frame, as well as the screen resolution returned by GetScreenWidth/GetScreenHeight. The following formula determines the Model-relative coordinate that corresponds to the top-right of the Model frame (CoordRight,CoordTop,0):

local Scale = UIParent:GetEffectiveScale();
local Hypotenuse = ( ( GetScreenWidth() * Scale ) ^ 2 + ( GetScreenHeight() * Scale ) ^ 2 ) ^ 0.5;

local CoordRight = ( MyModelFrame:GetRight() - MyModelFrame:GetLeft() ) / Hypotenuse; -- X
local CoordTop = ( MyModelFrame:GetTop() - MyModelFrame:GetBottom() ) / Hypotenuse; -- Y