Giter VIP home page Giter VIP logo

Comments (7)

nakedible avatar nakedible commented on July 4, 2024

I am seriously considering that both position and adjacent should be integer vectors instead, to fix this nonsense.

from voxel-engine.

theoxylo avatar theoxylo commented on July 4, 2024

I have a work-around in voxel-highlight (not committed) that pretty much takes that approach (convert hit position to voxel int coordinates array, then add normal):

  //var newVoxelPos = this.game.blockPosition(hit.position)
  var newVoxelPos = [
    Math.floor(hit.position[0]), 
    Math.floor(hit.position[1]), 
    Math.floor(hit.position[2])
  ]
  //var newVoxelAdj = this.game.blockPosition(hit.adjacent)
  var newVoxelAdj = newVoxelPos.slice()
  newVoxelAdj[0] += hit.normal[0]
  newVoxelAdj[1] += hit.normal[1]
  newVoxelAdj[2] += hit.normal[2]

Since this is a "voxel only" raycast and voxels can't move, maybe we don't need to know the exact hit or adjacent positions and can just use the voxel int coordinates? I guess it depends on what else this is used for -- highlight/erase/place only needs coordinates.

from voxel-engine.

max-mapper avatar max-mapper commented on July 4, 2024

1.999999999999999 === 2 but 1.99999999999999 === 1.99999999999999, so we could probably just truncate data after the 15th decimal place to get around this

from voxel-engine.

mikolalysenko avatar mikolalysenko commented on July 4, 2024

Actually, 1.9999999999999998 = 2.0 - MIN_FLOAT, and since (2.0-MIN_FLOAT) + 1 = 3, this is the intended behaviour. If you want the integer position of the hit, you can round it down to the nearest int; but getting the exact hit location is useful too. (For example, say you shoot a bullet and want to spawn a special effect at the point of impact.)

from voxel-engine.

max-mapper avatar max-mapper commented on July 4, 2024

i'm gonna Math.floor .position and use that to get .adjacent, and also return a new property voxel: [1,1,1]

from voxel-engine.

theoxylo avatar theoxylo commented on July 4, 2024

So we would get something like this back?

{
 position: [1.5503287987061696, 1.9999999999999998, 1.5288654983645178],
 voxel: [1, 1, 1],
 adjacent: [1, 2, 1],
 direction: [-0.16332358934799918, -0.4095857816495397, -0.8975326693959512],                                                                                     
 value: 1,                                                                                                     
 normal: [ 0, 1, 0 ]
}

That would be perfect!

from voxel-engine.

max-mapper avatar max-mapper commented on July 4, 2024

output is now:

# raycastVoxelsPrecise
{ position: [ 1.5503287987061696, 1.9999999999999998, 1.5288654983645178 ],
  voxel: [ 1, 1, 1 ],
  direction: 
   [ -0.16332358934799918,
     -0.4095857816495397,
     -0.8975326693959512 ],
  value: 1,
  normal: [ 0, 1, 0 ],
  adjacent: [ 1, 2, 1 ] }

from voxel-engine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.