no more js
This commit is contained in:
18
collision.cm
18
collision.cm
@@ -1,5 +1,7 @@
|
||||
// Collision module for lance3d
|
||||
|
||||
var math = use('math/radians')
|
||||
|
||||
// Private collider storage
|
||||
var _colliders = []
|
||||
var _collider_id = 0
|
||||
@@ -70,7 +72,7 @@ function raycast(ox, oy, oz, dx, dy, dz, opts) {
|
||||
var layer_mask = opts.layer_mask || 0xFFFFFFFF
|
||||
|
||||
// Normalize direction
|
||||
var len = Math.sqrt(dx*dx + dy*dy + dz*dz)
|
||||
var len = math.sqrt(dx*dx + dy*dy + dz*dz)
|
||||
if (len < 0.0001) return null
|
||||
dx /= len
|
||||
dy /= len
|
||||
@@ -119,11 +121,11 @@ function _check_collision(a, b) {
|
||||
var dx = pb.x - pa.x
|
||||
var dy = pb.y - pa.y
|
||||
var dz = pb.z - pa.z
|
||||
var dist = Math.sqrt(dx*dx + dy*dy + dz*dz)
|
||||
var dist = math.sqrt(dx*dx + dy*dy + dz*dz)
|
||||
|
||||
// Simple sphere-sphere approximation
|
||||
var ra = a.radius || Math.max(a.sx || 0, a.sy || 0, a.sz || 0)
|
||||
var rb = b.radius || Math.max(b.sx || 0, b.sy || 0, b.sz || 0)
|
||||
var ra = a.radius || number.max(a.sx || 0, a.sy || 0, a.sz || 0)
|
||||
var rb = b.radius || number.max(b.sx || 0, b.sy || 0, b.sz || 0)
|
||||
return dist < ra + rb
|
||||
}
|
||||
|
||||
@@ -144,7 +146,7 @@ function _ray_sphere(ox, oy, oz, dx, dy, dz, sphere) {
|
||||
var r2 = r*r
|
||||
if (d2 > r2) return null
|
||||
|
||||
var thc = Math.sqrt(r2 - d2)
|
||||
var thc = math.sqrt(r2 - d2)
|
||||
var t = tca - thc
|
||||
if (t < 0) t = tca + thc
|
||||
if (t < 0) return null
|
||||
@@ -180,7 +182,7 @@ function _ray_box(ox, oy, oz, dx, dy, dz, box) {
|
||||
var nx = 0, ny = 0, nz = 0
|
||||
|
||||
// X slab
|
||||
if (Math.abs(dx) > 0.0001) {
|
||||
if (number.abs(dx) > 0.0001) {
|
||||
var t1 = (minx - ox) / dx
|
||||
var t2 = (maxx - ox) / dx
|
||||
if (t1 > t2) { var tmp = t1; t1 = t2; t2 = tmp }
|
||||
@@ -191,7 +193,7 @@ function _ray_box(ox, oy, oz, dx, dy, dz, box) {
|
||||
}
|
||||
|
||||
// Y slab
|
||||
if (Math.abs(dy) > 0.0001) {
|
||||
if (number.abs(dy) > 0.0001) {
|
||||
var t1 = (miny - oy) / dy
|
||||
var t2 = (maxy - oy) / dy
|
||||
if (t1 > t2) { var tmp = t1; t1 = t2; t2 = tmp }
|
||||
@@ -202,7 +204,7 @@ function _ray_box(ox, oy, oz, dx, dy, dz, box) {
|
||||
}
|
||||
|
||||
// Z slab
|
||||
if (Math.abs(dz) > 0.0001) {
|
||||
if (number.abs(dz) > 0.0001) {
|
||||
var t1 = (minz - oz) / dz
|
||||
var t2 = (maxz - oz) / dz
|
||||
if (t1 > t2) { var tmp = t1; t1 = t2; t2 = tmp }
|
||||
|
||||
24
core.cm
24
core.cm
@@ -12,6 +12,8 @@ var resources_mod = use('resources')
|
||||
var camera_mod = use('camera')
|
||||
var math_mod = use('math')
|
||||
|
||||
var math = use('math/radians')
|
||||
|
||||
// Style configurations (PS1, N64, Saturn)
|
||||
var _styles = {
|
||||
ps1: {
|
||||
@@ -190,7 +192,7 @@ function log_msg() {
|
||||
function set_lighting(opts) {
|
||||
if (opts.sun_dir) {
|
||||
var d = opts.sun_dir
|
||||
var len = Math.sqrt(d[0]*d[0] + d[1]*d[1] + d[2]*d[2])
|
||||
var len = math.sqrt(d[0]*d[0] + d[1]*d[1] + d[2]*d[2])
|
||||
if (len > 0) {
|
||||
_state.lighting.sun_dir = [d[0]/len, d[1]/len, d[2]/len]
|
||||
}
|
||||
@@ -275,15 +277,15 @@ function make_sphere(r, segments) {
|
||||
|
||||
for (var y = 0; y <= segments; y++) {
|
||||
var v = y / segments
|
||||
var theta = v * 3.14159265
|
||||
var theta = v * pi
|
||||
|
||||
for (var x = 0; x <= segments; x++) {
|
||||
var u = x / segments
|
||||
var phi = u * 2 * 3.14159265
|
||||
var phi = u * 2 * pi
|
||||
|
||||
var nx = Math.sin(theta) * Math.cos(phi)
|
||||
var ny = Math.cos(theta)
|
||||
var nz = Math.sin(theta) * Math.sin(phi)
|
||||
var nx = math.sine(theta) * math.cosine(phi)
|
||||
var ny = math.cosine(theta)
|
||||
var nz = math.sine(theta) * math.sine(phi)
|
||||
|
||||
positions.push(nx * r, ny * r, nz * r)
|
||||
normals.push(nx, ny, nz)
|
||||
@@ -312,9 +314,9 @@ function make_cylinder(r, h, segments) {
|
||||
|
||||
for (var i = 0; i <= segments; i++) {
|
||||
var u = i / segments
|
||||
var angle = u * 2 * 3.14159265
|
||||
var nx = Math.cos(angle)
|
||||
var nz = Math.sin(angle)
|
||||
var angle = u * 2 * pi
|
||||
var nx = math.cosine(angle)
|
||||
var nz = math.sine(angle)
|
||||
|
||||
positions.push(nx * r, -hh, nz * r)
|
||||
normals.push(nx, 0, nz)
|
||||
@@ -528,7 +530,7 @@ function draw_billboard(texture, x, y, z, size, mat) {
|
||||
var cam_eye = camera_mod.get_eye()
|
||||
var dx = cam_eye.x - x
|
||||
var dz = cam_eye.z - z
|
||||
var yaw = Math.atan2(dx, dz)
|
||||
var yaw = math.atan2(dx, dz)
|
||||
var q = math_mod.euler_to_quat(0, yaw, 0)
|
||||
|
||||
var transform = math_mod.trs_matrix(x, y, z, q.x, q.y, q.z, q.w, size, size, 1)
|
||||
@@ -758,6 +760,8 @@ return {
|
||||
keyp: input_mod.keyp,
|
||||
axis: input_mod.axis,
|
||||
|
||||
switch_style,
|
||||
|
||||
// Math
|
||||
seed: math_mod.seed,
|
||||
rand: math_mod.rand,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
var time_mod = use('time')
|
||||
var lance3d = use('core')
|
||||
var math = use('math/radians')
|
||||
|
||||
// Camera orbit state
|
||||
var cam_distance = 5
|
||||
@@ -107,9 +108,9 @@ function _draw() {
|
||||
lance3d.camera_perspective(60, 0.1, 100)
|
||||
|
||||
// Calculate camera position from orbit
|
||||
var cam_x = Math.sin(cam_yaw) * Math.cos(cam_pitch) * cam_distance
|
||||
var cam_y = Math.sin(cam_pitch) * cam_distance + 0.5
|
||||
var cam_z = Math.cos(cam_yaw) * Math.cos(cam_pitch) * cam_distance
|
||||
var cam_x = math.sine(cam_yaw) * math.cosine(cam_pitch) * cam_distance
|
||||
var cam_y = math.sine(cam_pitch) * cam_distance + 0.5
|
||||
var cam_z = math.cosine(cam_yaw) * math.cosine(cam_pitch) * cam_distance
|
||||
|
||||
lance3d.camera_look_at(cam_x, cam_y, cam_z, 0, 0.5, 0)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
var time_mod = use('time')
|
||||
var lance3d = use('core')
|
||||
var math = use('math/radians')
|
||||
|
||||
// Meshes
|
||||
var ground_mesh = null
|
||||
@@ -104,12 +105,12 @@ function _update(dt) {
|
||||
|
||||
if (forward != 0 || right != 0) {
|
||||
// Update yaw based on movement direction
|
||||
player.yaw = Math.atan2(forward, -right)
|
||||
player.yaw = math.arc_tangent(forward, -right)
|
||||
|
||||
var fx = Math.sin(player.yaw)
|
||||
var fz = Math.cos(player.yaw)
|
||||
var fx = math.sine(player.yaw)
|
||||
var fz = math.cosine(player.yaw)
|
||||
|
||||
var len = Math.sqrt(fx * fx + fz * fz)
|
||||
var len = math.sqrt(fx * fx + fz * fz)
|
||||
if (len > 0) {
|
||||
fx /= len
|
||||
fz /= len
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
var io = use('fd')
|
||||
var time_mod = use('time')
|
||||
var lance3d = use('core')
|
||||
var math = use('math/radians')
|
||||
|
||||
log.console(lance3d.key)
|
||||
|
||||
@@ -193,9 +194,9 @@ function _draw() {
|
||||
lance3d.camera_perspective(60, 0.1, 100)
|
||||
|
||||
// Calculate camera position from orbit
|
||||
var cam_x = Math.sin(cam_yaw) * Math.cos(cam_pitch) * cam_distance
|
||||
var cam_y = Math.sin(cam_pitch) * cam_distance + cam_target_y
|
||||
var cam_z = Math.cos(cam_yaw) * Math.cos(cam_pitch) * cam_distance
|
||||
var cam_x = math.sine(cam_yaw) * math.cosine(cam_pitch) * cam_distance
|
||||
var cam_y = math.sine(cam_pitch) * cam_distance + cam_target_y
|
||||
var cam_z = math.cosine(cam_yaw) * math.cosine(cam_pitch) * cam_distance
|
||||
|
||||
lance3d.camera_look_at(cam_x, cam_y, cam_z, 0, cam_target_y, 0)
|
||||
|
||||
|
||||
18
math.cm
18
math.cm
@@ -1,5 +1,7 @@
|
||||
// Math module for lance3d
|
||||
var model_c = use('model')
|
||||
var math = use('math/radians')
|
||||
var random = use('random')
|
||||
|
||||
// Private RNG state
|
||||
var _rng_seed = 12345
|
||||
@@ -15,7 +17,7 @@ function rand() {
|
||||
}
|
||||
|
||||
function irand(min_inclusive, max_inclusive) {
|
||||
return Math.floor(rand() * (max_inclusive - min_inclusive + 1)) + min_inclusive
|
||||
return number.floor(rand() * (max_inclusive - min_inclusive + 1)) + min_inclusive
|
||||
}
|
||||
|
||||
// Matrix helpers
|
||||
@@ -40,12 +42,12 @@ function trs_matrix(x, y, z, qx, qy, qz, qw, sx, sy, sz) {
|
||||
}
|
||||
|
||||
function euler_to_quat(pitch, yaw, roll) {
|
||||
var cy = Math.cos(yaw * 0.5)
|
||||
var sy = Math.sin(yaw * 0.5)
|
||||
var cp = Math.cos(pitch * 0.5)
|
||||
var sp = Math.sin(pitch * 0.5)
|
||||
var cr = Math.cos(roll * 0.5)
|
||||
var sr = Math.sin(roll * 0.5)
|
||||
var cy = math.cosine(yaw * 0.5)
|
||||
var sy = math.sine(yaw * 0.5)
|
||||
var cp = math.cosine(pitch * 0.5)
|
||||
var sp = math.sine(pitch * 0.5)
|
||||
var cr = math.cosine(roll * 0.5)
|
||||
var sr = math.sine(roll * 0.5)
|
||||
|
||||
return {
|
||||
x: sr * cp * cy - cr * sp * sy,
|
||||
@@ -90,7 +92,7 @@ function vec3_cross(a, b) {
|
||||
}
|
||||
|
||||
function vec3_length(v) {
|
||||
return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z)
|
||||
return math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z)
|
||||
}
|
||||
|
||||
function vec3_normalize(v) {
|
||||
|
||||
10
resources.cm
10
resources.cm
@@ -11,7 +11,7 @@ var skin_mod = use('skin')
|
||||
var _backend = null
|
||||
|
||||
// Texture original data storage for re-resizing on style change
|
||||
var TEX_ORIGINAL = Symbol("texture_original")
|
||||
var TEX_ORIGINAL = key("texture_original")
|
||||
|
||||
// Default material prototype
|
||||
var _default_material = {
|
||||
@@ -47,9 +47,9 @@ function resize_image_for_platform(img, style, tier) {
|
||||
}
|
||||
|
||||
// Resize to fit within target_size x target_size (square)
|
||||
var scale = target_size / Math.max(src_w, src_h)
|
||||
var dst_w = Math.floor(src_w * scale)
|
||||
var dst_h = Math.floor(src_h * scale)
|
||||
var scale = target_size / number.max(src_w, src_h)
|
||||
var dst_w = number.floor(src_w * scale)
|
||||
var dst_h = number.floor(src_h * scale)
|
||||
if (dst_w < 1) dst_w = 1
|
||||
if (dst_h < 1) dst_h = 1
|
||||
|
||||
@@ -252,7 +252,7 @@ function load_model(path, style, tier) {
|
||||
if (mesh.mesh_index != node.mesh_index) continue
|
||||
|
||||
var mat_idx = mesh.material_index
|
||||
var mat = (mat_idx != null && materials[mat_idx]) ? materials[mat_idx] : Object.create(_default_material)
|
||||
var mat = (mat_idx != null && materials[mat_idx]) ? materials[mat_idx] : meme(_default_material)
|
||||
|
||||
result.push({
|
||||
mesh: mesh,
|
||||
|
||||
Reference in New Issue
Block a user