Tweak physics, cannons, nsbtp support, prepare to add items.
This commit is contained in:
1 parent
e1dc8603d1
commit
e010627b5d
19 files changed
+982
-353
No files matched your search
@@ -20,35 +20,48 @@ window.cameraIngame = function(kart) {
|
||||
var lookAtOffset = [0, 16, 0]
|
||||
|
||||
var camNormal = [0, 1, 0];
|
||||
var forwardNormal = null;
|
||||
var camAngle = 0;
|
||||
var boostOff = 0;
|
||||
|
||||
function tweenVec3(from, to) {
|
||||
from[0] += (to[0]-from[0])*0.075;
|
||||
from[1] += (to[1]-from[1])*0.075;
|
||||
from[2] += (to[2]-from[2])*0.075;
|
||||
}
|
||||
|
||||
function getView(scene) {
|
||||
var loop = kart.physBasis != null && kart.physBasis.loop;
|
||||
var basis = buildBasis();
|
||||
tweenVec3(camOffset, loop ? [0, 12, -57] : [0, 32, -48]);
|
||||
var camPos = vec3.transformMat4([], camOffset, basis);
|
||||
var lookAtPos = vec3.transformMat4([], lookAtOffset, basis);
|
||||
|
||||
vec3.scale(camPos, camPos, 1/1024);
|
||||
vec3.scale(lookAtPos, lookAtPos, 1/1024);
|
||||
|
||||
var mat = mat4.lookAt(mat4.create(), camPos, lookAtPos, [0, 1, 0]);
|
||||
var mat = mat4.lookAt(mat4.create(), camPos, lookAtPos, (kart.physBasis) ? camNormal : [0, 1, 0]);
|
||||
var kpos = vec3.clone(kart.pos);
|
||||
if (kart.drifting && !kart.driftLanded && kart.ylock>0) kpos[1] -= kart.ylock;
|
||||
mat4.translate(mat, mat, vec3.scale([], kpos, -1/1024));
|
||||
|
||||
//interpolate visual normal roughly to target
|
||||
camNormal[0] += (kart.kartNormal[0]-camNormal[0])*0.075;
|
||||
camNormal[1] += (kart.kartNormal[1]-camNormal[1])*0.075;
|
||||
camNormal[2] += (kart.kartNormal[2]-camNormal[2])*0.075;
|
||||
tweenVec3(camNormal, kart.kartNormal);
|
||||
vec3.normalize(camNormal, camNormal);
|
||||
|
||||
if (kart.physBasis != null) {
|
||||
if (loop) {
|
||||
var kartA = kart.physicalDir+kart.driftOff/2;
|
||||
var forward = [Math.sin(kartA), 0, -Math.cos(kartA)];
|
||||
vec3.transformMat4(forward, forward, kart.physBasis.mat);
|
||||
camAngle += dirDiff(Math.atan2(forward[0], -forward[2]), camAngle)*0.075;
|
||||
if (forwardNormal == null) {
|
||||
forwardNormal = [Math.sin(camAngle), 0, -Math.cos(camAngle)];
|
||||
} else {
|
||||
tweenVec3(forwardNormal, forward);
|
||||
}
|
||||
} else {
|
||||
camAngle += dirDiff(kart.physicalDir+kart.driftOff/2, camAngle)*0.075;
|
||||
forwardNormal = null;
|
||||
}
|
||||
camAngle = fixDir(camAngle);
|
||||
|
||||
@@ -67,8 +80,8 @@ window.cameraIngame = function(kart) {
|
||||
function buildBasis() {
|
||||
//order y, x, z
|
||||
var kart = thisObj.kart;
|
||||
var forward = [Math.sin(camAngle), 0, -Math.cos(camAngle)];
|
||||
var side = [Math.cos(camAngle), 0, Math.sin(camAngle)];
|
||||
var forward = (forwardNormal != null) ? forwardNormal : [Math.sin(camAngle), 0, -Math.cos(camAngle)];
|
||||
var side = vec3.cross([], forward, camNormal);
|
||||
/*
|
||||
if (kart.physBasis != null) {
|
||||
vec3.transformMat4(forward, forward, kart.physBasis.mat);
|
||||
|
||||
+108
-107
@@ -1,108 +1,109 @@
|
||||
//
|
||||
// ingameRes.js
|
||||
//--------------------
|
||||
// Provides access to general ingame resources.
|
||||
// by RHY3756547
|
||||
//
|
||||
|
||||
window.IngameRes = function(rom) {
|
||||
var r = this;
|
||||
this.kartPhys = new kartphysicalparam(rom.getFile("/data/KartModelMenu/kartphysicalparam.bin"));
|
||||
this.kartOff = new kartoffsetdata(rom.getFile("/data/KartModelMenu/kartoffsetdata.bin"));
|
||||
this.MapObj = new narc(lz77.decompress(rom.getFile("/data/Main/MapObj.carc"))); //contains generic map obj, look in here when mapobj res is missing from course. (itembox etc)
|
||||
this.MainRace = new narc(lz77.decompress(rom.getFile("/data/MainRace.carc"))); //contains item models.
|
||||
this.MainEffect = new narc(lz77.decompress(rom.getFile("/data/MainEffect.carc"))); //contains particles.
|
||||
this.Main2D = new narc(lz77.decompress(rom.getFile("/data/Main2D.carc")));
|
||||
|
||||
this.KartModelSub = new narc(lz77.decompress(rom.getFile("/data/KartModelSub.carc"))); //contains characters + animations
|
||||
|
||||
this.Race = new narc(lz77.decompress(rom.getFile("/data/Scene/Race.carc"))); //contains lakitu, count, various graphics
|
||||
this.RaceLoc = new narc(lz77.decompress(rom.getFile("/data/Scene/Race_us.carc"))); //contains lakitu lap signs, START, YOU WIN etc. some of these will be replaced by hi res graphics by default.
|
||||
this.RaceEffect = new spa(r.MainEffect.getFile("RaceEffect.spa"));
|
||||
|
||||
this.MainFont = new nftr(r.Main2D.getFile("marioFont.NFTR"));
|
||||
//debugger;
|
||||
|
||||
this.getChar = getChar;
|
||||
this.getKart = getKart;
|
||||
|
||||
var itemNames = [
|
||||
"banana", "bomb", "gesso" /*squid*/, "kinoko" /*mushroom*/, "kinoko_p" /*queen shroom*/, "koura_g" /*green shell*/, "koura_r" /*red shell*/, "star", "teresa" /*boo*/, "thunder",
|
||||
"koura_w" /*blue shell item rep*/, "f_box", "killer" /*bullet bill*/
|
||||
]
|
||||
|
||||
//order
|
||||
//donkey, toad, bowser?, luigi, mario, peach, wario, yoshi, daisy, waluigi, dry bones (karon), robo, heyho
|
||||
var toSoundOff = [
|
||||
4, 0, 1, 2, 5, 6, 7, 3, 10, 8, 9, 11, 12
|
||||
];
|
||||
|
||||
var charNames = [
|
||||
"mario", "donkey", "kinopio", "koopa", "peach", "wario", "yoshi", "luigi", "karon", "daisy", "waluigi", "robo", "heyho"
|
||||
];
|
||||
|
||||
var charAbbrv = [
|
||||
"MR", "DK", "KO", "KP", "PC", "WR", "YS", "LG", "KA", "DS", "WL", "RB", "HH"
|
||||
];
|
||||
|
||||
var tireName = ["kart_tire_L", "kart_tire_M", "kart_tire_S"];
|
||||
|
||||
var characters = [];
|
||||
var karts = [];
|
||||
|
||||
loadItems();
|
||||
loadTires();
|
||||
|
||||
function loadItems() { //loads physical representations of items
|
||||
var t = {}
|
||||
for (var i=0; i<itemNames.length; i++) {
|
||||
var n = itemNames[i];
|
||||
t[n] = new nitroModel(new nsbmd(r.MainRace.getFile("/Item/it_"+n+".nsbmd")));
|
||||
}
|
||||
t.blueShell = new nitroModel(new nsbmd(r.MainRace.getFile("/Item/koura_w.nsbmd")));
|
||||
t.splat = new nitroModel(new nsbmd(r.MainRace.getFile("/Item/geso_sumi.nsbmd")));
|
||||
r.items = t;
|
||||
}
|
||||
|
||||
function loadTires() {
|
||||
var path = "/data/KartModelMenu/kart/tire/";
|
||||
var tires = {};
|
||||
for (var i=0; i<tireName.length; i++) tires[tireName[i]] = new nitroModel(new nsbmd(rom.getFile(path+tireName[i]+".nsbmd")), new nsbtx(rom.getFile(path+tireName[i]+".nsbtx")));
|
||||
r.tireRes = tires;
|
||||
}
|
||||
|
||||
function getChar(ind) {
|
||||
if (characters[ind] != null) return characters[ind];
|
||||
var base = "/character/"+charNames[ind]+"/P_"+charAbbrv[ind];
|
||||
|
||||
var obj = {
|
||||
model: new nitroModel(new nsbmd(r.KartModelSub.getFile(base+".nsbmd")), new nsbtx(r.KartModelSub.getFile(base+".nsbtx")), {tex:{1:2}, pal:{1:2}}),
|
||||
driveA: new nsbca(r.KartModelSub.getFile(base+"_drive.nsbca")),
|
||||
loseA: new nsbca(r.KartModelSub.getFile(base+"_lose.nsbca")),
|
||||
spinA: new nsbca(r.KartModelSub.getFile(base+"_spin.nsbca")),
|
||||
winA: new nsbca(r.KartModelSub.getFile(base+"_win.nsbca")),
|
||||
sndOff: toSoundOff[ind]*14,
|
||||
}
|
||||
characters[ind] = obj;
|
||||
return characters[ind];
|
||||
}
|
||||
|
||||
var letters = ["a", "b", "c"]
|
||||
|
||||
function getKart(ind) { //returns a nitroModel, but also includes a property "shadVol" containing the kart's shadow volume.
|
||||
if (karts[ind] != null) return karts[ind];
|
||||
var c = Math.floor(ind/3);
|
||||
var t = ind%3;
|
||||
if (t == 0) c = 0; //only mario has standard kart
|
||||
|
||||
var name = charAbbrv[c]+"_"+letters[t];
|
||||
var path = "/data/KartModelMenu/kart/"+charNames[c]+"/kart_"+name;
|
||||
|
||||
var model = new nitroModel(new nsbmd(rom.getFile(path+".nsbmd")), new nsbtx(rom.getFile(path+".nsbtx")));
|
||||
model.shadVol = new nitroModel(new nsbmd(rom.getFile("/data/KartModelMenu/kart/shadow/sh_"+name+".nsbmd")));
|
||||
//todo, assign special pallete for A karts
|
||||
|
||||
karts[ind] = model;
|
||||
return karts[ind];
|
||||
}
|
||||
//
|
||||
// ingameRes.js
|
||||
//--------------------
|
||||
// Provides access to general ingame resources.
|
||||
// by RHY3756547
|
||||
//
|
||||
|
||||
window.IngameRes = function(rom) {
|
||||
var r = this;
|
||||
this.kartPhys = new kartphysicalparam(rom.getFile("/data/KartModelMenu/kartphysicalparam.bin"));
|
||||
this.kartOff = new kartoffsetdata(rom.getFile("/data/KartModelMenu/kartoffsetdata.bin"));
|
||||
this.MapObj = new narc(lz77.decompress(rom.getFile("/data/Main/MapObj.carc"))); //contains generic map obj, look in here when mapobj res is missing from course. (itembox etc)
|
||||
this.MainRace = new narc(lz77.decompress(rom.getFile("/data/MainRace.carc"))); //contains item models.
|
||||
this.MainEffect = new narc(lz77.decompress(rom.getFile("/data/MainEffect.carc"))); //contains particles.
|
||||
this.Main2D = new narc(lz77.decompress(rom.getFile("/data/Main2D.carc")));
|
||||
|
||||
this.KartModelSub = new narc(lz77.decompress(rom.getFile("/data/KartModelSub.carc"))); //contains characters + animations
|
||||
|
||||
this.Race = new narc(lz77.decompress(rom.getFile("/data/Scene/Race.carc"))); //contains lakitu, count, various graphics
|
||||
this.RaceLoc = new narc(lz77.decompress(rom.getFile("/data/Scene/Race_us.carc"))); //contains lakitu lap signs, START, YOU WIN etc. some of these will be replaced by hi res graphics by default.
|
||||
this.RaceEffect = new spa(r.MainEffect.getFile("RaceEffect.spa"));
|
||||
|
||||
this.MainFont = new nftr(r.Main2D.getFile("marioFont.NFTR"));
|
||||
//debugger;
|
||||
|
||||
this.getChar = getChar;
|
||||
this.getKart = getKart;
|
||||
|
||||
var itemNames = [
|
||||
"banana", "bomb", "gesso" /*squid*/, "kinoko" /*mushroom*/, "kinoko_p" /*queen shroom*/, "koura_g" /*green shell*/, "koura_r" /*red shell*/, "star", "teresa" /*boo*/, "thunder",
|
||||
"koura_w" /*blue shell item rep*/, "f_box", "killer" /*bullet bill*/
|
||||
]
|
||||
|
||||
//order
|
||||
//donkey, toad, bowser?, luigi, mario, peach, wario, yoshi, daisy, waluigi, dry bones (karon), robo, heyho
|
||||
var toSoundOff = [
|
||||
4, 0, 1, 2, 5, 6, 7, 3, 10, 8, 9, 11, 12
|
||||
];
|
||||
|
||||
var charNames = [
|
||||
"mario", "donkey", "kinopio", "koopa", "peach", "wario", "yoshi", "luigi", "karon", "daisy", "waluigi", "robo", "heyho"
|
||||
];
|
||||
|
||||
var charAbbrv = [
|
||||
"MR", "DK", "KO", "KP", "PC", "WR", "YS", "LG", "KA", "DS", "WL", "RB", "HH"
|
||||
];
|
||||
|
||||
var tireName = ["kart_tire_L", "kart_tire_M", "kart_tire_S"];
|
||||
|
||||
var characters = [];
|
||||
var karts = [];
|
||||
|
||||
loadItems();
|
||||
loadTires();
|
||||
|
||||
function loadItems() { //loads physical representations of items
|
||||
var t = {}
|
||||
for (var i=0; i<itemNames.length; i++) {
|
||||
var n = itemNames[i];
|
||||
t[n] = new nitroModel(new nsbmd(r.MainRace.getFile("/Item/it_"+n+".nsbmd")));
|
||||
}
|
||||
t.blueShell = new nitroModel(new nsbmd(r.MainRace.getFile("/Item/koura_w.nsbmd")));
|
||||
t.splat = new nitroModel(new nsbmd(r.MainRace.getFile("/Item/geso_sumi.nsbmd")));
|
||||
t.fakeBox = new nitroModel(new nsbmd(r.MainRace.getFile("/MapObj/box.nsbmd")));
|
||||
r.items = t;
|
||||
}
|
||||
|
||||
function loadTires() {
|
||||
var path = "/data/KartModelMenu/kart/tire/";
|
||||
var tires = {};
|
||||
for (var i=0; i<tireName.length; i++) tires[tireName[i]] = new nitroModel(new nsbmd(rom.getFile(path+tireName[i]+".nsbmd")), new nsbtx(rom.getFile(path+tireName[i]+".nsbtx")));
|
||||
r.tireRes = tires;
|
||||
}
|
||||
|
||||
function getChar(ind) {
|
||||
if (characters[ind] != null) return characters[ind];
|
||||
var base = "/character/"+charNames[ind]+"/P_"+charAbbrv[ind];
|
||||
|
||||
var obj = {
|
||||
model: new nitroModel(new nsbmd(r.KartModelSub.getFile(base+".nsbmd")), new nsbtx(r.KartModelSub.getFile(base+".nsbtx")), {tex:{1:2}, pal:{1:2}}),
|
||||
driveA: new nsbca(r.KartModelSub.getFile(base+"_drive.nsbca")),
|
||||
loseA: new nsbca(r.KartModelSub.getFile(base+"_lose.nsbca")),
|
||||
spinA: new nsbca(r.KartModelSub.getFile(base+"_spin.nsbca")),
|
||||
winA: new nsbca(r.KartModelSub.getFile(base+"_win.nsbca")),
|
||||
sndOff: toSoundOff[ind]*14,
|
||||
}
|
||||
characters[ind] = obj;
|
||||
return characters[ind];
|
||||
}
|
||||
|
||||
var letters = ["a", "b", "c"]
|
||||
|
||||
function getKart(ind) { //returns a nitroModel, but also includes a property "shadVol" containing the kart's shadow volume.
|
||||
if (karts[ind] != null) return karts[ind];
|
||||
var c = Math.floor(ind/3);
|
||||
var t = ind%3;
|
||||
if (t == 0) c = 0; //only mario has standard kart
|
||||
|
||||
var name = charAbbrv[c]+"_"+letters[t];
|
||||
var path = "/data/KartModelMenu/kart/"+charNames[c]+"/kart_"+name;
|
||||
|
||||
var model = new nitroModel(new nsbmd(rom.getFile(path+".nsbmd")), new nsbtx(rom.getFile(path+".nsbtx")));
|
||||
model.shadVol = new nitroModel(new nsbmd(rom.getFile("/data/KartModelMenu/kart/shadow/sh_"+name+".nsbmd")));
|
||||
//todo, assign special pallete for A karts
|
||||
|
||||
karts[ind] = model;
|
||||
return karts[ind];
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,10 @@
|
||||
|
||||
window.MKDSCONST = new (function() {
|
||||
|
||||
this.DAMAGE_SPIN = 0;
|
||||
this.DAMAGE_FLIP = 0;
|
||||
this.DAMAGE_EXPLODE = 0;
|
||||
|
||||
this.COURSEDIR = "/data/Course/";
|
||||
|
||||
this.COURSES = [ //in order of course id, nitro through retro
|
||||
|
||||
@@ -56,12 +56,17 @@ window.courseScene = function(mainNarc, texNarc, music, chars, options, gameRes)
|
||||
|
||||
//load main course
|
||||
var courseTx = new nsbtx(texNarc.getFile("/course_model.nsbtx"), false, true);
|
||||
|
||||
var taFile = mainNarc.getFile("/course_model.nsbta");
|
||||
if (taFile != null) var courseTa = new nsbta(taFile); //can be null
|
||||
var tpFile = mainNarc.getFile("/course_model.nsbtp");
|
||||
if (tpFile != null) var courseTp = new nsbtp(tpFile); //can be null
|
||||
|
||||
var courseMdl = new nsbmd(mainNarc.getFile("/course_model.nsbmd"));
|
||||
|
||||
var course = new nitroModel(courseMdl, courseTx)
|
||||
if (taFile != null) course.loadTexAnim(courseTa);
|
||||
if (tpFile != null) course.loadTexPAnim(courseTp);
|
||||
|
||||
//load sky
|
||||
var skyTx = new nsbtx(texNarc.getFile("/course_model_V.nsbtx"), false, true);
|
||||
@@ -229,12 +234,25 @@ window.courseScene = function(mainNarc, texNarc, music, chars, options, gameRes)
|
||||
scn.paths = paths;
|
||||
}
|
||||
|
||||
function getLightCenter() {
|
||||
var average = vec3.create();
|
||||
var objs = scn.nkm.sections["OBJI"].entries;
|
||||
for (var i=0; i<objs.length; i++) {
|
||||
vec3.add(average, average, objs[i].pos);
|
||||
}
|
||||
vec3.scale(average, average, (1/objs.length) /-1024);
|
||||
return average;
|
||||
}
|
||||
|
||||
function startCourse() {
|
||||
scn.lightMat = mat4.create();
|
||||
|
||||
mat4.rotateX(scn.lightMat, scn.lightMat, Math.PI*(61/180));
|
||||
mat4.rotateY(scn.lightMat, scn.lightMat, Math.PI*(21/180));
|
||||
scn.farShadMat = mat4.create();
|
||||
mat4.translate(scn.farShadMat, scn.lightMat, getLightCenter());
|
||||
|
||||
mat4.mul(scn.farShadMat, mat4.ortho(mat4.create(), -5, 5, -5, 5, -5, 5), scn.lightMat);
|
||||
mat4.mul(scn.farShadMat, mat4.ortho(mat4.create(), -5, 5, -5, 5, -5, 5), scn.farShadMat);
|
||||
|
||||
compilePaths();
|
||||
|
||||
|
||||
Reference in new issue
Block a user