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:
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. |
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 :p |
Yeah i got it, i just have no clue how to code that now.
|
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:
|
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:
|
I'm a bit high on a sleeping pill at the moment, but I promise to give this a look in the morning :)
|
Quote:
|
Hmmm, it looks fine... I'll have to run it myself and see what's happening, at some point after work. I hate it when real life keeps me away from coding fun stuff :p
|
Interesting thread. I have some model functions in my model viewer aswell.
Finding a function that allows tossing around with the cameraposition would be awesome. It would be enough if the cameraposition z-axis has a max of 180° (-90° till 90°). Thus you can look at a model from bottom to top. model:SetRotation() will do the rest since it allows a 360° rotation of the model around its axis. Important: Models only work when cached. The only way to display uncached models is by using SetDisplayInfo() on a playermodel type model. That's how NPCSCAN works. It checks for the model cache to determine if a rare mob model is found. Model methods Quote:
PlayerModel model sub-methods Quote:
For my purposes I could work with playermodel type models only since I could not rely on a model being cached. But I could not get a custom camera to work on it. But maybe I was missing sth who knows. Accoring to the docs a playermodel type model is a child of the model object and inherits all model functions, so custom camera should work. |
Great point about model:SetRotation(), assuming it rotates the model itself, it solves what is normally a pretty significant problem :)
|
Yep i was aware pretty much any api that models have, the bad part most of them is undocumented, i would like to add some descripion for some of the function i recently tried:
Model:ClearModel() -- Works fine unless your model is set by unit ids like: Model:SetModel("player"), you can clear that with Model:SetModel("none"). Model:SetCustomCamera() -- You can enabled this with 1 parameter, not sure how to disable it, my guess would be 0. Model:GetCameraPosition() -- Gives you the current camera's X, Y, Z axis coordinates based on 0, 0, 0 point in this order: Y, X, Z. Model:GetCameraDistance() -- Disabled, addons cant call it (Always returns 0.). Workaround to get the same value: Lua Code:
Model:SetCameraDistance() -- Works fine. Model:SetCameraPosition(x, y, z) -- Only works with "Model:SetCustomCamera(1)", the order is Y, X, Z. I'm actually not sure whats the difference between Model and PlayerModel, i was always using PlayerModel. Also you're right about the "SetRotation will fix it" but when you want to handle the tilting value with an onupdate script which automatically tilts the models in like 3-4 sec in 0-90 degrees then the random flipping could be annoying. |
I would like the tilting to be like on WoW Model Viewer or like pretty much any 3D modeller program has:
https://wowmodelviewer.atlassian.net...2898511&api=v2 |
Regarding models. You can play different animation types. This is from the petbattle ui.
Lua Code:
Other functions from the tabardframe.lua Lua Code:
|
I didn't meant that but if you compare the tilting from WoW model viewer and my my code then you can see my method still have some zooming/scaling issues.
Edit: I fixed that now: Lua Code:
This one should be much smoother. I blame Malsomnus ofc. There is no need for math.pow here: :P Lua Code:
|
Bad news, seems like you can only set custom camera for the model if Model:HasCustomCamera() returns true.
Also managed to fix the flipping issue like this: Lua Code:
|
The custom camera seems to be limited to keeping the model upright, that's what's causing the sudden flipping. You may just need to cap the pitch to +/- 90 degrees (+/- pi / 2 radians). Here is what I came up with from playing around with the camera stuff today (along with many client crashes):
Code:
local MODEL = "Creature/LasherSunflower/lasher_sunflower.m2" |
Quote:
Thats actually really good, any chance to save the positions on mouseup and continue from there in the next click? Also you could add the model:SetPosition(x, y, z) function to right clicking, then you have pretty much all the model functions in it. |
Quote:
Quote:
Code:
local function OnUpdate(self) Quote:
|
I see, well the main reason i wanted this tilting because i want to use it for the project i just started too.
I was trying to make a workaround for models with model:HasCustomCamera() == false, but i failed. |
Quote:
|
All times are GMT -6. The time now is 09:06 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI