2018-12-28 00:11:43 +00:00
|
|
|
# coding=UTF-8
|
|
|
|
|
|
|
|
'''
|
2019-01-16 00:50:24 +00:00
|
|
|
Anaglyphed rotating cube (for red and green glasses)
|
|
|
|
|
|
|
|
This client uses the drawing functions (polyline) provided by LJ in lj.py
|
|
|
|
You must check in lj.py if the redis server IP is correct.
|
2018-12-28 00:11:43 +00:00
|
|
|
|
|
|
|
LICENCE : CC
|
|
|
|
'''
|
|
|
|
|
|
|
|
import redis
|
2019-01-16 00:50:24 +00:00
|
|
|
import lj
|
2018-12-28 00:11:43 +00:00
|
|
|
import math
|
|
|
|
import time
|
2019-01-16 00:50:24 +00:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
print ("")
|
|
|
|
print ("Arguments parsing if needed...")
|
|
|
|
argsparser = argparse.ArgumentParser(description="Text Cycling for LJ")
|
|
|
|
argsparser.add_argument("-r","--redisIP",help="IP of the Redis server used by LJ (127.0.0.1 by default) ",type=str)
|
|
|
|
argsparser.add_argument("-c","--client",help="LJ client number (0 by default)",type=int)
|
|
|
|
argsparser.add_argument("-l","--laser",help="Laser number to be displayed (0 by default)",type=int)
|
|
|
|
|
|
|
|
args = argsparser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
if args.client:
|
|
|
|
ljclient = args.client
|
|
|
|
else:
|
|
|
|
ljclient = 0
|
|
|
|
|
|
|
|
if args.laser:
|
|
|
|
plnumber = args.laser
|
|
|
|
else:
|
|
|
|
plnumber = 0
|
|
|
|
|
|
|
|
# Redis Computer IP
|
|
|
|
if args.redisIP != None:
|
|
|
|
redisIP = args.redisIP
|
|
|
|
else:
|
|
|
|
redisIP = '127.0.0.1'
|
2018-12-28 00:11:43 +00:00
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
lj.Config(redisIP,ljclient)
|
2018-12-28 00:11:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
width = 800
|
|
|
|
height = 600
|
|
|
|
centerX = width / 2
|
|
|
|
centerY = height / 2
|
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
# 3D to 2D projection parameters
|
2018-12-28 00:11:43 +00:00
|
|
|
fov = 256
|
|
|
|
viewer_distance = 2.2
|
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
|
|
|
|
# Anaglyph computation parameters for right and left eyes.
|
2018-12-28 00:11:43 +00:00
|
|
|
eye_spacing = 100
|
|
|
|
nadir = 0.5
|
|
|
|
observer_altitude = 30000
|
2019-01-01 10:13:12 +00:00
|
|
|
#observer_altitude = 10000
|
2018-12-28 00:11:43 +00:00
|
|
|
# elevation = z coordinate
|
2019-01-16 00:50:24 +00:00
|
|
|
# 0.0, -2000 pop out
|
2018-12-28 00:11:43 +00:00
|
|
|
map_plane_altitude = 0.0
|
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
# Cube coordinates
|
|
|
|
# Define the vertices that compose each of the 6 faces.
|
2018-12-28 00:11:43 +00:00
|
|
|
vertices = [
|
|
|
|
(- 1.0, 1.0,- 1.0),
|
|
|
|
( 1.0, 1.0,- 1.0),
|
|
|
|
( 1.0,- 1.0,- 1.0),
|
|
|
|
(- 1.0,- 1.0,- 1.0),
|
|
|
|
(- 1.0, 1.0, 1.0),
|
|
|
|
( 1.0, 1.0, 1.0),
|
|
|
|
( 1.0,- 1.0, 1.0),
|
|
|
|
(- 1.0,- 1.0, 1.0)
|
|
|
|
]
|
2019-01-01 10:13:12 +00:00
|
|
|
faces = [(0,1,2,3),(0,4,5,1),(1,5,6,2),(2,3,7,6),(6,5,4,7),(7,3,0,4)]
|
2018-12-28 00:11:43 +00:00
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
|
|
|
|
|
2018-12-28 00:11:43 +00:00
|
|
|
def LeftShift(elevation):
|
|
|
|
|
|
|
|
diff = elevation - map_plane_altitude
|
|
|
|
return nadir * eye_spacing * diff / (observer_altitude - elevation)
|
|
|
|
|
|
|
|
def RightShift(elevation):
|
|
|
|
|
|
|
|
diff = map_plane_altitude - elevation
|
|
|
|
return (1 - nadir) * eye_spacing * diff / (observer_altitude - elevation)
|
|
|
|
|
|
|
|
# If you want to use rgb for color :
|
|
|
|
def rgb2int(r,g,b):
|
|
|
|
return int('0x%02x%02x%02x' % (r,g,b),0)
|
|
|
|
|
|
|
|
|
|
|
|
def Proj(x,y,z,angleX,angleY,angleZ):
|
|
|
|
|
|
|
|
rad = angleX * math.pi / 180
|
|
|
|
cosa = math.cos(rad)
|
|
|
|
sina = math.sin(rad)
|
|
|
|
y2 = y
|
|
|
|
y = y2 * cosa - z * sina
|
|
|
|
z = y2 * sina + z * cosa
|
|
|
|
|
|
|
|
rad = angleY * math.pi / 180
|
|
|
|
cosa = math.cos(rad)
|
|
|
|
sina = math.sin(rad)
|
|
|
|
z2 = z
|
|
|
|
z = z2 * cosa - x * sina
|
|
|
|
x = z2 * sina + x * cosa
|
|
|
|
|
|
|
|
rad = angleZ * math.pi / 180
|
|
|
|
cosa = math.cos(rad)
|
|
|
|
sina = math.sin(rad)
|
|
|
|
x2 = x
|
|
|
|
x = x2 * cosa - y * sina
|
|
|
|
y = x2 * sina + y * cosa
|
|
|
|
|
|
|
|
|
|
|
|
""" Transforms this 3D point to 2D using a perspective projection. """
|
|
|
|
factor = fov / (viewer_distance + z)
|
|
|
|
x = x * factor + centerX
|
|
|
|
y = - y * factor + centerY
|
|
|
|
return (x,y)
|
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
def Run():
|
2018-12-28 00:11:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
Left = []
|
|
|
|
Right = []
|
|
|
|
counter =0
|
|
|
|
|
|
|
|
while 1:
|
2019-01-16 00:50:24 +00:00
|
|
|
|
2018-12-28 10:25:21 +00:00
|
|
|
Left = []
|
|
|
|
Right = []
|
2019-01-01 10:13:12 +00:00
|
|
|
|
|
|
|
x = vertices[0][0]
|
|
|
|
y = vertices[0][1]
|
|
|
|
z = vertices[0][2]
|
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
# The cube start always with vertice 0
|
|
|
|
# LJ tracers will "move" the laser to this first point in black, then move to the next with second point color.
|
2019-01-01 10:13:12 +00:00
|
|
|
# For more accuracy in dac emulator, repeat this first point.
|
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
# Cube Y axis rotation of 'counter' angle and 3d-2d Proj function.
|
|
|
|
#Left.append( Proj(x+LeftShift(z*5),y,z,0,counter,0))
|
|
|
|
#Right.append(Proj(x+RightShift(z*5),y,z,0,counter,0))
|
2019-01-01 10:13:12 +00:00
|
|
|
|
2018-12-28 00:11:43 +00:00
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
# Add all the cube points face by face.
|
|
|
|
for fa in faces:
|
2018-12-28 00:11:43 +00:00
|
|
|
for point in fa:
|
|
|
|
x = vertices[point][0]
|
|
|
|
y = vertices[point][1]
|
|
|
|
z = vertices[point][2]
|
|
|
|
|
2018-12-31 02:41:02 +00:00
|
|
|
Left.append( Proj(x+LeftShift(z*25),y,z,0,counter,0))
|
|
|
|
Right.append(Proj(x+RightShift(z*25),y,z,0,counter,0))
|
2018-12-28 00:11:43 +00:00
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
|
|
|
|
# Drawing step, 2 possibilities
|
|
|
|
|
|
|
|
# Red and Green drawn by laser 0
|
|
|
|
lj.PolyLineOneColor(Left, c = red, PL = 0, closed = True)
|
|
|
|
lj.PolyLineOneColor(Right, c = green, PL = 0, closed = True)
|
|
|
|
lj.DrawPL(0)
|
2018-12-28 10:25:21 +00:00
|
|
|
|
2018-12-28 00:11:43 +00:00
|
|
|
'''
|
2019-01-16 00:50:24 +00:00
|
|
|
# Red on laser 1 and green on laser 2
|
|
|
|
lj.PolyLineOneColor(Left, c = red, PL = 1, closed = True)
|
|
|
|
lj.PolyLineOneColor(Right, c = green, PL = 2, closed = True)
|
|
|
|
lj.DrawPL(1)
|
|
|
|
lj.DrawPL(2)
|
|
|
|
|
2018-12-28 00:11:43 +00:00
|
|
|
'''
|
2019-01-16 00:50:24 +00:00
|
|
|
|
2018-12-28 00:11:43 +00:00
|
|
|
time.sleep(0.1)
|
2019-01-16 00:50:24 +00:00
|
|
|
|
2019-01-01 10:13:12 +00:00
|
|
|
counter += 1
|
2018-12-28 00:11:43 +00:00
|
|
|
if counter >360:
|
|
|
|
counter =0
|
|
|
|
|
|
|
|
white = rgb2int(255,255,255)
|
|
|
|
red = rgb2int(255,0,0)
|
|
|
|
blue = rgb2int(0,0,255)
|
|
|
|
green = rgb2int(0,255,0)
|
|
|
|
|
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
Run()
|