Thread Tools Display Modes
10-22-13, 06:22 AM   #1
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Model tilting

I managed to tilt ingame models in the x axis like this:



However my code only works with ~45 degree tilt yet.

Lua Code:
  1. local frame = CreateFrame("Frame", nil, UIParent)
  2. frame:SetPoint("Center", 128, 0)
  3. frame:SetWidth(512 / (2 * math.sqrt(2)))
  4. frame:SetHeight(512 / (2 * math.sqrt(2)))
  5. frame:SetAlpha(1)
  6.  
  7. local model = CreateFrame("PlayerModel", nil, frame)
  8. model:SetAllPoints(frame)
  9.  
  10. local zz = 2
  11.  
  12. function ModelBasics_UpdateModel()
  13.     model:SetModel("Creature/LasherSunflower/lasher_sunflower.m2")
  14.     model:SetRotation(math.rad(0))
  15.     model:SetAlpha(1)
  16.     model:SetCustomCamera(1)
  17.     model:SetCameraDistance(1)
  18.     local x, y, z = model:GetCameraPosition()
  19.     model:SetCameraPosition(x, y, zz)
  20.     model:SetPosition(0, 0, - (zz * zz))
  21. end
  22.  
  23. ModelBasics_UpdateModel()
  24.  
  25. local frame2 = CreateFrame("Frame", nil, UIParent)
  26. frame2:SetPoint("Center", - 128, 0)
  27. frame2:SetWidth(512)
  28. frame2:SetHeight(512)
  29. frame2:SetAlpha(1)
  30.  
  31. local model2 = CreateFrame("PlayerModel", nil, frame)
  32. model2:SetAllPoints(frame2)
  33.  
  34. function ModelBasics_UpdateModel2()
  35.     model2:SetModel("Creature/LasherSunflower/lasher_sunflower.m2")
  36.     model2:SetRotation(math.rad(0))
  37.     model2:SetAlpha(1)
  38. end
  39.  
  40. ModelBasics_UpdateModel2()

Also i'm unable to create a slider for this zz (aka the tilt value) to work properly with every value from 0-90 (0-180 would be the best) degrees. Maybe someone with more experience can help me with this?

I think this would be an awsome feature for addons.

Last edited by Resike : 10-22-13 at 06:27 AM.
  Reply With Quote
10-22-13, 11:34 AM   #2
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
If I understand correctly, the problem you're describing is that you cannot actually rotate the model by 90 degrees by only controlling the Z axis, and the solution is to have the slider control the Y axis (or is it X?) as well to make sure that the camera goes in a circle around the model, with sin(Y) = sqrt (1-cos(Z)*cos(Z)) or some such equation.
I hope that that's indeed the problem you meant
__________________
SanityCheck - If you've ever said the words "Sorry, I forgot" then you need this add-on.

Remember, every time you post a comment on an add-on, a kitten gets its wings!
  Reply With Quote
10-22-13, 12:15 PM   #3
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Yeah i got it, i just have no clue how to code that now.
  Reply With Quote
10-22-13, 12:33 PM   #4
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
Say the slider moves between -180 and 180, and we call its value [i]s/I], and you have some value for camera distance because, you know, different model sizes, then you want something like:

Lua Code:
  1. local deg = s * math.pi / 180
  2. local y = math.pow (math.sin(deg), 2) * camDistance
  3. local z = math.pow (math.cos(deg), 2) * camDistance
(I think. It's been a long day.)
__________________
SanityCheck - If you've ever said the words "Sorry, I forgot" then you need this add-on.

Remember, every time you post a comment on an add-on, a kitten gets its wings!
  Reply With Quote
10-22-13, 04:41 PM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Okay, thanks for you help i managed to do it, however the tilting seems kinda weird, also the model sometimes radnomly flips 180 degrees when its tilted 0 or 90 degrees. Not sure whats causing this.

Here is my code:

Lua Code:
  1. local frame2 = CreateFrame("Frame", nil, UIParent)
  2. frame2:SetPoint("Center", - 128, 0)
  3. frame2:SetWidth(512)
  4. frame2:SetHeight(512)
  5. frame2:SetAlpha(1)
  6.  
  7. local model2 = CreateFrame("PlayerModel", nil, frame)
  8. model2:SetModel("Creature/LasherSunflower/lasher_sunflower.m2")
  9. model2:SetAlpha(1)
  10. model2:SetAllPoints(frame2)
  11. model2:SetCustomCamera(1)
  12. local x, y, z = model2:GetCameraPosition()
  13. local r = math.sqrt((x * x) + (z * z))
  14. print(x, y, z, r)
  15.  
  16. local degree = 90
  17.  
  18. local slider = CreateFrame("Slider", nil, UIParent, "OptionsSliderTemplate")
  19. slider:ClearAllPoints()
  20. slider:SetPoint("Center", UIParent, "Center", 0, 300)
  21. slider:SetMinMaxValues(90, 180)
  22. slider:SetValue(90)
  23. slider:SetValueStep(1)
  24. slider:SetScript("OnValueChanged", function(slider, value)
  25.     degree = value
  26.     ModelBasics_UpdateModel2()
  27. end)
  28.  
  29. function ModelBasics_UpdateModel2()
  30.     --model2:SetModel("Creature/LasherSunflower/lasher_sunflower.m2")
  31.     --model2:SetRotation(math.rad(0))
  32.     model2:SetCustomCamera(1)
  33.     local xx = math.pow(math.sin(math.rad(degree)), 2) * r
  34.     local zz = math.pow(math.cos(math.rad(degree)), 2) * r
  35.     model2:SetCameraPosition(xx, y, zz)
  36.     --model2:SetAllPoints(frame2)
  37. end
  38.  
  39. ModelBasics_UpdateModel2()

Last edited by Resike : 10-22-13 at 04:47 PM.
  Reply With Quote
10-22-13, 04:49 PM   #6
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
I'm a bit high on a sleeping pill at the moment, but I promise to give this a look in the morning
__________________
SanityCheck - If you've ever said the words "Sorry, I forgot" then you need this add-on.

Remember, every time you post a comment on an add-on, a kitten gets its wings!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Model tilting


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off