Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #41

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/accessvis/data/earth_shader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ vec3 rgb2hsv(vec3 c)

void main(void)
{
//Clip planes in X/Y/Z
if (any(lessThan(vVertex, uClipMin)) || any(greaterThan(vVertex, uClipMax))) discard;

float alpha = 1.0; //fColour.a;
float mask = 0.0;
vec4 tColour = texture(uTexture, vTexCoord);
Expand Down
66 changes: 17 additions & 49 deletions src/accessvis/earth.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,32 @@ def paste_image(fn, xpos, ypos, out):
out[yoff : yoff + col.shape[1], xoff : xoff + col.shape[0]] = col


def latlon_to_3D(lat, lon, alt=0):
def lonlat_to_3D(lon, lat, alt=0):
"""
Convert lat/lon coord to 3D coordinate for visualisation
Uses simple spherical earth rather than true ellipse
see http://www.mathworks.de/help/toolbox/aeroblks/llatoecefposition.html
https://stackoverflow.com/a/20360045
"""
return latlon_to_3D_true(lat, lon, alt, flattening=0.0)
return lonlat_to_3D_true(lon, lat, alt, flattening=0.0)


def latlon_to_3D_true(lat, lon, alt=0, flattening=1.0 / 298.257223563):
def latlon_to_3D(lat, lon, alt=0, flattening=0.0):
"""
Convert lat/lon coord to 3D coordinate for visualisation
Convert lon/lat coord to 3D coordinate for visualisation

Provided for backwards compatibility as main function now reverses arg order of
(lat, lon) to (lon, lat)
"""
return lonlat_to_3D_true(lon, lat, alt, flattening)


def lonlat_to_3D_true(lon, lat, alt=0, flattening=1.0 / 298.257223563):
"""
Convert lon/lat coord to 3D coordinate for visualisation
Now using longitude, latitude, altitude order for more natural argument order
longitude=x, latitude=y, altitude=z

Uses flattening factor for elliptical earth
see http://www.mathworks.de/help/toolbox/aeroblks/llatoecefposition.html
https://stackoverflow.com/a/20360045
Expand Down Expand Up @@ -1190,51 +1203,6 @@ def vector_align(v1, v2, lvformat=True):
return qr


def lookat(lv, pos, lookat=None, up=None):
"""
Set the camera with a position coord and lookat coord

Parameters
----------
lv : lavavu.Viewer
The viewer object
pos : list/numpy.ndarray
Camera position in world coords
lookat : list/numpy.ndarray
Look at position in world coords, defaults to model origin
up : list/numpy.ndarray
Up vector, defaults to Y axis [0,1,0]
"""

# Use the origin from viewer if no target provided
if lookat is None:
lookat = lv["focus"]
else:
lv["focus"] = lookat

# Default to Y-axis up vector
if up is None:
up = np.array([0, 1, 0])

# Calculate the rotation matrix
heading = np.array(pos) - np.array(lookat)
zd = normalise(heading)
xd = normalise(np.cross(up, zd))
yd = normalise(np.cross(zd, xd))
q = quat.from_rotation_matrix(np.array([xd, yd, zd]))
q = q.normalized()

# Apply the rotation
lv.rotation(q.x, q.y, q.z, q.w)

# Translate back by heading vector length in Z
# (model origin in lavavu takes care of lookat offset)
tr = [0, 0, -magnitude(np.array(pos) - np.array(lookat))]

# Apply translation
lv.translation(tr)


def sun_light(
time=None,
now=False,
Expand Down
Loading