1
0

Added simple trajectory sample

This commit is contained in:
neviyn 2020-07-21 19:11:22 +01:00
parent 8404e2b025
commit 7fdb5faeaf
2 changed files with 26 additions and 3 deletions

3
.gitignore vendored
View File

@ -57,3 +57,6 @@ $RECYCLE.BIN/
*.lnk *.lnk
# End of https://www.toptal.com/developers/gitignore/api/code,nim,linux,windows # End of https://www.toptal.com/developers/gitignore/api/code,nim,linux,windows
raytracer_nim
output.ppm

View File

@ -1,5 +1,25 @@
# This is just an example to get you started. A typical binary package import "./tuple", "./canvas"
# uses this file as the main entry point of the application.
type
Projectile = object
position: Tuple4
velocity: Tuple4
Environment = object
gravity: Tuple4
wind: Tuple4
proc tick(proj: Projectile, env: Environment): Projectile = Projectile(position: proj.position + proj.velocity, velocity: proj.velocity + env.gravity + env.wind)
when isMainModule: when isMainModule:
echo("Hello, World!") var world = canvas(800, 600)
let start = point(0, 1, 0)
let velocity = normalize(vector(0.5, 1.2, 0)) * 11.25
var projectile = Projectile(position: start, velocity: velocity)
let environment = Environment(gravity: vector(0, -0.1, 0), wind: vector(-0.01, 0, 0))
let colour = colour(1, 0, 0)
while projectile.position.x >= 0 and projectile.position.x < 800 and projectile.position.y >= 0 and projectile.position.y < 600:
world.writePixel(projectile.position.x, 600 - projectile.position.y, colour)
projectile = projectile.tick(environment)
writeFile("output.ppm", world.toPPM())