I am trying to create a simple scene in 3d (in python) where you have a cube in front of you, and you are able to rotate it around with the mouse.
I understand that you should rotate the complete scene to mimic camera movement but i can't figure out how you should do this.
Just to clarify I want the camera (or scene) to move a bit like blender (the program).
Thanks in advance
Ok I think i have found what you should do
just for the people that have trouble with this like I did this is the way you should do it:
to rotate around a cube with the camera in opengl:
your x mouse value has to be added to the z rotator of your scene
and the cosinus of your y mouse value has to be added to the x rotator
and then the sinus of your y mouse value has to be subtracted of your y rotator
that should do it
Related
i need help in understanding rotation values in webots. How do I calculate and set them?
I want my robot to rotate in direction of the certain object.
For example, if the ball is rolling around the robot, the robot tries to get the position of the ball and rotate to it, so that the robot is always facing the ball.
Does anybody have an idea how can I do it?
My thoughts on coding it:
Get position of the ball
Get position of the robot
Calculate the angle between them
Rotate the robot by calculated angle
Thanks in advance!
You don't have to calculate the angle, it is enough to find the position of the ball in a 2D image plane. If the ball is left from the image center the robot should rotate left and if the ball is right from the image center the robot should rotate right.
You can find an example here:
https://github.com/lukicdarkoo/webots-example-visual-tracking
and you can see the result here:
https://lukicdarkoo.github.io/webots-example-visual-tracking/
Good evening. I should define the x and y coordinates of the figure window when i move it. There is a way to know when a window has been moved/dragged across the screen in python?
I use the method fig.canvas.manager.window.winfo_geometry() to get the x and y coordinates but how do I get a callback when I move the window?
thanks.
I am currently working on a 2D platformer and the sprites that I have animate from the bottom left point of the animation and when I draw the animation using a x and y point it still animates from the bottom left, so when I draw the animation to the screen the sprite should get shorter but the sprites feet just lift up of the ground like this https://www.dropbox.com/s/ofeggmlcp4f6qsk/Animation_probs_video.mp4
I know the video is not high quality but so what.
His head should go up and down not his feet. If you guy's can help me I would be most greatful. I could also use a program that fixes that I have a Linux computer with a windows xp virtual box and I am using python 2.7 and pygame.
Thanks.
Assuming you are animating a series of rectangular sprites each being an instance of pygame.Surface, you will be adding the difference between the surface with the greatest height and the current sprite's surface to the y position every time you blit.
Find the height of the tallest sprite only once:
max_height = tallest_sprite.get_height()
Now while you are cycling through your sprints each frame with current_sprite:
screen.blit(current_sprite, (x, y+(max_height - current_sprite.get_height())
If framerate is an issue, you may want to calculate these differences beforehand and associate them with each sprite so you have one less get_height() call per frame.
Hi I am trying to make a punny cookie clicker type game called py clicker and made an invisible circle over the sprite which is a pie. How do I detect if the mouse is within the circle so when the user clicks it checks if it is in the circle and adds one to the counter?
If you know the x,y of the center of the circle and it's radius then you can calculate the distance from the center of the circle to your mouse pointer when you click. If it's greater than the radius then you are outside. There is a built in method that might help called math.hypot that will return the length between two points.
You could try pygame.sprite.collide_circle() . But you will need another Sprite with small radius and mouse position.
you can use the graphics library and use the method called getMouse.
I am trying to create a rectangle tool for a paint program using python. Basically, I would like for the user to be able to click on the canvas and to be able to draw rectangles from that specific point just as any rectangle tool in paint programs. This is the code I have right now. It currently gives me very small cross-like structure. I am not sure what is causing this output and would just like some insight on how the problem can be fixed. Thank you.
if mb[0] == 1 and canvas.collidepoint(mx,my):
screen.set_clip(canvas)
if tool == "rectangle":
screen.blit(copy,(0,0))
x,y = mouse.get_pos()
mx,my = mouse.get_pos()
draw.rect(screen,(c),(x,y,mx-x,my-y),sz)
screen.set_clip(None)
Instead of grabbing the current position, use mouse events.
On mouse down, store start coordinate
On mouse up, draw rect at start to current coordinates
You could draw in-progress rectangles with MOUSEMOTION's coordinates.