Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add naive position smoothing
- Loading branch information
Showing
6 changed files
with
59 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
(in-package :mortar-combat) | ||
|
||
|
||
(defclass proxy () | ||
((position :initform (vec2)) ; f(x,y) field space = f(x,-z) global space | ||
(rotation :initform (vec2) :accessor rotation-of) | ||
(updated-at :initform (real-time-seconds)) | ||
|
||
(next-position :initform (vec2)) | ||
(next-rotation :initform (vec2)) | ||
(next-at :initform (real-time-seconds)) | ||
|
||
(correction :initform 0.0))) | ||
|
||
|
||
(defun proxy-lerp-factor (proxy) | ||
(with-slots (updated-at next-at correction) proxy | ||
(let* ((now (- (real-time-seconds) correction)) | ||
(delta (- next-at updated-at))) | ||
(if (= delta 0.0) 1.0 (/ (- now next-at) delta))))) | ||
|
||
|
||
(defmethod position-of ((this proxy)) | ||
(with-slots (position next-position) this | ||
(lerp position next-position (proxy-lerp-factor this)))) | ||
|
||
|
||
(defmethod rotation-of ((this proxy)) | ||
(with-slots (rotation next-rotation) this | ||
(lerp rotation next-rotation (proxy-lerp-factor this)))) | ||
|
||
|
||
(defun update-proxy (proxy pos rot timestamp) | ||
(with-slots (next-position next-at position updated-at | ||
correction rotation next-rotation) | ||
proxy | ||
(setf correction (- (real-time-seconds) timestamp) | ||
|
||
position (position-of proxy) | ||
rotation (rotation-of proxy) | ||
updated-at next-at | ||
|
||
next-position pos | ||
next-rotation rot | ||
next-at timestamp))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters