-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash3d.sh
executable file
·62 lines (54 loc) · 1.82 KB
/
bash3d.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# Amit Bakshi ([email protected])
# 2/25/2012
function dot3 {
echo $(( $1 * $4 + $2 * $5 + $3 * $6 ))
}
function mul3 {
echo $(( $1 * $4 )) $(( $2 * $5 )) $(( $3 * $6 ))
}
function xform {
echo $(dot3 $1 $2 $3 $4 $5 $6) \
$(dot3 $1 $2 $3 $7 $8 $9) \
$(dot3 $1 $2 $3 ${10} ${11} ${12})
}
function axisrot {
local x=$1 y=$2 z=$3 a=$4
local c=`echo $a | awk '{print cos($1) * 100 }' | sed -e 's/\..*//g'`
local s=`echo $a | awk '{print sin($1) * 100 }' | sed -e 's/\..*//g'`
local t=$(( 100 - $c ))
echo $(( $t * $x * $x + $c )) $(( $t * $x * $y - $z * $s )) $(( $t * $x * $z + $y * $s )) \
$(( $t * $x * $y + $z * $s )) $(( $t * $y * $y + $c )) $(( $t * $y * $z + $x * $s )) \
$(( $t * $x * $z + $y * $s )) $(( $t * $y * $z + $x * $s )) $(( $t * $z * $z + $c ))
}
declare -i width=`tput cols`
declare -i height=$LINES
declare -i hwidth=$(( $width / 2 ))
declare -i hheight=$(( $height / 2 ))
function drawxy {
local -i x=$1
local -i y=$2
local -i z=$3
local -i c=$4
tput cup $(( y + hheight )) $(( x + hwidth ))
printf "%s" $c
}
declare -a v1=( 7 7 1 )
declare -a v2=( 17 17 1 )
declare -a v3=( 9 9 1 )
rot=0.0
for i in {0..1000}; do
# increment rotation
rot=`echo $rot | awk '{print $1 + 0.1}'`
vec1=( `echo $(xform ${v1[@]} $(axisrot 70 70 0 $rot)) | awk '{printf("%d %d %d",\$1/1000000,\$2/1000000,\$3/1000000)}'` )
vec2=( `echo $(xform ${v2[@]} $(axisrot 70 70 0 $rot)) | awk '{printf("%d %d %d",\$1/1000000,\$2/1000000,\$3/1000000)}'` )
vec3=( `echo $(xform ${v3[@]} $(axisrot 70 70 0 $rot)) | awk '{printf("%d %d %d",\$1/1000000,\$2/1000000,\$3/1000000)}'` )
tput clear
echo ${vec1[@]}
echo ${vec2[@]}
echo ${vec3[@]}
drawxy ${vec1[@]} "A"
drawxy ${vec2[@]} "B"
drawxy ${vec3[@]} "C"
sleep 0.1
done