Animations!
This commit is contained in:
parent
d3e27026ef
commit
0d12bc4156
24
tinyrender1_perspective/animation.sh
Executable file
24
tinyrender1_perspective/animation.sh
Executable file
@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "You must pass the basename for the animation folder"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Building"
|
||||
go build
|
||||
mkdir -p $1
|
||||
|
||||
echo "Running"
|
||||
|
||||
frame=0
|
||||
for x in $(seq -3 0.1 3); do
|
||||
ff=$(printf "%03d" $frame)
|
||||
./tinyrender1 "-xofs=$x" "-zofs=-1.8" "-fov=70" >"$1/$ff.ppm"
|
||||
frame=$((frame + 1))
|
||||
done
|
||||
|
||||
echo "Converting animation"
|
||||
|
||||
cd $1
|
||||
convert -delay 5 -loop 0 *.ppm -resize 256x256 anim.gif
|
@ -11,11 +11,11 @@ import (
|
||||
const (
|
||||
Width = 512
|
||||
Height = 512
|
||||
FOV = 110
|
||||
FOV = 70
|
||||
NearClip = 0.1
|
||||
FarClip = 2 // Because the head is so small and close
|
||||
FarClip = 5 // Because the head is so small and close
|
||||
ObjectFile = "head.obj"
|
||||
Repeat = 1000
|
||||
Repeat = 1 // Because I want to see an animation
|
||||
)
|
||||
|
||||
func must(err error) {
|
||||
@ -26,6 +26,9 @@ func must(err error) {
|
||||
|
||||
// However flag works... idk
|
||||
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
|
||||
var xofs = flag.Float64("xofs", 0, "Offset image by x")
|
||||
var zofs = flag.Float64("zofs", -1.5, "Offset image by z (should be negative)")
|
||||
var fov = flag.Float64("fov", 90, "Field of view")
|
||||
|
||||
func main() {
|
||||
log.Printf("Program start")
|
||||
@ -59,9 +62,10 @@ func main() {
|
||||
|
||||
var projection Mat44f
|
||||
var worldToCamera Mat44f
|
||||
projection.SetProjection(FOV, NearClip, FarClip)
|
||||
projection.SetProjection(float32(*fov), NearClip, FarClip)
|
||||
worldToCamera.SetIdentity()
|
||||
worldToCamera.Set(2, 3, -1) // Get farther away from the face
|
||||
worldToCamera.Set(0, 3, float32(*xofs)) // Let user decide how to offset x
|
||||
worldToCamera.Set(2, 3, float32(*zofs)) // Get farther away from the face (user)
|
||||
|
||||
var x [3]int
|
||||
var y [3]int
|
||||
@ -78,7 +82,8 @@ func main() {
|
||||
fp = projection.MultiplyPoint3(fp)
|
||||
x[i] = int((fp.X + 1) * halfwidth)
|
||||
y[i] = hi - int((fp.Y+1)*halfheight)
|
||||
c[i] = Col2Uint(byte(0xFF*fp.Z), byte(0xFF*fp.Z), byte(0xFF*fp.Z))
|
||||
c[i] = 0xFFFFFF
|
||||
//c[i] = Col2Uint(byte(0xFF*fp.Z), byte(0xFF*fp.Z), byte(0xFF*fp.Z))
|
||||
}
|
||||
Bresenham2(&fb, c[0], x[0], y[0], x[1], y[1])
|
||||
Bresenham2(&fb, c[1], x[1], y[1], x[2], y[2])
|
||||
|
Loading…
Reference in New Issue
Block a user