Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setMass; correct terrain sampling #763

Merged
merged 2 commits into from
Apr 11, 2024

Conversation

jmiskovic
Copy link
Contributor

For terrain sampling fix, this is the before and after.

image

image

world = lovr.physics.newWorld()
collider = world:newTerrainCollider(4, function(x, z) return 1 end, 128)

function lovr.draw(pass)
  pass:setProjection(1, mat4():orthographic(-3, 3, 3, -3, 0.01, 100))
  pass:plane(0, 0, 0,  4, 4, -math.pi/2, 1,0,0, 'line')
  for x = -5, 5, 0.2 do
    for z = -5, 5, 0.2 do
      o = vec3(x,  100, z)
      t = vec3(x, -100, z)
      world:raycast(o, t,
        function(shape, x, y, z, nx, ny, nz)
         pass:sphere(x, y, z, 0.05)
         pass:line(x, y, z, x+nx, y+ny, z+nz)
        end)
    end
  end
end

@bjornbytes
Copy link
Owner

Couldn't this also be / (n - 1) instead of / (n + 1)? That way the callback gives you this when samples = 2

-2.00, -2.00,
2.00, -2.00,
-2.00, 2.00
2.00, 2.00

instead of this

-2.00, -2.00
-.667, -2.00
-2.00, -.667
-.667, -.667

Also for some reason Jolt crashes when samples == 2, but that's a separate thing.

@jmiskovic
Copy link
Contributor Author

Yup, fixed. The screenshot was with n-1 but I submitted wrong version.

@bjornbytes
Copy link
Owner

Cool, looks good!

@bjornbytes bjornbytes merged commit 72e042f into bjornbytes:dev Apr 11, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants