reoriented everything to proper coords, still trying to get sprite size correct
This commit is contained in:
parent
22818f983d
commit
02ced2dac2
|
@ -94,7 +94,7 @@ if __name__=="__main__":
|
||||||
pygame.init()
|
pygame.init()
|
||||||
pygame.display.set_caption("Spinny")
|
pygame.display.set_caption("Spinny")
|
||||||
|
|
||||||
window = pygame.display.set_mode((900, 900))
|
window = pygame.display.set_mode((1500, 900))
|
||||||
resolutionDownscaling = 2
|
resolutionDownscaling = 2
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ if __name__=="__main__":
|
||||||
running = True
|
running = True
|
||||||
display = False
|
display = False
|
||||||
thisEarth = deepcopy(Planet.Earth)
|
thisEarth = deepcopy(Planet.Earth)
|
||||||
sat = OrbitingBody(Point(config()["earthRadius"] * 2, 0, 0), Point(0,0,0), "BoSLOO", 3, thisEarth)
|
sat = OrbitingBody(Point(0, config()["earthRadius"] * 2, 0), Point(0,0,0), "BoSLOO", 3, thisEarth)
|
||||||
orbitlines = []
|
orbitlines = []
|
||||||
renderObjects = [thisEarth, sat, orbitlines]
|
renderObjects = [thisEarth, sat, orbitlines]
|
||||||
imageThread = threading.Thread()
|
imageThread = threading.Thread()
|
||||||
|
@ -116,7 +116,7 @@ if __name__=="__main__":
|
||||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
if not display:
|
if not display:
|
||||||
display = True
|
display = True
|
||||||
camera = Camera(window, Point(0, 0, 2 * config()["earthRadius"]), thisEarth, renderObjects)
|
camera = Camera(window, Point(5 * config()["earthRadius"], 0, 0), thisEarth, renderObjects)
|
||||||
camera.renderFrame()
|
camera.renderFrame()
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
else:
|
else:
|
||||||
|
|
31
renderer.py
31
renderer.py
|
@ -11,9 +11,13 @@ class Point:
|
||||||
self.vector = numpy.array([x, y, z])
|
self.vector = numpy.array([x, y, z])
|
||||||
|
|
||||||
def polar(self):
|
def polar(self):
|
||||||
|
if self.vector[0] == 0:
|
||||||
|
self.vector[0] = 0.1
|
||||||
|
if self.vector[2] == 0:
|
||||||
|
self.vector[2] = 0.1
|
||||||
rho = math.sqrt(self.vector[0] ** 2 + self.vector[1] ** 2 + self.vector[2] ** 2)
|
rho = math.sqrt(self.vector[0] ** 2 + self.vector[1] ** 2 + self.vector[2] ** 2)
|
||||||
theta = math.atan(self.vector[2]/self.vector[0])
|
theta = math.atan(self.vector[1]/self.vector[0])
|
||||||
phi = math.acos((self.vector[1])/(rho))
|
phi = math.acos(self.vector[2]/rho)
|
||||||
return [rho, theta, phi]
|
return [rho, theta, phi]
|
||||||
|
|
||||||
def magnitude(self):
|
def magnitude(self):
|
||||||
|
@ -92,9 +96,9 @@ class PlanetSprite(pygame.sprite.Sprite):
|
||||||
winWidth, winHeight = camera.surface.get_size()
|
winWidth, winHeight = camera.surface.get_size()
|
||||||
distance = Point.subtract(camera.location, self.parentPlanet.location).magnitude()
|
distance = Point.subtract(camera.location, self.parentPlanet.location).magnitude()
|
||||||
widthHalf = self.parentPlanet.radius
|
widthHalf = self.parentPlanet.radius
|
||||||
angle = numpy.arctan(widthHalf/distance) #the angle from center to edge of the sphere, from the camera
|
angle = numpy.degrees(numpy.arctan(widthHalf/distance)) #the angle from center to edge of the sphere, from the camera
|
||||||
sizeAsPercent = numpy.degrees(angle)/camera.hFOV
|
sizeAsPercent = angle/camera.hFOV
|
||||||
self.sideLength = int(winWidth*sizeAsPercent)
|
self.sideLength = int(winWidth*sizeAsPercent*2)
|
||||||
self.image = pygame.transform.scale(self.image, (self.sideLength, self.sideLength))
|
self.image = pygame.transform.scale(self.image, (self.sideLength, self.sideLength))
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.rect.center = (winWidth/2, winHeight/2)
|
self.rect.center = (winWidth/2, winHeight/2)
|
||||||
|
@ -110,13 +114,12 @@ class PlanetSprite(pygame.sprite.Sprite):
|
||||||
|
|
||||||
class Camera:
|
class Camera:
|
||||||
"""Object which will be used to paint pixels on screen."""
|
"""Object which will be used to paint pixels on screen."""
|
||||||
def __init__(self, surface:pygame.Surface, location:Point, target:"Planet", objects, hFOV = 60, vFOV = 60):
|
def __init__(self, surface:pygame.Surface, location:Point, target:"Planet", objects, hFOV = 45):
|
||||||
self.surface = surface
|
self.surface = surface
|
||||||
self.objects = objects
|
self.objects = objects
|
||||||
self.location = location
|
self.location = location
|
||||||
self.target = target
|
self.target = target
|
||||||
self.hFOV = hFOV
|
self.hFOV = hFOV
|
||||||
self.vFOV = vFOV
|
|
||||||
self.spriteGroup = pygame.sprite.Group()
|
self.spriteGroup = pygame.sprite.Group()
|
||||||
self.spriteGroup.add(PlanetSprite(self, self.target))
|
self.spriteGroup.add(PlanetSprite(self, self.target))
|
||||||
|
|
||||||
|
@ -145,8 +148,8 @@ class Camera:
|
||||||
lineToCamera = Line(obj.location, self.location)
|
lineToCamera = Line(obj.location, self.location)
|
||||||
intersectPoint = lineToCamera.intersectWithPlane(screenPlane)
|
intersectPoint = lineToCamera.intersectWithPlane(screenPlane)
|
||||||
if intersectPoint is not None:
|
if intersectPoint is not None:
|
||||||
intersectPoint = Point.add(intersectPoint, Point(int(winWidth/2), int(winHeight/2), 0))
|
intersectPoint = Point.add(intersectPoint, Point(0, int(winWidth/2), int(winHeight/2))) #x is meaningless here
|
||||||
pygame.draw.circle(screenSurface, (255,255,150), (int(intersectPoint.vector[0]), int(intersectPoint.vector[1])), obj.displaySize)
|
pygame.draw.circle(screenSurface, (255,255,150), (int(intersectPoint.vector[1]), int(intersectPoint.vector[2])), obj.displaySize)
|
||||||
|
|
||||||
elif isinstance(obj, list):
|
elif isinstance(obj, list):
|
||||||
for orbitline in obj:
|
for orbitline in obj:
|
||||||
|
@ -154,11 +157,8 @@ class Camera:
|
||||||
lineToCamera = Line(orbitline.location, self.location)
|
lineToCamera = Line(orbitline.location, self.location)
|
||||||
intersectPoint = lineToCamera.intersectWithPlane(screenPlane)
|
intersectPoint = lineToCamera.intersectWithPlane(screenPlane)
|
||||||
if intersectPoint is not None:
|
if intersectPoint is not None:
|
||||||
intersectPoint = Point.add(intersectPoint, Point(int(winWidth/2), int(winHeight/2), 0))
|
intersectPoint = Point.add(intersectPoint, Point(0, int(winWidth/2), int(winHeight/2)))
|
||||||
pygame.draw.circle(screenSurface, orbitline.color, (int(intersectPoint.vector[0]), int(intersectPoint.vector[1])), 1)
|
pygame.draw.circle(screenSurface, orbitline.color, (int(intersectPoint.vector[1]), int(intersectPoint.vector[2])), 1)
|
||||||
|
|
||||||
|
|
||||||
screenSurface = pygame.transform.flip(screenSurface, False, True)
|
|
||||||
|
|
||||||
#generate text
|
#generate text
|
||||||
rho, theta, phi = sat.location.polar()
|
rho, theta, phi = sat.location.polar()
|
||||||
|
@ -168,10 +168,9 @@ class Camera:
|
||||||
0 == 0
|
0 == 0
|
||||||
|
|
||||||
#textSurface, rect = font.render(f"Speed: {round(sat.velocity.magnitude())} m/s \nAltitude: {round(rho - target.radius)} m", False, (255,255,255))
|
#textSurface, rect = font.render(f"Speed: {round(sat.velocity.magnitude())} m/s \nAltitude: {round(rho - target.radius)} m", False, (255,255,255))
|
||||||
font.render_to(screenSurface, (0,0), f"Speed: {round(sat.velocity.magnitude())} m/s", (255,255,255))
|
font.render_to(screenSurface, (0,0), f"Speed: {round(sat.velocity.magnitude()/1000,3)} km/s", (255,255,255))
|
||||||
font.render_to(screenSurface, (0,20), f"Altitude: {round((rho - self.target.radius)/1000)} km", (255,255,255))
|
font.render_to(screenSurface, (0,20), f"Altitude: {round((rho - self.target.radius)/1000)} km", (255,255,255))
|
||||||
|
|
||||||
self.surface.fill((0,0,0))
|
|
||||||
self.surface.blit(screenSurface, (0,0))
|
self.surface.blit(screenSurface, (0,0))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue