I'm trying to create a simple 3d rendering of a cube. As in this video from the Coding Train: https://www.youtube.com/watch?v=p4Iz0XJY-Qk on minute 14. I got stuck at one point. Since I'm pretty new to all of this, I'm not exactly sure what's causing my issue. When I start the project, the cube rotates as I want it to, but moves away from the screen to the left and it looks like it's making a circle.
import pygame
import numpy as np
import os
import math
WHITE = (255,255,255)
width, height = 700, 700
screen = pygame.display.set_mode((width, height))
clock = pygame.time.Clock()
points = []
angle = 0
points.append(np.array([[300], [250], [1]]))
points.append(np.array([[300], [350], [1]]))
points.append(np.array([[400], [250], [1]]))
points.append(np.array([[400], [350], [1]]))
projectionMatrix = np.array([[1, 0, 0],
[0, 1, 0]])
while True:
clock.tick(30)
screen.fill((0,0,0))
rotation = np.array([[math.cos(angle), -math.sin(angle)],
[math.sin(angle), math.cos(angle)]])
for event in pygame.event.get():
if event.type == pygame.QUIT:
os._exit(1)
for point in points:
projected2d = np.dot(projectionMatrix, point)
rotated = np.dot(rotation, projected2d)
pygame.draw.circle(screen, WHITE, (int(rotated[0][0]), int(rotated[1][0])), 5)
angle += 0.01
pygame.display.update()
I would really appreciate any help to why this is happening and how I could fix it so it's just rotating around.