Skip to content
Snippets Groups Projects
Commit d7333adb authored by Damien Picard's avatar Damien Picard
Browse files

Sun Position: cleanup

parent f5ea6e39
No related branches found
No related tags found
No related merge requests found
...@@ -52,11 +52,11 @@ else: ...@@ -52,11 +52,11 @@ else:
shader = gpu.types.GPUShader(vertex_shader, fragment_shader) shader = gpu.types.GPUShader(vertex_shader, fragment_shader)
def draw_north_callback(): def draw_north_callback():
# ------------------------------------------------------------------ """
# Set up the compass needle using the current north offset angle Set up the compass needle using the current north offset angle
# less 90 degrees. This forces the unit circle to begin at the less 90 degrees. This forces the unit circle to begin at the
# 12 O'clock instead of 3 O'clock position. 12 O'clock instead of 3 O'clock position.
# ------------------------------------------------------------------ """
sun_props = bpy.context.scene.sun_pos_properties sun_props = bpy.context.scene.sun_pos_properties
color = (0.2, 0.6, 1.0, 0.7) color = (0.2, 0.6, 1.0, 0.7)
...@@ -64,30 +64,25 @@ else: ...@@ -64,30 +64,25 @@ else:
angle = -(sun_props.north_offset - math.pi / 2) angle = -(sun_props.north_offset - math.pi / 2)
x = math.cos(angle) * radius x = math.cos(angle) * radius
y = math.sin(angle) * radius y = math.sin(angle) * radius
coords = Vector((x, y, 0)), Vector((0, 0, 0))
coords = Vector((x, y, 0)), Vector((0, 0, 0)) # Start & end of needle batch = batch_for_shader(shader, 'LINE_STRIP', {"position": coords})
batch = batch_for_shader(
shader, 'LINE_STRIP',
{"position": coords},
)
shader.bind()
matrix = bpy.context.region_data.perspective_matrix matrix = bpy.context.region_data.perspective_matrix
shader.uniform_float("u_ViewProjectionMatrix", matrix) shader.uniform_float("u_ViewProjectionMatrix", matrix)
shader.uniform_float("u_Resolution", (bpy.context.region.width, bpy.context.region.height)) shader.uniform_float("u_Resolution", (bpy.context.region.width,
bpy.context.region.height))
shader.uniform_float("u_Color", color) shader.uniform_float("u_Color", color)
gpu.state.line_width_set(2.0) gpu.state.line_width_set(2.0)
batch.draw(shader) batch.draw(shader)
_handle = None
_north_handle = None
def north_update(self, context): def north_update(self, context):
global _handle global _north_handle
if self.show_north and _handle is None: if self.show_north and _north_handle is None:
_handle = bpy.types.SpaceView3D.draw_handler_add(draw_north_callback, (), 'WINDOW', 'POST_VIEW') _north_handle = bpy.types.SpaceView3D.draw_handler_add(draw_north_callback, (), 'WINDOW', 'POST_VIEW')
elif _handle is not None: elif _north_handle is not None:
bpy.types.SpaceView3D.draw_handler_remove(_handle, 'WINDOW') bpy.types.SpaceView3D.draw_handler_remove(_north_handle, 'WINDOW')
_handle = None _north_handle = None
context.area.tag_redraw() context.area.tag_redraw()
...@@ -9,14 +9,10 @@ import datetime ...@@ -9,14 +9,10 @@ import datetime
from .geo import parse_position from .geo import parse_position
############################################################################
#
# SunClass is used for storing intermediate sun calculations.
#
############################################################################
class SunClass: class SunClass:
"""
SunClass is used for storing intermediate sun calculations.
"""
class TazEl: class TazEl:
time = 0.0 time = 0.0
azimuth = 0.0 azimuth = 0.0
...@@ -81,16 +77,11 @@ def sun_handler(scene): ...@@ -81,16 +77,11 @@ def sun_handler(scene):
move_sun(bpy.context) move_sun(bpy.context)
############################################################################
#
# move_sun() will cycle through all the selected objects
# and call set_sun_position and set_sun_rotations
# to place them in the sky.
#
############################################################################
def move_sun(context): def move_sun(context):
"""
Cycle through all the selected objects and call set_sun_position and
set_sun_rotations to place them in the sky
"""
addon_prefs = context.preferences.addons[__package__].preferences addon_prefs = context.preferences.addons[__package__].preferences
sun_props = context.scene.sun_pos_properties sun_props = context.scene.sun_pos_properties
...@@ -265,29 +256,23 @@ def format_lat_long(lat_long, is_latitude): ...@@ -265,29 +256,23 @@ def format_lat_long(lat_long, is_latitude):
return hh + "° " + mm + "' " + ss + '"' + coord_tag return hh + "° " + mm + "' " + ss + '"' + coord_tag
############################################################################
#
# Calculate the actual position of the sun based on input parameters.
#
# The sun positioning algorithms below are based on the National Oceanic
# and Atmospheric Administration's (NOAA) Solar Position Calculator
# which rely on calculations of Jean Meeus' book "Astronomical Algorithms."
# Use of NOAA data and products are in the public domain and may be used
# freely by the public as outlined in their policies at
# www.nws.noaa.gov/disclaimer.php
#
# The calculations of this script can be verified with those of NOAA's
# using the Azimuth and Solar Elevation displayed in the SunPos_Panel.
# NOAA's web site is:
# http://www.esrl.noaa.gov/gmd/grad/solcalc
############################################################################
def get_sun_position(local_time, latitude, longitude, north_offset, def get_sun_position(local_time, latitude, longitude, north_offset,
utc_zone, month, day, year, distance): utc_zone, month, day, year, distance):
"""
Calculate the actual position of the sun based on input parameters.
The sun positioning algorithms below are based on the National Oceanic
and Atmospheric Administration's (NOAA) Solar Position Calculator
which rely on calculations of Jean Meeus' book "Astronomical Algorithms."
Use of NOAA data and products are in the public domain and may be used
freely by the public as outlined in their policies at
www.nws.noaa.gov/disclaimer.php
The calculations of this script can be verified with those of NOAA's
using the Azimuth and Solar Elevation displayed in the SunPos_Panel.
NOAA's web site is:
http://www.esrl.noaa.gov/gmd/grad/solcalc
"""
addon_prefs = bpy.context.preferences.addons[__package__].preferences addon_prefs = bpy.context.preferences.addons[__package__].preferences
sun_props = bpy.context.scene.sun_pos_properties sun_props = bpy.context.scene.sun_pos_properties
...@@ -381,9 +366,7 @@ def set_sun_position(obj, distance): ...@@ -381,9 +366,7 @@ def set_sun_position(obj, distance):
locY = math.sin(sun.theta) * math.cos(sun.phi) * distance locY = math.sin(sun.theta) * math.cos(sun.phi) * distance
locZ = math.cos(sun.theta) * distance locZ = math.cos(sun.theta) * distance
#----------------------------------------------
# Update selected object in viewport # Update selected object in viewport
#----------------------------------------------
obj.location = locX, locY, locZ obj.location = locX, locY, locZ
...@@ -475,13 +458,12 @@ def calc_sunrise_sunset(rise): ...@@ -475,13 +458,12 @@ def calc_sunrise_sunset(rise):
sun.sunset.azimuth = sun.azimuth sun.sunset.azimuth = sun.azimuth
sun.sunset.elevation = sun.elevation sun.sunset.elevation = sun.elevation
##########################################################################
## Get the elapsed julian time since 1/1/2000 12:00 gmt
## Y2k epoch (1/1/2000 12:00 gmt) is Julian day 2451545.0
##########################################################################
def julian_time_from_y2k(utc_time, year, month, day): def julian_time_from_y2k(utc_time, year, month, day):
"""
Get the elapsed julian time since 1/1/2000 12:00 gmt
Y2k epoch (1/1/2000 12:00 gmt) is Julian day 2451545.0
"""
century = 36525.0 # Days in Julian Century century = 36525.0 # Days in Julian Century
epoch = 2451545.0 # Julian Day for 1/1/2000 12:00 gmt epoch = 2451545.0 # Julian Day for 1/1/2000 12:00 gmt
jd = get_julian_day(year, month, day) jd = get_julian_day(year, month, day)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment