#๐Ÿ”’ why cube spawning somewhere at negatives coordinates?

14 messages ยท Page 1 of 1 (latest)

restive rose
#

Just trying to do a fun thing but its spawns at negative coordinates instead of positive coordinates, trying to do a research but i didnt found anything, i dont really know why that happened

misty oreBOT
#

@restive rose

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

restive rose
# misty ore <@724284358805946398>
from tkinter import *

tx=0
ty=0
tz=15
zoom=100
width=370
height=350
a=1

def together(x, y, z):
    x-=width//2
    y-=height//2
    print(((x+tx)/(tz+z))*zoom+width//2, ((y+ty)/(tz+z))*zoom+height//2)
    return ((x+tx)/(tz+z))*zoom+width//2, ((y+ty)/(tz+z))*zoom+height//2


def changeidk(which, i):
    global tz
    global tx
    global ty
    if which=='tz':
        tz+=i
    elif which=='tx':
        tx+=i
    elif which=='ty':
        ty+=i

def main():
    canvas.delete(ALL)
    canvas.create_line(together(20, 20, 0), together(50, 20, 0))
    canvas.create_line(together(50, 20, 0), together(50, 50, 0))
    canvas.create_line(together(50, 50, 0), together(20, 50, 0))
    canvas.create_line(together(20, 50, 0), together(20, 20, 0))

    canvas.create_line(together(20, 20, 10), together(50, 20, 10))
    canvas.create_line(together(50, 20, 10), together(50, 50, 10))
    canvas.create_line(together(50, 50, 10), together(20, 50, 10))
    canvas.create_line(together(20, 50, 10), together(20, 20, 10))

    canvas.create_line(together(20, 20, 0), together(20, 20, 10))
    canvas.create_line(together(50, 20, 0), together(50, 20, 10))
    canvas.create_line(together(50, 50, 0), together(50, 50, 10))
    canvas.create_line(together(20, 50, 0), together(20, 50, 10))
    root.after(60, main)

root=Tk()
root.title('3d Engine')
root.geometry('370x350')
root.resizable(width=False, height=False)
canvas=Canvas(root, width=370, height=350)
canvas.pack(expand=True)
root.after(1000, main)

root.bind('w', lambda x: changeidk('ty', 1))
root.bind('a', lambda x: changeidk('tx', -1))
root.bind('s', lambda x: changeidk('ty', -1))
root.bind('d', lambda x: changeidk('tx', 1))
root.bind('x', lambda x: changeidk('tz', 1))
root.bind('z', lambda x: changeidk('tz', -1))
root.mainloop()
fresh bane
#

I don't get what you mean. You already have the print, you can see which function does it badly - the function that does the printing.

So let's analyse first together call, together(20, 20, 0)

def together(x, y, z):
    x-=width//2
    y-=height//2

After those two lines x == -165, y == -155

    print(((x+tx)/(tz+z))*zoom+width//2, ((y+ty)/(tz+z))*zoom+height//2)
    return ((x+tx)/(tz+z))*zoom+width//2, ((y+ty)/(tz+z))*zoom+height//2

And with such x and y it prints -915.0 -858.3333333333335

So now it's time to think: why did you do the -width//2? What did you want to do instead?
Maybe you meant +width//2? It would mean the coordinates passed to function are calculated from the centre of the screen.

restive rose
#

Wait

fresh bane
#

How did you want it to be "by center of the cubes" when width is width of the screen?

fresh bane
#

Right now you do "move the cube points half a screen away from screen ๐Ÿ˜›
As I said, you could do +width//2 to have the coordinates work as from centre of the screen (function getting 0,0 would mean centre of the screen)
But minus makes no sense at all

restive rose
#

so i need to do only

return ((x+tx)/(tz+z))*zoom+width//2, ((y+ty)/(tz+z))*zoom+height//2
```?
fresh bane
#

For now I'd say yes. I have no idea why you did the minus. If you find out what you wanted to do exactly, you can try experimenting to do it properly

restive rose
#

ok, thanks!

misty oreBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.