Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

53 wiersze
1.2 KiB

  1. (import "oo.slime")
  2. (define-class vector3 (x y z)
  3. (define (get-x) x)
  4. (define (get-y) y)
  5. (define (get-z) z)
  6. (define (set-x new-x) (mutate x new-x))
  7. (define (set-y new-y) (mutate y new-y))
  8. (define (set-z new-z) (mutate z new-z))
  9. (define (length)
  10. (** (+ (* x x) (* y y) (* z z)) 0.5))
  11. (define (scale fac)
  12. (mutate x (* fac x))
  13. (mutate y (* fac y))
  14. (mutate z (* fac z))
  15. fac)
  16. (define (add other)
  17. (make-vector3
  18. (+ x (other get-x))
  19. (+ y (other get-y))
  20. (+ z (other get-z))))
  21. (define (subtract other)
  22. (make-vector3
  23. (- x (other get-x))
  24. (- y (other get-y))
  25. (- z (other get-z))))
  26. (define (scalar-product other)
  27. (+ (* x (other get-x))
  28. (* y (other get-y))
  29. (* z (other get-z))))
  30. (define (cross-product other)
  31. (make-vector3
  32. (- (* y (other get-z)) (* z (other get-y)))
  33. (- (* z (other get-x)) (* x (other get-z)))
  34. (- (* x (other get-y)) (* y (other get-x)))))
  35. (define (print)
  36. (printf :sep "" "[vector3] (" x y z ")"))
  37. )
  38. (define v1 (make-vector3 1 2 3))
  39. (define v2 (make-vector3 3 2 1))
  40. (assert (= (type v1) (type v2) :vector3))
  41. (assert (= (v1 scalar-product v2) 10))