Comments (7)
I am seriously considering that both position and adjacent should be integer vectors instead, to fix this nonsense.
from voxel-engine.
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.
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.
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.
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.
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.
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)
- esprima-six module is not reachable anymore HOT 8
- Forcing master branch to render blocks HOT 2
- Large positions cause strange behavior, glitchly camera, falling through blocks, no rendering. HOT 2
- Async loading of chunks HOT 1
- Shading planned
- Do I need a backend server for this usage scenario? HOT 3
- Why not use requestAnimationFrame instead of setInterval ?
- How to regenerate terrain? HOT 1
- How to create a world with voxel that serves multi-player? HOT 1
- How to check whether or not the mouse pointer is locked in game or not. HOT 1
- setBlock() does not update canvas until mouse click HOT 1
- How to use RessourcePack textures in voxel.js ? HOT 1
- Runing the Voxel Engine..
- How to Fix Voxel Bugs
- textures don't work?
- Add TypeScript definitions
- document.getElementById("game") is not a Node HOT 1
- All textures are black
- voxeljs.com is now parked by a domain squatter HOT 2
- Is the website hacked? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from voxel-engine.