Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Positions for 3D objects #59

Open
oganm opened this issue Feb 9, 2019 · 5 comments
Open

Positions for 3D objects #59

oganm opened this issue Feb 9, 2019 · 5 comments
Labels

Comments

@oganm
Copy link

oganm commented Feb 9, 2019

I am going through the wiki but I was unable to find functions to set positions of 3D objects like cube3D. Is there a way to do this or is it a work in progress? It seems like OCG1 had functions to set positions but those don't seem to exist anymore

@xiaC4ll
Copy link

xiaC4ll commented Feb 10, 2019

"Translation" here is synonym to "Position"
(by the way I can't understand why)

@oganm
Copy link
Author

oganm commented Feb 10, 2019

Ah it seems like they merged the function to change the position and set the position into a single function since the widgets initiate at the origin. Thanks!

@ben-mkiv
Copy link
Collaborator

Yes its addTranslation()
The new API kinda works like the OpenGL stack, so the methods are also named like that.

Also think of it as moving instead of setting a position as if you do another addTranslation they will add up, so calling widget.addTranslation(0, 2, 0) twice will move the widget 4 blocks up, if you dont want to save multiple translations on the render stack you can change the values of a existing modifier, the following example will move the widget to y2 first and then set it to y4

modifierIndex = widget.addTranslation(0, 2, 0)
widget.updateModifier(modifierIndex, 0, 4, 0)

@oganm
Copy link
Author

oganm commented Feb 13, 2019

Are the modifiers ordered in the same way they are shown in the wiki? Might be nice to have named constants for them

@ben-mkiv
Copy link
Collaborator

ben-mkiv commented Feb 14, 2019

no, they are executed and get their index in the order you add them to a widget, so you have to store their index if you want to modify them later.

-- this example  would draw the widget 2 blocks above and then rotate it
modifier1 = widget.addTranslation(0, 2, 0)
modifier2 = widget.addRotation(45, 0, 1, 0)
-- this example  would rotate by 45° and move in that angle 2 blocks away to draw the widget
modifier1 = widget.addRotation(45, 0, 1, 0)
modifier2 = widget.addTranslation(0, 2, 0)

so changing in which order you add the modifiers can significantly change the render result.

old openglasses1 behavior can be easy wrapped with a small lua lib which uses fixed modifiers like you mentioned before, and just updates them when necessary.

btw. all add Modifier methods return their index. so if you just want to keep track of one for later usage you dont have to count them, just store it somewhere

-- add green color
myColorModifier = widget.addColor(0, 1, 0, 0)
-- some code [...]
-- change the green to red color
widget.updateModifier(myColorModifier, 1, 0, 0, 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants