Replies: 2 comments
-
For matrices, https://ebiten.org/documents/matrix.html might be a good tutorial. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I think I solved this for my purposes by just translating by the camera's available X/Y. Would be good to know from anyone if this is a good approach or not: func (g *Game) Draw(screen *ebiten.Image) {
g.Camera.Surface.Clear()
drawopt := &ebiten.DrawImageOptions{}
for _, obj := range g.Root.Render.Objects {
drawopt.GeoM.Reset()
drawopt.GeoM.Concat(obj.DrawOpts.GeoM)
drawopt.GeoM.Translate(-g.Camera.X, -g.Camera.Y)
g.Camera.Surface.DrawImage(obj.Image, drawopt)
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Everyone,
I'm just getting started with ebiten and given my lackluster understanding of matrix math I'm struggling with a fairly simple transforms that include a camera/view matrix. My gamedev dabbling has usually been in engines that mostly handle this for you so any links with easy to digest explanations would also be wonderful.
My game would benefit from a scene tree where objects can be parented to inherit position and rotation (saving scale/skew for another day) from their parents all the way up to the root of the tree. Here is my naive implementation:
The idea being that any object in the tree can be translated or rotated relative to the parent and all children will be updated to reflect those changes. We don't need to calculate the entire tree's final transform on each update/draw as the calculation is only done when an object's
Translate
orRotate
methods are called, saving calculation of transform on objects that rarely/never move.This works great when drawing pure world space geometry. But I think I have order of operations wrong when introducing the
ebiten-camera
library into the mix.My game object sorts the tree into a flat list and iterates over all objects to draw them. This is where I introduce the camera and attempt to apply each objects transform to the cameras transform:
This again works fine when none of my objects are rotated in world space. However if I rotate any objects in my scene tree prior to applying the camera's transform, The objects in world space get translated by the cameras transform relative to their "up vector?" meaning if I have a world object rotated 180deg when moving the camera
down
the object movesdown
as well instead ofup
as you would expect.Some options I'm toying with:
camera
aware, and apply the cameras transform when callingcalcgeom()
. Probably requires the entire scene tree to be recalculated regardless if only a nested object changed.How do others handle this in their engines? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions