# Chapter 23 (Animation) - A small coding question (probably more of a style question)

**URL:** <https://forums.kodeco.com/t/chapter-23-animation-a-small-coding-question-probably-more-of-a-style-question/207349>\
**Category:** Metal by Tutorials\
**Created:** [November 20, 2024, 2:14pm UTC](https://forums.kodeco.com/t/chapter-23-animation-a-small-coding-question-probably-more-of-a-style-question/207349 "2024-11-20T14:14:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![petenish](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/petenish/32/110937_2.png) [@petenish](https://forums.kodeco.com/u/petenish)\
**Post date:** [November 20, 2024, 2:14pm UTC](https://forums.kodeco.com/t/chapter-23-animation-a-small-coding-question-probably-more-of-a-style-question/207349/1 "2024-11-20T14:14:30Z")

</div>

Hi,

In Chapter 23 (Animation), once all the transform stuff was implemented, in ./Game/Render  
ing.swift, the your sample code contains:

```
for mesh in meshes {
  let currentLocalTransform =
    mesh.transform?.currentTransform ?? .identity
  uniforms.modelMatrix =
    transform.modelMatrix * currentLocalTransform
  uniforms.normalMatrix = uniforms.modelMatrix.upperLeft
  encoder.setVertexBytes(
    &uniforms,
    length: MemoryLayout<Uniforms>.stride,
    index: UniformsBuffer.index)

```

So, as I was going through the tutorial, I fat fingered the assignment of uniforms.modelMatrix and, in my code, I had:

```
 uniforms.modelMatrix =
    currentLocalTransform

```

Initially, I fixed this by adding the code (to the previous line)

```
  let currentLocalTransform =
    mesh.transform?.currentTransform ?? transform.modelMatrix

```

And this “fixed” my typo.

I did go back to your code and found my mis-type.

My question: I’m “pretty sure” (for varying degrees of “pretty sure”) that the code is  
equivalent, but can you see any situation where it wouldn’t be? I’m trying to make sure I didn’t “miss” any potential problem.

Thanks for your patience

---

<div class="post-metadata">

**Author:** ![robertomachorro](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/robertomachorro/32/111603_2.png) [@robertomachorro](https://forums.kodeco.com/u/robertomachorro)\
**Post date:** [November 20, 2024, 5:25pm UTC](https://forums.kodeco.com/t/chapter-23-animation-a-small-coding-question-probably-more-of-a-style-question/207349/2 "2024-11-20T17:25:21Z")

</div>

Just a casual observer here, but it all depends on the values. There could be moments which the results will match, and some that won’t.

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [November 20, 2024, 11:26pm UTC](https://forums.kodeco.com/t/chapter-23-animation-a-small-coding-question-probably-more-of-a-style-question/207349/3 "2024-11-20T23:26:31Z")

</div>

If you run the final sample code, you will immediately see the difference.

The ground disappears.

The ground is scaled up by 40, so `transform.modelMatrix` contains

```auto
[0, 40, 0, 0]
[-40, 0, 0, 0]
[0, 0, 40, 0] 
[0, 0, 0, 1]

```

The base transform is scaled by 40, so the local transform shouldn’t be scaled again.
