0.2.1 • Published 13 years ago
voxel-raycast v0.2.1
voxel-raycast
Ray casting queries for voxel.js
Installation
Via npm:
npm install voxel-raycastExample
Here is how you could use the library to make a ray query:
var traceRay = require("voxel-raycast").bind({}, voxels);
var hit_normal = new Array(3);
var hit_position = new Array(3);
var hit_block = traceRay([0,0,0], [1,0,0], 10.0, hit_positions, hit_normal);
if(hit_block > 0) {
console.log("Hit:", hit_block, hit_position, hit_normal);
} else {
console.log("Miss");
}require("voxel-raycast")(voxels, origin, direction, max_d[, hit_position, hit_normal])
Casts a ray against a voxel.js game instance.
voxelsis the main voxel.js instanceoriginis the origin of the raydirectionis the direction of the raymax_dis a limit on the distance the ray can travelhit_positionis the point of impact of the ray and the voxel worldhit_normalis the normal of the ray impact
Returns the block type of the voxel that the ray cast hit, or if no voxel was encountered returns -1.
Credits
(c) 2013 Mikola Lysenko. BSD License