jeudi 26 janvier 2017

Virtual Reality using smartphone's sensors like a camera3d in real world including 3d virtual graphics written in Mintoris Basic Pro language!

VR works with sensors on smartphone coded in Mintoris Basic Pro language!
graphics on
WakeLock on
rounding on
orientation 2
sensors on

global hide
global x0, y0, z0, xorigin, yorigin
global a1, a2, a3, b1, b2, b3, c1, c2, c3, zoom, focal, rayon, distance
global hide
global azimuth,pitch,roll
dim o(3)
global alpha, theta, phi

xorigin = screenx()/2
yorigin = screeny()/2
theta = 0
phi = 0
distance = 5
x0 = 50
y0 = 0
z0 = 30
zoom = 3
focal = 150
rayon = 0
t = 0


do

o()= getorientation()
azimuth = -pi/180*o(0)
pitch= -pi/180*o(1)
roll= -pi/180*o(2)

color 0,0,0:CLS

teta = roll:phi =azimuth:alpha =-pitch

lookAt(teta, phi,alpha)

horizon(200):CUBE(30):axis(60)

touch x,y,1
loop while x=-1 and y=-1

END

sub delta(x, y, z)
return c1 * (x0 - x) + c2 * (y0 - y) + c3 * (z0 - z) + rayon + focal - distance
end sub

SUB CLIPPING(x1, y1, z1, x2, y2, z2)
test1 = delta(x1, y1, z1)
test2 = delta(x2, y2, z2)
hide = 0

IF test1 < 0 AND test2 < 0 THEN
hide = 1
GOTO fin
endif

IF test1 > 0 AND test2 > 0 THEN fin

IF test1 < 0 AND test2 > 0 THEN
xk = x1
yk = y1
zk = z1
landa = test2 / (c1 * (x2 - x1) + c2 * (y2 - y1) + c3 * (z2 - z1))
x1 = landa * (x2 - xk) + x2
y1 = landa * (y2 - yk) + y2
z1 = landa * (z2 - zk) + z2
GOTO fin
endif


IF test1 > 0 AND test2 < 0 THEN
xk = x2
yk = y2
zk = z2
landa = test1 / (c1 * (x2 - x1) + c2 * (y2 - y1) + c3 * (z2 - z1))
x2 = landa * (xk - x1) + x1
y2 = landa * (yk - y1) + y1
z2 = landa * (zk - z1) + z1
endif

fin:
END SUB


SUB CUBE(L)
color 100,100,100
line3d(-l, -l, -l, -l, -l, l)
line3d(-l, l, -l, -l, l, l)
line3d(l, l, -l, l, l, l)
line3d(l, -l, -l, l, -l, l)

line3d(-l, -l, l, -l, l, l)
line3d(-l, l, l, l, l, l)
line3d(l, l, l, l, -l, l)
line3d(l, -l, l, -l, -l, l)

line3d(-l, -l, -l, -l, l, -l)
line3d(-l, l, -l, l, l, -l)
line3d(l, l, -l, l, -l, -l)
line3d(l, -l, -l, -l, -l, -l)

'triangle3d(-l,-l,2*l,-l,l,2*l,l,l,2*l)
END SUB

SUB doprojection(x, y, z, xp, yp)
x=x-x0:y=y-y0:z=z-z0
Zdepth = -zoom*focal / (c1*x+ c2*y+c3*z - rayon - focal)
yp= Zdepth * (b1 * x + b2 * y +b3*z) +yorigin
xp= -Zdepth * (a1 * x + a2 * y + a3 * z ) +xorigin
END SUB

SUB horizon(p)
color 30,30,30
FOR k = -p TO p STEP 80
line3d(-p, k, 0, p, k, 0)
line3d(k, -p, 0, k, p, 0)
next k
END SUB

SUB line3d(x1, y1, z1, x2 , y2 , z2 )
CLIPPING(&x1, &y1, &z1, &x2, &y2, &z2)
IF hide = 0 THEN
doprojection(x1, y1, z1, &xp1, &yp1)
doprojection(x2, y2, z2, &xp2, &yp2)
LINE xp1, yp1,xp2, yp2
endif
END SUB


SUB triangle3d(x1, y1, z1, x2 , y2 , z2,x3,y3,z3 )
'CLIPPING(&x1, &y1, &z1, &x2, &y2, &z2)
'IF hide = 0 THEN
doprojection(x1, y1, z1, &xp1, &yp1)
doprojection(x2, y2, z2, &xp2, &yp2)
doprojection(x3, y3, z3, &xp3, &yp3)

triangle xp1, yp1,xp2, yp2,xp3,yp3,1
endif
END SUB

SUB lookAt(t, f,a)
teta = t
phi = f
alpha =a
ct = cos(teta)
st = sin(teta)
cf = cos(phi)
sf = sin(phi)
ca= cos(alpha)
sa= sin(alpha)

c1 = sf*st
c2 = -cf* st
c3 = ct
b1 = -cf*sa-sf*ct*ca
b2 = -sf*sa+cf*ct*ca
b3 = st*ca

a1 = cf*ca-sf*ct*sa
a2 = sf*ca+cf*ct*sa
a3 = st*sa
end sub

sub point3d(x, y, z)
test = delta(x, y, z)
IF test > 0 THEN
doprojection(x, y, z, &xp, &yp)
color 100,100,100
point xp, yp
endif
end sub


sub drawtext3d(t$,x, y, z)
test = delta(x, y, z)
IF test > 0 THEN
doprojection(x, y, z, &xp, &yp)
textsize 30
drawtext t$,xp,yp,90,0
endif
end sub


sub axi(L)
color 100,100,0
line3d(0,0,0,l,0,0)
textcolor 100,100,0
drawtext3d("X",l ,0,0)

color 100,0,0
line3d(0,0,0,0,l,0)
textcolor 100,0,0
drawtext3d("Y",0 ,l,0)

color 100,0,0
line3d(0,0,0,0,0,l)
textcolor 0,0,100
drawtext3d("Z",0 ,0,l)
end sub

Aucun commentaire:

Enregistrer un commentaire

Remarque : Seul un membre de ce blog est autorisé à enregistrer un commentaire.