Change folder structure
This commit is contained in:
parent
8657f7bfc2
commit
205e4f63ce
272
atan.c
272
atan.c
@ -1,272 +0,0 @@
|
|||||||
// Arctan base table
|
|
||||||
static int AtanBaseTable[8] = {
|
|
||||||
0x0000,
|
|
||||||
-0x4000,
|
|
||||||
-0xFFFF,
|
|
||||||
0xC000,
|
|
||||||
-0x8000,
|
|
||||||
0x4000,
|
|
||||||
0x8000,
|
|
||||||
-0xC000,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Arctan angle table
|
|
||||||
static short AtanAngleTable[0x802] = {
|
|
||||||
0x0000, 0x0005, 0x000A, 0x000F, 0x0014, 0x0019, 0x001F, 0x0024,
|
|
||||||
0x0029, 0x002E, 0x0033, 0x0038, 0x003D, 0x0042, 0x0047, 0x004C,
|
|
||||||
0x0051, 0x0057, 0x005C, 0x0061, 0x0066, 0x006B, 0x0070, 0x0075,
|
|
||||||
0x007A, 0x007F, 0x0084, 0x008A, 0x008F, 0x0094, 0x0099, 0x009E,
|
|
||||||
0x00A3, 0x00A8, 0x00AD, 0x00B2, 0x00B7, 0x00BC, 0x00C2, 0x00C7,
|
|
||||||
0x00CC, 0x00D1, 0x00D6, 0x00DB, 0x00E0, 0x00E5, 0x00EA, 0x00EF,
|
|
||||||
0x00F4, 0x00FA, 0x00FF, 0x0104, 0x0109, 0x010E, 0x0113, 0x0118,
|
|
||||||
0x011D, 0x0122, 0x0127, 0x012C, 0x0131, 0x0137, 0x013C, 0x0141,
|
|
||||||
0x0146, 0x014B, 0x0150, 0x0155, 0x015A, 0x015F, 0x0164, 0x0169,
|
|
||||||
0x016F, 0x0174, 0x0179, 0x017E, 0x0183, 0x0188, 0x018D, 0x0192,
|
|
||||||
0x0197, 0x019C, 0x01A1, 0x01A6, 0x01AC, 0x01B1, 0x01B6, 0x01BB,
|
|
||||||
0x01C0, 0x01C5, 0x01CA, 0x01CF, 0x01D4, 0x01D9, 0x01DE, 0x01E3,
|
|
||||||
0x01E9, 0x01EE, 0x01F3, 0x01F8, 0x01FD, 0x0202, 0x0207, 0x020C,
|
|
||||||
0x0211, 0x0216, 0x021B, 0x0220, 0x0226, 0x022B, 0x0230, 0x0235,
|
|
||||||
0x023A, 0x023F, 0x0244, 0x0249, 0x024E, 0x0253, 0x0258, 0x025D,
|
|
||||||
0x0262, 0x0268, 0x026D, 0x0272, 0x0277, 0x027C, 0x0281, 0x0286,
|
|
||||||
0x028B, 0x0290, 0x0295, 0x029A, 0x029F, 0x02A4, 0x02A9, 0x02AF,
|
|
||||||
0x02B4, 0x02B9, 0x02BE, 0x02C3, 0x02C8, 0x02CD, 0x02D2, 0x02D7,
|
|
||||||
0x02DC, 0x02E1, 0x02E6, 0x02EB, 0x02F0, 0x02F6, 0x02FB, 0x0300,
|
|
||||||
0x0305, 0x030A, 0x030F, 0x0314, 0x0319, 0x031E, 0x0323, 0x0328,
|
|
||||||
0x032D, 0x0332, 0x0337, 0x033C, 0x0341, 0x0347, 0x034C, 0x0351,
|
|
||||||
0x0356, 0x035B, 0x0360, 0x0365, 0x036A, 0x036F, 0x0374, 0x0379,
|
|
||||||
0x037E, 0x0383, 0x0388, 0x038D, 0x0392, 0x0397, 0x039C, 0x03A2,
|
|
||||||
0x03A7, 0x03AC, 0x03B1, 0x03B6, 0x03BB, 0x03C0, 0x03C5, 0x03CA,
|
|
||||||
0x03CF, 0x03D4, 0x03D9, 0x03DE, 0x03E3, 0x03E8, 0x03ED, 0x03F2,
|
|
||||||
0x03F7, 0x03FC, 0x0401, 0x0407, 0x040C, 0x0411, 0x0416, 0x041B,
|
|
||||||
0x0420, 0x0425, 0x042A, 0x042F, 0x0434, 0x0439, 0x043E, 0x0443,
|
|
||||||
0x0448, 0x044D, 0x0452, 0x0457, 0x045C, 0x0461, 0x0466, 0x046B,
|
|
||||||
0x0470, 0x0475, 0x047A, 0x047F, 0x0484, 0x0489, 0x048E, 0x0494,
|
|
||||||
0x0499, 0x049E, 0x04A3, 0x04A8, 0x04AD, 0x04B2, 0x04B7, 0x04BC,
|
|
||||||
0x04C1, 0x04C6, 0x04CB, 0x04D0, 0x04D5, 0x04DA, 0x04DF, 0x04E4,
|
|
||||||
0x04E9, 0x04EE, 0x04F3, 0x04F8, 0x04FD, 0x0502, 0x0507, 0x050C,
|
|
||||||
0x0511, 0x0516, 0x051B, 0x0520, 0x0525, 0x052A, 0x052F, 0x0534,
|
|
||||||
0x0539, 0x053E, 0x0543, 0x0548, 0x054D, 0x0552, 0x0557, 0x055C,
|
|
||||||
0x0561, 0x0566, 0x056B, 0x0570, 0x0575, 0x057A, 0x057F, 0x0584,
|
|
||||||
0x0589, 0x058E, 0x0593, 0x0598, 0x059D, 0x05A2, 0x05A7, 0x05AC,
|
|
||||||
0x05B1, 0x05B6, 0x05BB, 0x05C0, 0x05C5, 0x05CA, 0x05CF, 0x05D4,
|
|
||||||
0x05D9, 0x05DE, 0x05E3, 0x05E8, 0x05ED, 0x05F2, 0x05F7, 0x05FC,
|
|
||||||
0x0601, 0x0606, 0x060B, 0x0610, 0x0615, 0x061A, 0x061F, 0x0624,
|
|
||||||
0x0629, 0x062E, 0x0633, 0x0638, 0x063D, 0x0642, 0x0647, 0x064C,
|
|
||||||
0x0651, 0x0656, 0x065B, 0x0660, 0x0665, 0x066A, 0x066E, 0x0673,
|
|
||||||
0x0678, 0x067D, 0x0682, 0x0687, 0x068C, 0x0691, 0x0696, 0x069B,
|
|
||||||
0x06A0, 0x06A5, 0x06AA, 0x06AF, 0x06B4, 0x06B9, 0x06BE, 0x06C3,
|
|
||||||
0x06C8, 0x06CD, 0x06D2, 0x06D7, 0x06DC, 0x06E1, 0x06E5, 0x06EA,
|
|
||||||
0x06EF, 0x06F4, 0x06F9, 0x06FE, 0x0703, 0x0708, 0x070D, 0x0712,
|
|
||||||
0x0717, 0x071C, 0x0721, 0x0726, 0x072B, 0x0730, 0x0735, 0x0739,
|
|
||||||
0x073E, 0x0743, 0x0748, 0x074D, 0x0752, 0x0757, 0x075C, 0x0761,
|
|
||||||
0x0766, 0x076B, 0x0770, 0x0775, 0x077A, 0x077E, 0x0783, 0x0788,
|
|
||||||
0x078D, 0x0792, 0x0797, 0x079C, 0x07A1, 0x07A6, 0x07AB, 0x07B0,
|
|
||||||
0x07B5, 0x07B9, 0x07BE, 0x07C3, 0x07C8, 0x07CD, 0x07D2, 0x07D7,
|
|
||||||
0x07DC, 0x07E1, 0x07E6, 0x07EB, 0x07EF, 0x07F4, 0x07F9, 0x07FE,
|
|
||||||
0x0803, 0x0808, 0x080D, 0x0812, 0x0817, 0x081C, 0x0820, 0x0825,
|
|
||||||
0x082A, 0x082F, 0x0834, 0x0839, 0x083E, 0x0843, 0x0848, 0x084C,
|
|
||||||
0x0851, 0x0856, 0x085B, 0x0860, 0x0865, 0x086A, 0x086F, 0x0873,
|
|
||||||
0x0878, 0x087D, 0x0882, 0x0887, 0x088C, 0x0891, 0x0896, 0x089A,
|
|
||||||
0x089F, 0x08A4, 0x08A9, 0x08AE, 0x08B3, 0x08B8, 0x08BD, 0x08C1,
|
|
||||||
0x08C6, 0x08CB, 0x08D0, 0x08D5, 0x08DA, 0x08DF, 0x08E3, 0x08E8,
|
|
||||||
0x08ED, 0x08F2, 0x08F7, 0x08FC, 0x0901, 0x0905, 0x090A, 0x090F,
|
|
||||||
0x0914, 0x0919, 0x091E, 0x0922, 0x0927, 0x092C, 0x0931, 0x0936,
|
|
||||||
0x093B, 0x093F, 0x0944, 0x0949, 0x094E, 0x0953, 0x0958, 0x095C,
|
|
||||||
0x0961, 0x0966, 0x096B, 0x0970, 0x0975, 0x0979, 0x097E, 0x0983,
|
|
||||||
0x0988, 0x098D, 0x0992, 0x0996, 0x099B, 0x09A0, 0x09A5, 0x09AA,
|
|
||||||
0x09AE, 0x09B3, 0x09B8, 0x09BD, 0x09C2, 0x09C6, 0x09CB, 0x09D0,
|
|
||||||
0x09D5, 0x09DA, 0x09DE, 0x09E3, 0x09E8, 0x09ED, 0x09F2, 0x09F6,
|
|
||||||
0x09FB, 0x0A00, 0x0A05, 0x0A0A, 0x0A0E, 0x0A13, 0x0A18, 0x0A1D,
|
|
||||||
0x0A22, 0x0A26, 0x0A2B, 0x0A30, 0x0A35, 0x0A39, 0x0A3E, 0x0A43,
|
|
||||||
0x0A48, 0x0A4D, 0x0A51, 0x0A56, 0x0A5B, 0x0A60, 0x0A64, 0x0A69,
|
|
||||||
0x0A6E, 0x0A73, 0x0A77, 0x0A7C, 0x0A81, 0x0A86, 0x0A8B, 0x0A8F,
|
|
||||||
0x0A94, 0x0A99, 0x0A9E, 0x0AA2, 0x0AA7, 0x0AAC, 0x0AB1, 0x0AB5,
|
|
||||||
0x0ABA, 0x0ABF, 0x0AC4, 0x0AC8, 0x0ACD, 0x0AD2, 0x0AD7, 0x0ADB,
|
|
||||||
0x0AE0, 0x0AE5, 0x0AE9, 0x0AEE, 0x0AF3, 0x0AF8, 0x0AFC, 0x0B01,
|
|
||||||
0x0B06, 0x0B0B, 0x0B0F, 0x0B14, 0x0B19, 0x0B1E, 0x0B22, 0x0B27,
|
|
||||||
0x0B2C, 0x0B30, 0x0B35, 0x0B3A, 0x0B3F, 0x0B43, 0x0B48, 0x0B4D,
|
|
||||||
0x0B51, 0x0B56, 0x0B5B, 0x0B60, 0x0B64, 0x0B69, 0x0B6E, 0x0B72,
|
|
||||||
0x0B77, 0x0B7C, 0x0B80, 0x0B85, 0x0B8A, 0x0B8F, 0x0B93, 0x0B98,
|
|
||||||
0x0B9D, 0x0BA1, 0x0BA6, 0x0BAB, 0x0BAF, 0x0BB4, 0x0BB9, 0x0BBD,
|
|
||||||
0x0BC2, 0x0BC7, 0x0BCB, 0x0BD0, 0x0BD5, 0x0BD9, 0x0BDE, 0x0BE3,
|
|
||||||
0x0BE7, 0x0BEC, 0x0BF1, 0x0BF5, 0x0BFA, 0x0BFF, 0x0C03, 0x0C08,
|
|
||||||
0x0C0D, 0x0C11, 0x0C16, 0x0C1B, 0x0C1F, 0x0C24, 0x0C29, 0x0C2D,
|
|
||||||
0x0C32, 0x0C37, 0x0C3B, 0x0C40, 0x0C45, 0x0C49, 0x0C4E, 0x0C53,
|
|
||||||
0x0C57, 0x0C5C, 0x0C60, 0x0C65, 0x0C6A, 0x0C6E, 0x0C73, 0x0C78,
|
|
||||||
0x0C7C, 0x0C81, 0x0C86, 0x0C8A, 0x0C8F, 0x0C93, 0x0C98, 0x0C9D,
|
|
||||||
0x0CA1, 0x0CA6, 0x0CAB, 0x0CAF, 0x0CB4, 0x0CB8, 0x0CBD, 0x0CC2,
|
|
||||||
0x0CC6, 0x0CCB, 0x0CCF, 0x0CD4, 0x0CD9, 0x0CDD, 0x0CE2, 0x0CE6,
|
|
||||||
0x0CEB, 0x0CF0, 0x0CF4, 0x0CF9, 0x0CFD, 0x0D02, 0x0D07, 0x0D0B,
|
|
||||||
0x0D10, 0x0D14, 0x0D19, 0x0D1E, 0x0D22, 0x0D27, 0x0D2B, 0x0D30,
|
|
||||||
0x0D34, 0x0D39, 0x0D3E, 0x0D42, 0x0D47, 0x0D4B, 0x0D50, 0x0D54,
|
|
||||||
0x0D59, 0x0D5E, 0x0D62, 0x0D67, 0x0D6B, 0x0D70, 0x0D74, 0x0D79,
|
|
||||||
0x0D7D, 0x0D82, 0x0D87, 0x0D8B, 0x0D90, 0x0D94, 0x0D99, 0x0D9D,
|
|
||||||
0x0DA2, 0x0DA6, 0x0DAB, 0x0DAF, 0x0DB4, 0x0DB9, 0x0DBD, 0x0DC2,
|
|
||||||
0x0DC6, 0x0DCB, 0x0DCF, 0x0DD4, 0x0DD8, 0x0DDD, 0x0DE1, 0x0DE6,
|
|
||||||
0x0DEA, 0x0DEF, 0x0DF3, 0x0DF8, 0x0DFC, 0x0E01, 0x0E05, 0x0E0A,
|
|
||||||
0x0E0F, 0x0E13, 0x0E18, 0x0E1C, 0x0E21, 0x0E25, 0x0E2A, 0x0E2E,
|
|
||||||
0x0E33, 0x0E37, 0x0E3C, 0x0E40, 0x0E45, 0x0E49, 0x0E4E, 0x0E52,
|
|
||||||
0x0E56, 0x0E5B, 0x0E5F, 0x0E64, 0x0E68, 0x0E6D, 0x0E71, 0x0E76,
|
|
||||||
0x0E7A, 0x0E7F, 0x0E83, 0x0E88, 0x0E8C, 0x0E91, 0x0E95, 0x0E9A,
|
|
||||||
0x0E9E, 0x0EA3, 0x0EA7, 0x0EAC, 0x0EB0, 0x0EB4, 0x0EB9, 0x0EBD,
|
|
||||||
0x0EC2, 0x0EC6, 0x0ECB, 0x0ECF, 0x0ED4, 0x0ED8, 0x0EDC, 0x0EE1,
|
|
||||||
0x0EE5, 0x0EEA, 0x0EEE, 0x0EF3, 0x0EF7, 0x0EFC, 0x0F00, 0x0F04,
|
|
||||||
0x0F09, 0x0F0D, 0x0F12, 0x0F16, 0x0F1B, 0x0F1F, 0x0F23, 0x0F28,
|
|
||||||
0x0F2C, 0x0F31, 0x0F35, 0x0F3A, 0x0F3E, 0x0F42, 0x0F47, 0x0F4B,
|
|
||||||
0x0F50, 0x0F54, 0x0F58, 0x0F5D, 0x0F61, 0x0F66, 0x0F6A, 0x0F6E,
|
|
||||||
0x0F73, 0x0F77, 0x0F7C, 0x0F80, 0x0F84, 0x0F89, 0x0F8D, 0x0F91,
|
|
||||||
0x0F96, 0x0F9A, 0x0F9F, 0x0FA3, 0x0FA7, 0x0FAC, 0x0FB0, 0x0FB5,
|
|
||||||
0x0FB9, 0x0FBD, 0x0FC2, 0x0FC6, 0x0FCA, 0x0FCF, 0x0FD3, 0x0FD7,
|
|
||||||
0x0FDC, 0x0FE0, 0x0FE5, 0x0FE9, 0x0FED, 0x0FF2, 0x0FF6, 0x0FFA,
|
|
||||||
0x0FFF, 0x1003, 0x1007, 0x100C, 0x1010, 0x1014, 0x1019, 0x101D,
|
|
||||||
0x1021, 0x1026, 0x102A, 0x102E, 0x1033, 0x1037, 0x103B, 0x1040,
|
|
||||||
0x1044, 0x1048, 0x104D, 0x1051, 0x1055, 0x105A, 0x105E, 0x1062,
|
|
||||||
0x1067, 0x106B, 0x106F, 0x1073, 0x1078, 0x107C, 0x1080, 0x1085,
|
|
||||||
0x1089, 0x108D, 0x1092, 0x1096, 0x109A, 0x109E, 0x10A3, 0x10A7,
|
|
||||||
0x10AB, 0x10B0, 0x10B4, 0x10B8, 0x10BC, 0x10C1, 0x10C5, 0x10C9,
|
|
||||||
0x10CE, 0x10D2, 0x10D6, 0x10DA, 0x10DF, 0x10E3, 0x10E7, 0x10EB,
|
|
||||||
0x10F0, 0x10F4, 0x10F8, 0x10FD, 0x1101, 0x1105, 0x1109, 0x110E,
|
|
||||||
0x1112, 0x1116, 0x111A, 0x111F, 0x1123, 0x1127, 0x112B, 0x1130,
|
|
||||||
0x1134, 0x1138, 0x113C, 0x1140, 0x1145, 0x1149, 0x114D, 0x1151,
|
|
||||||
0x1156, 0x115A, 0x115E, 0x1162, 0x1166, 0x116B, 0x116F, 0x1173,
|
|
||||||
0x1177, 0x117C, 0x1180, 0x1184, 0x1188, 0x118C, 0x1191, 0x1195,
|
|
||||||
0x1199, 0x119D, 0x11A1, 0x11A6, 0x11AA, 0x11AE, 0x11B2, 0x11B6,
|
|
||||||
0x11BB, 0x11BF, 0x11C3, 0x11C7, 0x11CB, 0x11CF, 0x11D4, 0x11D8,
|
|
||||||
0x11DC, 0x11E0, 0x11E4, 0x11E9, 0x11ED, 0x11F1, 0x11F5, 0x11F9,
|
|
||||||
0x11FD, 0x1202, 0x1206, 0x120A, 0x120E, 0x1212, 0x1216, 0x121A,
|
|
||||||
0x121F, 0x1223, 0x1227, 0x122B, 0x122F, 0x1233, 0x1237, 0x123C,
|
|
||||||
0x1240, 0x1244, 0x1248, 0x124C, 0x1250, 0x1254, 0x1259, 0x125D,
|
|
||||||
0x1261, 0x1265, 0x1269, 0x126D, 0x1271, 0x1275, 0x127A, 0x127E,
|
|
||||||
0x1282, 0x1286, 0x128A, 0x128E, 0x1292, 0x1296, 0x129A, 0x129F,
|
|
||||||
0x12A3, 0x12A7, 0x12AB, 0x12AF, 0x12B3, 0x12B7, 0x12BB, 0x12BF,
|
|
||||||
0x12C3, 0x12C7, 0x12CC, 0x12D0, 0x12D4, 0x12D8, 0x12DC, 0x12E0,
|
|
||||||
0x12E4, 0x12E8, 0x12EC, 0x12F0, 0x12F4, 0x12F8, 0x12FC, 0x1301,
|
|
||||||
0x1305, 0x1309, 0x130D, 0x1311, 0x1315, 0x1319, 0x131D, 0x1321,
|
|
||||||
0x1325, 0x1329, 0x132D, 0x1331, 0x1335, 0x1339, 0x133D, 0x1341,
|
|
||||||
0x1345, 0x1349, 0x134D, 0x1351, 0x1355, 0x135A, 0x135E, 0x1362,
|
|
||||||
0x1366, 0x136A, 0x136E, 0x1372, 0x1376, 0x137A, 0x137E, 0x1382,
|
|
||||||
0x1386, 0x138A, 0x138E, 0x1392, 0x1396, 0x139A, 0x139E, 0x13A2,
|
|
||||||
0x13A6, 0x13AA, 0x13AE, 0x13B2, 0x13B6, 0x13BA, 0x13BE, 0x13C2,
|
|
||||||
0x13C6, 0x13CA, 0x13CE, 0x13D2, 0x13D6, 0x13DA, 0x13DE, 0x13E2,
|
|
||||||
0x13E6, 0x13E9, 0x13ED, 0x13F1, 0x13F5, 0x13F9, 0x13FD, 0x1401,
|
|
||||||
0x1405, 0x1409, 0x140D, 0x1411, 0x1415, 0x1419, 0x141D, 0x1421,
|
|
||||||
0x1425, 0x1429, 0x142D, 0x1431, 0x1435, 0x1439, 0x143D, 0x1440,
|
|
||||||
0x1444, 0x1448, 0x144C, 0x1450, 0x1454, 0x1458, 0x145C, 0x1460,
|
|
||||||
0x1464, 0x1468, 0x146C, 0x1470, 0x1473, 0x1477, 0x147B, 0x147F,
|
|
||||||
0x1483, 0x1487, 0x148B, 0x148F, 0x1493, 0x1497, 0x149B, 0x149E,
|
|
||||||
0x14A2, 0x14A6, 0x14AA, 0x14AE, 0x14B2, 0x14B6, 0x14BA, 0x14BE,
|
|
||||||
0x14C1, 0x14C5, 0x14C9, 0x14CD, 0x14D1, 0x14D5, 0x14D9, 0x14DD,
|
|
||||||
0x14E0, 0x14E4, 0x14E8, 0x14EC, 0x14F0, 0x14F4, 0x14F8, 0x14FB,
|
|
||||||
0x14FF, 0x1503, 0x1507, 0x150B, 0x150F, 0x1513, 0x1516, 0x151A,
|
|
||||||
0x151E, 0x1522, 0x1526, 0x152A, 0x152D, 0x1531, 0x1535, 0x1539,
|
|
||||||
0x153D, 0x1541, 0x1544, 0x1548, 0x154C, 0x1550, 0x1554, 0x1558,
|
|
||||||
0x155B, 0x155F, 0x1563, 0x1567, 0x156B, 0x156E, 0x1572, 0x1576,
|
|
||||||
0x157A, 0x157E, 0x1581, 0x1585, 0x1589, 0x158D, 0x1591, 0x1594,
|
|
||||||
0x1598, 0x159C, 0x15A0, 0x15A4, 0x15A7, 0x15AB, 0x15AF, 0x15B3,
|
|
||||||
0x15B7, 0x15BA, 0x15BE, 0x15C2, 0x15C6, 0x15C9, 0x15CD, 0x15D1,
|
|
||||||
0x15D5, 0x15D8, 0x15DC, 0x15E0, 0x15E4, 0x15E8, 0x15EB, 0x15EF,
|
|
||||||
0x15F3, 0x15F7, 0x15FA, 0x15FE, 0x1602, 0x1606, 0x1609, 0x160D,
|
|
||||||
0x1611, 0x1614, 0x1618, 0x161C, 0x1620, 0x1623, 0x1627, 0x162B,
|
|
||||||
0x162F, 0x1632, 0x1636, 0x163A, 0x163E, 0x1641, 0x1645, 0x1649,
|
|
||||||
0x164C, 0x1650, 0x1654, 0x1658, 0x165B, 0x165F, 0x1663, 0x1666,
|
|
||||||
0x166A, 0x166E, 0x1671, 0x1675, 0x1679, 0x167D, 0x1680, 0x1684,
|
|
||||||
0x1688, 0x168B, 0x168F, 0x1693, 0x1696, 0x169A, 0x169E, 0x16A1,
|
|
||||||
0x16A5, 0x16A9, 0x16AC, 0x16B0, 0x16B4, 0x16B7, 0x16BB, 0x16BF,
|
|
||||||
0x16C2, 0x16C6, 0x16CA, 0x16CD, 0x16D1, 0x16D5, 0x16D8, 0x16DC,
|
|
||||||
0x16E0, 0x16E3, 0x16E7, 0x16EB, 0x16EE, 0x16F2, 0x16F6, 0x16F9,
|
|
||||||
0x16FD, 0x1700, 0x1704, 0x1708, 0x170B, 0x170F, 0x1713, 0x1716,
|
|
||||||
0x171A, 0x171D, 0x1721, 0x1725, 0x1728, 0x172C, 0x1730, 0x1733,
|
|
||||||
0x1737, 0x173A, 0x173E, 0x1742, 0x1745, 0x1749, 0x174C, 0x1750,
|
|
||||||
0x1754, 0x1757, 0x175B, 0x175E, 0x1762, 0x1766, 0x1769, 0x176D,
|
|
||||||
0x1770, 0x1774, 0x1778, 0x177B, 0x177F, 0x1782, 0x1786, 0x1789,
|
|
||||||
0x178D, 0x1791, 0x1794, 0x1798, 0x179B, 0x179F, 0x17A2, 0x17A6,
|
|
||||||
0x17AA, 0x17AD, 0x17B1, 0x17B4, 0x17B8, 0x17BB, 0x17BF, 0x17C2,
|
|
||||||
0x17C6, 0x17C9, 0x17CD, 0x17D1, 0x17D4, 0x17D8, 0x17DB, 0x17DF,
|
|
||||||
0x17E2, 0x17E6, 0x17E9, 0x17ED, 0x17F0, 0x17F4, 0x17F7, 0x17FB,
|
|
||||||
0x17FE, 0x1802, 0x1806, 0x1809, 0x180D, 0x1810, 0x1814, 0x1817,
|
|
||||||
0x181B, 0x181E, 0x1822, 0x1825, 0x1829, 0x182C, 0x1830, 0x1833,
|
|
||||||
0x1837, 0x183A, 0x183E, 0x1841, 0x1845, 0x1848, 0x184C, 0x184F,
|
|
||||||
0x1853, 0x1856, 0x185A, 0x185D, 0x1860, 0x1864, 0x1867, 0x186B,
|
|
||||||
0x186E, 0x1872, 0x1875, 0x1879, 0x187C, 0x1880, 0x1883, 0x1887,
|
|
||||||
0x188A, 0x188E, 0x1891, 0x1894, 0x1898, 0x189B, 0x189F, 0x18A2,
|
|
||||||
0x18A6, 0x18A9, 0x18AD, 0x18B0, 0x18B3, 0x18B7, 0x18BA, 0x18BE,
|
|
||||||
0x18C1, 0x18C5, 0x18C8, 0x18CC, 0x18CF, 0x18D2, 0x18D6, 0x18D9,
|
|
||||||
0x18DD, 0x18E0, 0x18E3, 0x18E7, 0x18EA, 0x18EE, 0x18F1, 0x18F5,
|
|
||||||
0x18F8, 0x18FB, 0x18FF, 0x1902, 0x1906, 0x1909, 0x190C, 0x1910,
|
|
||||||
0x1913, 0x1917, 0x191A, 0x191D, 0x1921, 0x1924, 0x1928, 0x192B,
|
|
||||||
0x192E, 0x1932, 0x1935, 0x1938, 0x193C, 0x193F, 0x1943, 0x1946,
|
|
||||||
0x1949, 0x194D, 0x1950, 0x1953, 0x1957, 0x195A, 0x195D, 0x1961,
|
|
||||||
0x1964, 0x1968, 0x196B, 0x196E, 0x1972, 0x1975, 0x1978, 0x197C,
|
|
||||||
0x197F, 0x1982, 0x1986, 0x1989, 0x198C, 0x1990, 0x1993, 0x1996,
|
|
||||||
0x199A, 0x199D, 0x19A0, 0x19A4, 0x19A7, 0x19AA, 0x19AE, 0x19B1,
|
|
||||||
0x19B4, 0x19B8, 0x19BB, 0x19BE, 0x19C2, 0x19C5, 0x19C8, 0x19CC,
|
|
||||||
0x19CF, 0x19D2, 0x19D5, 0x19D9, 0x19DC, 0x19DF, 0x19E3, 0x19E6,
|
|
||||||
0x19E9, 0x19ED, 0x19F0, 0x19F3, 0x19F6, 0x19FA, 0x19FD, 0x1A00,
|
|
||||||
0x1A04, 0x1A07, 0x1A0A, 0x1A0D, 0x1A11, 0x1A14, 0x1A17, 0x1A1B,
|
|
||||||
0x1A1E, 0x1A21, 0x1A24, 0x1A28, 0x1A2B, 0x1A2E, 0x1A31, 0x1A35,
|
|
||||||
0x1A38, 0x1A3B, 0x1A3E, 0x1A42, 0x1A45, 0x1A48, 0x1A4B, 0x1A4F,
|
|
||||||
0x1A52, 0x1A55, 0x1A58, 0x1A5C, 0x1A5F, 0x1A62, 0x1A65, 0x1A69,
|
|
||||||
0x1A6C, 0x1A6F, 0x1A72, 0x1A76, 0x1A79, 0x1A7C, 0x1A7F, 0x1A83,
|
|
||||||
0x1A86, 0x1A89, 0x1A8C, 0x1A8F, 0x1A93, 0x1A96, 0x1A99, 0x1A9C,
|
|
||||||
0x1A9F, 0x1AA3, 0x1AA6, 0x1AA9, 0x1AAC, 0x1AB0, 0x1AB3, 0x1AB6,
|
|
||||||
0x1AB9, 0x1ABC, 0x1AC0, 0x1AC3, 0x1AC6, 0x1AC9, 0x1ACC, 0x1ACF,
|
|
||||||
0x1AD3, 0x1AD6, 0x1AD9, 0x1ADC, 0x1ADF, 0x1AE3, 0x1AE6, 0x1AE9,
|
|
||||||
0x1AEC, 0x1AEF, 0x1AF2, 0x1AF6, 0x1AF9, 0x1AFC, 0x1AFF, 0x1B02,
|
|
||||||
0x1B05, 0x1B09, 0x1B0C, 0x1B0F, 0x1B12, 0x1B15, 0x1B18, 0x1B1C,
|
|
||||||
0x1B1F, 0x1B22, 0x1B25, 0x1B28, 0x1B2B, 0x1B2E, 0x1B32, 0x1B35,
|
|
||||||
0x1B38, 0x1B3B, 0x1B3E, 0x1B41, 0x1B44, 0x1B48, 0x1B4B, 0x1B4E,
|
|
||||||
0x1B51, 0x1B54, 0x1B57, 0x1B5A, 0x1B5D, 0x1B61, 0x1B64, 0x1B67,
|
|
||||||
0x1B6A, 0x1B6D, 0x1B70, 0x1B73, 0x1B76, 0x1B79, 0x1B7D, 0x1B80,
|
|
||||||
0x1B83, 0x1B86, 0x1B89, 0x1B8C, 0x1B8F, 0x1B92, 0x1B95, 0x1B98,
|
|
||||||
0x1B9C, 0x1B9F, 0x1BA2, 0x1BA5, 0x1BA8, 0x1BAB, 0x1BAE, 0x1BB1,
|
|
||||||
0x1BB4, 0x1BB7, 0x1BBA, 0x1BBD, 0x1BC1, 0x1BC4, 0x1BC7, 0x1BCA,
|
|
||||||
0x1BCD, 0x1BD0, 0x1BD3, 0x1BD6, 0x1BD9, 0x1BDC, 0x1BDF, 0x1BE2,
|
|
||||||
0x1BE5, 0x1BE8, 0x1BEB, 0x1BEE, 0x1BF2, 0x1BF5, 0x1BF8, 0x1BFB,
|
|
||||||
0x1BFE, 0x1C01, 0x1C04, 0x1C07, 0x1C0A, 0x1C0D, 0x1C10, 0x1C13,
|
|
||||||
0x1C16, 0x1C19, 0x1C1C, 0x1C1F, 0x1C22, 0x1C25, 0x1C28, 0x1C2B,
|
|
||||||
0x1C2E, 0x1C31, 0x1C34, 0x1C37, 0x1C3A, 0x1C3D, 0x1C40, 0x1C43,
|
|
||||||
0x1C46, 0x1C49, 0x1C4C, 0x1C4F, 0x1C52, 0x1C55, 0x1C58, 0x1C5B,
|
|
||||||
0x1C5E, 0x1C61, 0x1C64, 0x1C67, 0x1C6A, 0x1C6D, 0x1C70, 0x1C73,
|
|
||||||
0x1C76, 0x1C79, 0x1C7C, 0x1C7F, 0x1C82, 0x1C85, 0x1C88, 0x1C8B,
|
|
||||||
0x1C8E, 0x1C91, 0x1C94, 0x1C97, 0x1C9A, 0x1C9D, 0x1CA0, 0x1CA3,
|
|
||||||
0x1CA6, 0x1CA9, 0x1CAC, 0x1CAF, 0x1CB2, 0x1CB5, 0x1CB8, 0x1CBB,
|
|
||||||
0x1CBE, 0x1CC1, 0x1CC3, 0x1CC6, 0x1CC9, 0x1CCC, 0x1CCF, 0x1CD2,
|
|
||||||
0x1CD5, 0x1CD8, 0x1CDB, 0x1CDE, 0x1CE1, 0x1CE4, 0x1CE7, 0x1CEA,
|
|
||||||
0x1CED, 0x1CF0, 0x1CF3, 0x1CF5, 0x1CF8, 0x1CFB, 0x1CFE, 0x1D01,
|
|
||||||
0x1D04, 0x1D07, 0x1D0A, 0x1D0D, 0x1D10, 0x1D13, 0x1D16, 0x1D18,
|
|
||||||
0x1D1B, 0x1D1E, 0x1D21, 0x1D24, 0x1D27, 0x1D2A, 0x1D2D, 0x1D30,
|
|
||||||
0x1D33, 0x1D35, 0x1D38, 0x1D3B, 0x1D3E, 0x1D41, 0x1D44, 0x1D47,
|
|
||||||
0x1D4A, 0x1D4D, 0x1D4F, 0x1D52, 0x1D55, 0x1D58, 0x1D5B, 0x1D5E,
|
|
||||||
0x1D61, 0x1D64, 0x1D66, 0x1D69, 0x1D6C, 0x1D6F, 0x1D72, 0x1D75,
|
|
||||||
0x1D78, 0x1D7B, 0x1D7D, 0x1D80, 0x1D83, 0x1D86, 0x1D89, 0x1D8C,
|
|
||||||
0x1D8E, 0x1D91, 0x1D94, 0x1D97, 0x1D9A, 0x1D9D, 0x1DA0, 0x1DA2,
|
|
||||||
0x1DA5, 0x1DA8, 0x1DAB, 0x1DAE, 0x1DB1, 0x1DB3, 0x1DB6, 0x1DB9,
|
|
||||||
0x1DBC, 0x1DBF, 0x1DC2, 0x1DC4, 0x1DC7, 0x1DCA, 0x1DCD, 0x1DD0,
|
|
||||||
0x1DD3, 0x1DD5, 0x1DD8, 0x1DDB, 0x1DDE, 0x1DE1, 0x1DE3, 0x1DE6,
|
|
||||||
0x1DE9, 0x1DEC, 0x1DEF, 0x1DF1, 0x1DF4, 0x1DF7, 0x1DFA, 0x1DFD,
|
|
||||||
0x1DFF, 0x1E02, 0x1E05, 0x1E08, 0x1E0B, 0x1E0D, 0x1E10, 0x1E13,
|
|
||||||
0x1E16, 0x1E19, 0x1E1B, 0x1E1E, 0x1E21, 0x1E24, 0x1E26, 0x1E29,
|
|
||||||
0x1E2C, 0x1E2F, 0x1E32, 0x1E34, 0x1E37, 0x1E3A, 0x1E3D, 0x1E3F,
|
|
||||||
0x1E42, 0x1E45, 0x1E48, 0x1E4A, 0x1E4D, 0x1E50, 0x1E53, 0x1E55,
|
|
||||||
0x1E58, 0x1E5B, 0x1E5E, 0x1E60, 0x1E63, 0x1E66, 0x1E69, 0x1E6B,
|
|
||||||
0x1E6E, 0x1E71, 0x1E74, 0x1E76, 0x1E79, 0x1E7C, 0x1E7F, 0x1E81,
|
|
||||||
0x1E84, 0x1E87, 0x1E8A, 0x1E8C, 0x1E8F, 0x1E92, 0x1E94, 0x1E97,
|
|
||||||
0x1E9A, 0x1E9D, 0x1E9F, 0x1EA2, 0x1EA5, 0x1EA8, 0x1EAA, 0x1EAD,
|
|
||||||
0x1EB0, 0x1EB2, 0x1EB5, 0x1EB8, 0x1EBA, 0x1EBD, 0x1EC0, 0x1EC3,
|
|
||||||
0x1EC5, 0x1EC8, 0x1ECB, 0x1ECD, 0x1ED0, 0x1ED3, 0x1ED5, 0x1ED8,
|
|
||||||
0x1EDB, 0x1EDE, 0x1EE0, 0x1EE3, 0x1EE6, 0x1EE8, 0x1EEB, 0x1EEE,
|
|
||||||
0x1EF0, 0x1EF3, 0x1EF6, 0x1EF8, 0x1EFB, 0x1EFE, 0x1F00, 0x1F03,
|
|
||||||
0x1F06, 0x1F08, 0x1F0B, 0x1F0E, 0x1F10, 0x1F13, 0x1F16, 0x1F18,
|
|
||||||
0x1F1B, 0x1F1E, 0x1F20, 0x1F23, 0x1F26, 0x1F28, 0x1F2B, 0x1F2E,
|
|
||||||
0x1F30, 0x1F33, 0x1F36, 0x1F38, 0x1F3B, 0x1F3D, 0x1F40, 0x1F43,
|
|
||||||
0x1F45, 0x1F48, 0x1F4B, 0x1F4D, 0x1F50, 0x1F53, 0x1F55, 0x1F58,
|
|
||||||
0x1F5A, 0x1F5D, 0x1F60, 0x1F62, 0x1F65, 0x1F68, 0x1F6A, 0x1F6D,
|
|
||||||
0x1F6F, 0x1F72, 0x1F75, 0x1F77, 0x1F7A, 0x1F7C, 0x1F7F, 0x1F82,
|
|
||||||
0x1F84, 0x1F87, 0x1F8A, 0x1F8C, 0x1F8F, 0x1F91, 0x1F94, 0x1F97,
|
|
||||||
0x1F99, 0x1F9C, 0x1F9E, 0x1FA1, 0x1FA4, 0x1FA6, 0x1FA9, 0x1FAB,
|
|
||||||
0x1FAE, 0x1FB0, 0x1FB3, 0x1FB6, 0x1FB8, 0x1FBB, 0x1FBD, 0x1FC0,
|
|
||||||
0x1FC3, 0x1FC5, 0x1FC8, 0x1FCA, 0x1FCD, 0x1FCF, 0x1FD2, 0x1FD5,
|
|
||||||
0x1FD7, 0x1FDA, 0x1FDC, 0x1FDF, 0x1FE1, 0x1FE4, 0x1FE6, 0x1FE9,
|
|
||||||
0x1FEC, 0x1FEE, 0x1FF1, 0x1FF3, 0x1FF6, 0x1FF8, 0x1FFB, 0x1FFD,
|
|
||||||
0x2000, 0x2000,
|
|
||||||
};
|
|
62
camera.c
62
camera.c
@ -1,62 +0,0 @@
|
|||||||
#include "camera.h"
|
|
||||||
#include "math.h"
|
|
||||||
|
|
||||||
void getCameraXZ(int * x, int * z, int actorX, int actorZ, int angle, int distance) {
|
|
||||||
|
|
||||||
// Using Nic's Costable : https://github.com/grumpycoders/Balau/blob/master/tests/test-Handles.cc#L20-L102
|
|
||||||
// https://godbolt.org/z/q6cMcj
|
|
||||||
|
|
||||||
*x = (actorX << 12) + (distance * nsin(angle));
|
|
||||||
|
|
||||||
*z = (actorZ << 12) - (distance * ncos(angle));
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
void getCameraXZY(int * x, int * z, int * y, int actorX, int actorZ, int actorY, int angle, int angleX, int distance) {
|
|
||||||
|
|
||||||
// Using Nic's Costable : https://github.com/grumpycoders/Balau/blob/master/tests/test-Handles.cc#L20-L102
|
|
||||||
// https://godbolt.org/z/q6cMcj
|
|
||||||
|
|
||||||
*x = (actorX << 12) + (distance * nsin(angle));
|
|
||||||
|
|
||||||
*z = (actorZ << 12) - (distance * ( ( ncos(angle) * ncos(angleX) ) >> 12 ) );
|
|
||||||
|
|
||||||
*y = (actorY << 12) - (distance * nsin(angleX));
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
void getCameraZY( int * z, int * y, int actorZ, int actorY, int angleX, int distance) {
|
|
||||||
|
|
||||||
*z = (actorZ << 12) - (distance * ncos(angleX));
|
|
||||||
|
|
||||||
*y = (actorY << 12) - (distance * nsin(angleX));
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// @Will : you might want to use sin/cos to move the camera in a circle but you could do that by moving it along it’s tangent and then clamping the distance
|
|
||||||
|
|
||||||
void applyCamera( CAMERA * cam ) {
|
|
||||||
|
|
||||||
VECTOR vec; // Vector that holds the output values of the following instructions
|
|
||||||
|
|
||||||
RotMatrix_gte(&cam->rot, &cam->mat); // Convert rotation angle in psx units (360° == 4096) to rotation matrix)
|
|
||||||
|
|
||||||
ApplyMatrixLV(&cam->mat, &cam->pos, &vec); // Multiply matrix by vector pos and output to vec
|
|
||||||
|
|
||||||
TransMatrix(&cam->mat, &vec); // Apply transform vector
|
|
||||||
|
|
||||||
SetRotMatrix(&cam->mat); // Set Rotation matrix
|
|
||||||
|
|
||||||
SetTransMatrix(&cam->mat); // Set Transform matrix
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
void setCameraPos( CAMERA * camera, VECTOR pos, SVECTOR rot ) {
|
|
||||||
|
|
||||||
camera->pos = pos;
|
|
||||||
|
|
||||||
camera->rot = rot;
|
|
||||||
|
|
||||||
};
|
|
46
camera.h
46
camera.h
@ -1,46 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <libgte.h>
|
|
||||||
|
|
||||||
// Camera modes
|
|
||||||
#define ACTOR 0
|
|
||||||
#define ROTATE 1
|
|
||||||
#define FIXED 2
|
|
||||||
#define TRACK 3
|
|
||||||
#define FLYCAM 4
|
|
||||||
#define FOLLOW 5
|
|
||||||
|
|
||||||
typedef struct{
|
|
||||||
|
|
||||||
int x, xv; // x: current value += xv : new value
|
|
||||||
|
|
||||||
int y, yv; // x,y,z, vx, vy, vz are in PSX units (ONE == 4096)
|
|
||||||
|
|
||||||
int z, zv;
|
|
||||||
|
|
||||||
int pan, panv;
|
|
||||||
|
|
||||||
int tilt, tiltv;
|
|
||||||
|
|
||||||
int rol;
|
|
||||||
|
|
||||||
VECTOR pos;
|
|
||||||
|
|
||||||
SVECTOR rot;
|
|
||||||
|
|
||||||
SVECTOR dvs;
|
|
||||||
|
|
||||||
MATRIX mat;
|
|
||||||
|
|
||||||
} CAMERA;
|
|
||||||
|
|
||||||
void getCameraXZ(int * x, int * z, int actorX, int actorZ, int angle, int distance);
|
|
||||||
|
|
||||||
void getCameraXZY(int * x, int * z, int * y, int actorX, int actorZ, int actorY, int angle, int angleX, int distance);
|
|
||||||
|
|
||||||
void getCameraZY( int * z, int * y, int actorZ, int actorY, int angleX, int distance);
|
|
||||||
|
|
||||||
void applyCamera(CAMERA * cam);
|
|
||||||
|
|
||||||
void setCameraPos(CAMERA * camera, VECTOR pos, SVECTOR rot);
|
|
89
defines.h
89
defines.h
@ -1,89 +0,0 @@
|
|||||||
#define VMODE 0 // 0 == NTSC, 1 == PAL
|
|
||||||
|
|
||||||
#define VSYNC 0
|
|
||||||
|
|
||||||
#define SCREENXRES 320
|
|
||||||
|
|
||||||
#define SCREENYRES 240
|
|
||||||
|
|
||||||
#define CENTERX SCREENXRES/2
|
|
||||||
|
|
||||||
#define CENTERY SCREENYRES/2
|
|
||||||
|
|
||||||
#define FOV CENTERX
|
|
||||||
|
|
||||||
#define CLEAR_COLOR_R 0
|
|
||||||
|
|
||||||
#define CLEAR_COLOR_G 0
|
|
||||||
|
|
||||||
#define CLEAR_COLOR_B 0
|
|
||||||
|
|
||||||
// Debug Font
|
|
||||||
|
|
||||||
#define FNT_VRAM_X 960
|
|
||||||
|
|
||||||
#define FNT_VRAM_Y 256
|
|
||||||
|
|
||||||
#define FNT_SCR_X 16
|
|
||||||
|
|
||||||
#define FNT_SCR_Y 192
|
|
||||||
|
|
||||||
#define FNT_SCR_W 240
|
|
||||||
|
|
||||||
#define FNT_SCR_H 32
|
|
||||||
|
|
||||||
#define FNT_SCR_BG 0
|
|
||||||
|
|
||||||
#define FNT_SCR_MAX_CHAR 256
|
|
||||||
|
|
||||||
// Ordering table
|
|
||||||
|
|
||||||
#define OT2LEN 8
|
|
||||||
|
|
||||||
#define OTLEN 768
|
|
||||||
|
|
||||||
#define PRIMBUFFLEN 4096 * sizeof(POLY_GT4) // Maximum number of POLY_GT3 primitives
|
|
||||||
|
|
||||||
// Fog
|
|
||||||
|
|
||||||
#define FOG_NEAR 1300
|
|
||||||
|
|
||||||
#define FOG_FAR 1600
|
|
||||||
|
|
||||||
// Physics
|
|
||||||
|
|
||||||
#define GRAVITY 10
|
|
||||||
|
|
||||||
#define SCALE 4
|
|
||||||
|
|
||||||
// Pad codes defines
|
|
||||||
|
|
||||||
// Applied on PADL
|
|
||||||
|
|
||||||
#define PadSelect ( 1 )
|
|
||||||
|
|
||||||
#define PadStart ( 1 << 3 )
|
|
||||||
|
|
||||||
// Up, Right, Down, Left will be used on PADL (left side of pad )and PADR (right side of pad)
|
|
||||||
|
|
||||||
#define PadUp ( 1 << 4 )
|
|
||||||
|
|
||||||
#define PadRight ( 1 << 5 )
|
|
||||||
|
|
||||||
#define PadDown ( 1 << 6 )
|
|
||||||
|
|
||||||
#define PadLeft ( 1 << 7 )
|
|
||||||
|
|
||||||
#define PadR3 ( 1 << 2 )
|
|
||||||
|
|
||||||
#define PadL3 ( 1 << 1 )
|
|
||||||
|
|
||||||
// Triggers applied on PADR
|
|
||||||
|
|
||||||
#define PadShldL1 ( 1 << 2 )
|
|
||||||
|
|
||||||
#define PadShldL2 ( 1 )
|
|
||||||
|
|
||||||
#define PadShldR1 ( 1 << 3 )
|
|
||||||
|
|
||||||
#define PadShldR2 ( 1 << 1 )
|
|
766
graphics.c
766
graphics.c
@ -1,766 +0,0 @@
|
|||||||
#include "graphics.h"
|
|
||||||
#include "math.h"
|
|
||||||
|
|
||||||
void transformMesh(CAMERA * camera, MESH * mesh){
|
|
||||||
|
|
||||||
MATRIX mat;
|
|
||||||
|
|
||||||
// Apply rotation matrix
|
|
||||||
|
|
||||||
RotMatrix_gte(&mesh->rot, &mat);
|
|
||||||
|
|
||||||
// Apply translation matrix
|
|
||||||
|
|
||||||
TransMatrix(&mat, &mesh->pos);
|
|
||||||
|
|
||||||
// Compose matrix with cam
|
|
||||||
|
|
||||||
CompMatrix(&camera->mat, &mat, &mat);
|
|
||||||
|
|
||||||
// Set default rotation and translation matrices
|
|
||||||
|
|
||||||
SetRotMatrix(&mat);
|
|
||||||
|
|
||||||
SetTransMatrix(&mat);
|
|
||||||
|
|
||||||
//~ }
|
|
||||||
};
|
|
||||||
|
|
||||||
//TODO : Break this monster in tiny bits ?
|
|
||||||
|
|
||||||
void drawPoly(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw) {
|
|
||||||
|
|
||||||
long nclip, t = 0;
|
|
||||||
|
|
||||||
// mesh is POLY_GT3 ( triangle )
|
|
||||||
|
|
||||||
if (mesh->index[t].code == 4) {
|
|
||||||
|
|
||||||
POLY_GT3 * poly;
|
|
||||||
|
|
||||||
// len member == # vertices, but here it's # of triangle... So, for each tri * 3 vertices ...
|
|
||||||
|
|
||||||
for ( int i = 0; i < (mesh->tmesh->len * 3); i += 3 ) {
|
|
||||||
|
|
||||||
// If mesh is not part of precalculated background, draw them, else, discard
|
|
||||||
|
|
||||||
if ( !( mesh->isBG ) || *camMode != 2) {
|
|
||||||
|
|
||||||
poly = (POLY_GT3 *)*nextpri;
|
|
||||||
|
|
||||||
// If Vertex Anim flag is set, use it
|
|
||||||
|
|
||||||
if (mesh->isAnim){
|
|
||||||
|
|
||||||
// If interpolation flag is set, use it
|
|
||||||
|
|
||||||
if(mesh->anim->interpolate){
|
|
||||||
|
|
||||||
// Ping pong
|
|
||||||
|
|
||||||
//~ //if (mesh->anim->cursor > 4096 || mesh->anim->cursor < 0){
|
|
||||||
|
|
||||||
//~ // mesh->anim->dir *= -1;
|
|
||||||
|
|
||||||
//~ //}
|
|
||||||
|
|
||||||
|
|
||||||
// Fixed point math precision
|
|
||||||
|
|
||||||
short precision = 12;
|
|
||||||
|
|
||||||
// Find next keyframe
|
|
||||||
|
|
||||||
if (mesh->anim->cursor > (1 << precision)) {
|
|
||||||
|
|
||||||
// There are still keyframes to interpolate between
|
|
||||||
|
|
||||||
if ( mesh->anim->lerpCursor < mesh->anim->nframes - 1 ) {
|
|
||||||
|
|
||||||
mesh->anim->lerpCursor ++;
|
|
||||||
|
|
||||||
mesh->anim->cursor = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// We've reached last frame, go back to first frame
|
|
||||||
|
|
||||||
if ( mesh->anim->lerpCursor == mesh->anim->nframes - 1 ) {
|
|
||||||
|
|
||||||
mesh->anim->lerpCursor = 0;
|
|
||||||
|
|
||||||
mesh->anim->cursor = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let's lerp between keyframes
|
|
||||||
|
|
||||||
// TODO : Finish lerped animation implementation
|
|
||||||
|
|
||||||
// Vertex 1
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vx = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vx].vx << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vx].vx << precision, mesh->anim->cursor << precision) >> precision;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vz = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vx].vz << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vx].vz << precision, mesh->anim->cursor << precision) >> precision;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vy = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vx].vy << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vx].vy << precision, mesh->anim->cursor << precision) >> precision;
|
|
||||||
|
|
||||||
// Vertex 2
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vx = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vz].vx << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vz].vx << precision, mesh->anim->cursor << precision) >> precision;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vz = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vz].vz << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vz].vz << precision, mesh->anim->cursor << precision) >> precision;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vy = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vz].vy << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vz].vy << precision, mesh->anim->cursor << precision) >> precision;
|
|
||||||
|
|
||||||
// Vertex 3
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vx = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vy].vx << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vy].vx << precision, mesh->anim->cursor << precision) >> precision;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vz = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vy].vz << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vy].vz << precision, mesh->anim->cursor << precision) >> precision;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vy = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vy].vy << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vy].vy << precision, mesh->anim->cursor << precision) >> precision;
|
|
||||||
|
|
||||||
mesh->anim->cursor += 24 * mesh->anim->dir;
|
|
||||||
|
|
||||||
// Coord transformation from world space to screen space
|
|
||||||
|
|
||||||
nclip = RotAverageNclip3(
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.vx ],
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.vz ],
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.vy ],
|
|
||||||
|
|
||||||
( long* ) &poly->x0, ( long* ) &poly->x1, ( long* ) &poly->x2,
|
|
||||||
|
|
||||||
&mesh->p,
|
|
||||||
|
|
||||||
&mesh->OTz,
|
|
||||||
|
|
||||||
Flag
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// No interpolation
|
|
||||||
|
|
||||||
// Use the pre-calculated vertices coordinates from the animation data
|
|
||||||
|
|
||||||
nclip = RotAverageNclip3(
|
|
||||||
|
|
||||||
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vx ],
|
|
||||||
|
|
||||||
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vz ],
|
|
||||||
|
|
||||||
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vy ],
|
|
||||||
|
|
||||||
( long* ) &poly->x0, ( long* ) &poly->x1, ( long* ) &poly->x2,
|
|
||||||
|
|
||||||
&mesh->p,
|
|
||||||
|
|
||||||
&mesh->OTz,
|
|
||||||
|
|
||||||
Flag
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// No animation
|
|
||||||
|
|
||||||
// Use model's regular vertex coordinates
|
|
||||||
|
|
||||||
nclip = RotAverageNclip3(
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.vx ],
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.vz ],
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.vy ],
|
|
||||||
|
|
||||||
( long * ) &poly->x0, ( long * ) &poly->x1, ( long * ) &poly->x2,
|
|
||||||
|
|
||||||
&mesh->p,
|
|
||||||
|
|
||||||
&mesh->OTz,
|
|
||||||
|
|
||||||
Flag
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do not draw invisible meshes
|
|
||||||
|
|
||||||
if ( nclip > 0 && mesh->OTz > 0 && (mesh->p < 4096) ) {
|
|
||||||
|
|
||||||
|
|
||||||
SetPolyGT3( poly );
|
|
||||||
|
|
||||||
// If isPrism flag is set, use it
|
|
||||||
|
|
||||||
// FIXME : Doesn't work with pre-rendered BGs
|
|
||||||
|
|
||||||
if ( mesh->isPrism ) {
|
|
||||||
|
|
||||||
// Transparency effect :
|
|
||||||
|
|
||||||
// Use current DRAWENV clip as TPAGE instead of regular textures
|
|
||||||
|
|
||||||
( (POLY_GT3 *) poly )->tpage = getTPage( mesh->tim->mode&0x3, 0,
|
|
||||||
|
|
||||||
draw->clip.x,
|
|
||||||
|
|
||||||
draw->clip.y
|
|
||||||
);
|
|
||||||
|
|
||||||
// Use projected coordinates (results from RotAverage...) as UV coords and clamp them to 0-255,0-224 Why 224 though ?
|
|
||||||
|
|
||||||
setUV3(poly, (poly->x0 < 0 ? 0 : poly->x0 > 255 ? 255 : poly->x0),
|
|
||||||
|
|
||||||
(poly->y0 < 0 ? 0 : poly->y0 > 240 ? 240 : poly->y0),
|
|
||||||
|
|
||||||
(poly->x1 < 0 ? 0 : poly->x1 > 255 ? 255 : poly->x1),
|
|
||||||
|
|
||||||
(poly->y1 < 0 ? 0 : poly->y1 > 240 ? 240 : poly->y1),
|
|
||||||
|
|
||||||
(poly->x2 < 0 ? 0 : poly->x2 > 255 ? 255 : poly->x2),
|
|
||||||
|
|
||||||
(poly->y2 < 0 ? 0 : poly->y2 > 240 ? 240 : poly->y2)
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// No transparency effect
|
|
||||||
|
|
||||||
// Use regular TPAGE
|
|
||||||
|
|
||||||
( (POLY_GT3 *) poly )->tpage = getTPage(mesh->tim->mode&0x3, 0,
|
|
||||||
|
|
||||||
mesh->tim->prect->x,
|
|
||||||
|
|
||||||
mesh->tim->prect->y
|
|
||||||
);
|
|
||||||
|
|
||||||
setUV3(poly, mesh->tmesh->u[i].vx , mesh->tmesh->u[i].vy + mesh->tim->prect->y,
|
|
||||||
|
|
||||||
mesh->tmesh->u[i+2].vx, mesh->tmesh->u[i+2].vy + mesh->tim->prect->y,
|
|
||||||
|
|
||||||
mesh->tmesh->u[i+1].vx, mesh->tmesh->u[i+1].vy + mesh->tim->prect->y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// CLUT setup
|
|
||||||
// If tim mode == 0 | 1 (4bits/8bits image), set CLUT coordinates
|
|
||||||
|
|
||||||
if ( (mesh->tim->mode & 0x3 ) < 2){
|
|
||||||
|
|
||||||
setClut(poly,
|
|
||||||
|
|
||||||
mesh->tim->crect->x,
|
|
||||||
|
|
||||||
mesh->tim->crect->y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mesh->isSprite ) {
|
|
||||||
|
|
||||||
SetShadeTex( poly, 1 );
|
|
||||||
|
|
||||||
}
|
|
||||||
// Defaults depth color to neutral grey
|
|
||||||
|
|
||||||
CVECTOR outCol = { 128,128,128,0 };
|
|
||||||
|
|
||||||
CVECTOR outCol1 = { 128,128,128,0 };
|
|
||||||
|
|
||||||
CVECTOR outCol2 = { 128,128,128,0 };
|
|
||||||
|
|
||||||
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.vx ], &mesh->tmesh->c[ mesh->index[t].order.vx ], mesh->p, &outCol);
|
|
||||||
|
|
||||||
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.vz ], &mesh->tmesh->c[ mesh->index[t].order.vz ], mesh->p, &outCol1);
|
|
||||||
|
|
||||||
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.vy ], &mesh->tmesh->c[ mesh->index[t].order.vy ], mesh->p, &outCol2);
|
|
||||||
|
|
||||||
// If transparent effect is in use, inhibit shadows
|
|
||||||
|
|
||||||
if (mesh->isPrism){
|
|
||||||
|
|
||||||
// Use un-interpolated (i.e: no light, no fog) colors
|
|
||||||
|
|
||||||
setRGB0(poly, mesh->tmesh->c[i].r, mesh->tmesh->c[i].g, mesh->tmesh->c[i].b);
|
|
||||||
|
|
||||||
setRGB1(poly, mesh->tmesh->c[i+1].r, mesh->tmesh->c[i+1].g, mesh->tmesh->c[i+1].b);
|
|
||||||
|
|
||||||
setRGB2(poly, mesh->tmesh->c[i+2].r, mesh->tmesh->c[i+2].g, mesh->tmesh->c[i+2].b);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
setRGB0(poly, outCol.r, outCol.g , outCol.b);
|
|
||||||
|
|
||||||
setRGB1(poly, outCol1.r, outCol1.g, outCol1.b);
|
|
||||||
|
|
||||||
setRGB2(poly, outCol2.r, outCol2.g, outCol2.b);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( (mesh->OTz > 0) /*&& (*mesh->OTz < OTLEN)*/ && (mesh->p < 4096) ) {
|
|
||||||
|
|
||||||
AddPrim(&ot[ mesh->OTz-2 ], poly);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ mesh->pos2D.vx = *(&poly->x0);
|
|
||||||
//~ mesh->pos2D.vy = *(&poly->x0 + 1);
|
|
||||||
// mesh->pos2D.vy = poly->x0;
|
|
||||||
// FntPrint("%d %d\n", *(&poly->x0), *(&poly->x0 + 1));
|
|
||||||
|
|
||||||
*nextpri += sizeof(POLY_GT3);
|
|
||||||
}
|
|
||||||
|
|
||||||
t+=1;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// If mesh is quad
|
|
||||||
|
|
||||||
if (mesh->index[t].code == 8) {
|
|
||||||
|
|
||||||
POLY_GT4 * poly4;
|
|
||||||
|
|
||||||
for (int i = 0; i < (mesh->tmesh->len * 4); i += 4) {
|
|
||||||
|
|
||||||
// if mesh is not part of BG, draw them, else, discard
|
|
||||||
|
|
||||||
if ( !(mesh->isBG) || *camMode != 2 ) {
|
|
||||||
|
|
||||||
poly4 = (POLY_GT4 *)*nextpri;
|
|
||||||
|
|
||||||
// Vertex Anim
|
|
||||||
|
|
||||||
if (mesh->isAnim){
|
|
||||||
|
|
||||||
// with interpolation
|
|
||||||
|
|
||||||
if ( mesh->anim->interpolate ){
|
|
||||||
|
|
||||||
// ping pong
|
|
||||||
//~ if (mesh->anim->cursor > 4096 || mesh->anim->cursor < 0){
|
|
||||||
//~ mesh->anim->dir *= -1;
|
|
||||||
//~ }
|
|
||||||
|
|
||||||
short precision = 12;
|
|
||||||
|
|
||||||
if ( mesh->anim->cursor > 1<<precision ) {
|
|
||||||
|
|
||||||
if ( mesh->anim->lerpCursor < mesh->anim->nframes - 1 ) {
|
|
||||||
|
|
||||||
mesh->anim->lerpCursor ++;
|
|
||||||
|
|
||||||
mesh->anim->cursor = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mesh->anim->lerpCursor == mesh->anim->nframes - 1 ) {
|
|
||||||
|
|
||||||
mesh->anim->lerpCursor = 0;
|
|
||||||
|
|
||||||
mesh->anim->cursor = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vertex 1
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vx = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vx ].vx << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vx ].vx << 12, mesh->anim->cursor << 12) >> 12;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vz = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vx ].vz << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vx ].vz << 12, mesh->anim->cursor << 12) >> 12;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vy = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vx ].vy << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vx ].vy << 12, mesh->anim->cursor << 12) >> 12;
|
|
||||||
|
|
||||||
// Vertex 2
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vx = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vz ].vx << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vz ].vx << 12, mesh->anim->cursor << 12) >> 12;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vz = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vz ].vz << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vz ].vz << 12, mesh->anim->cursor << 12) >> 12;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vy = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vz ].vy << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vz ].vy << 12, mesh->anim->cursor << 12) >> 12;
|
|
||||||
|
|
||||||
// Vertex 3
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vx = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vy ].vx << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vy ].vx << 12, mesh->anim->cursor << 12) >> 12;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vz = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vy ].vz << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vy ].vz << 12, mesh->anim->cursor << 12) >> 12;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vy = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vy ].vy << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vy ].vy << 12, mesh->anim->cursor << 12) >> 12;
|
|
||||||
|
|
||||||
// Vertex 4
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.pad ].vx = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.pad ].vx << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.pad ].vx << 12, mesh->anim->cursor << 12) >> 12;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.pad ].vz = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.pad ].vz << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.pad ].vz << 12, mesh->anim->cursor << 12) >> 12;
|
|
||||||
|
|
||||||
mesh->tmesh->v[ mesh->index[ t ].order.pad ].vy = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.pad ].vy << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.pad ].vy << 12, mesh->anim->cursor << 12) >> 12;
|
|
||||||
|
|
||||||
mesh->anim->cursor += 2 * mesh->anim->dir;
|
|
||||||
|
|
||||||
// Coord transformations
|
|
||||||
nclip = RotAverageNclip4(
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.pad ],
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.vz],
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.vx ],
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.vy ],
|
|
||||||
|
|
||||||
( long* )&poly4->x0, ( long* )&poly4->x1, ( long* )&poly4->x2, ( long* )&poly4->x3,
|
|
||||||
|
|
||||||
&mesh->p,
|
|
||||||
|
|
||||||
&mesh->OTz,
|
|
||||||
|
|
||||||
Flag
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// No interpolation, use all vertices coordinates in anim data
|
|
||||||
|
|
||||||
nclip = RotAverageNclip4(
|
|
||||||
|
|
||||||
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.pad ],
|
|
||||||
|
|
||||||
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vz ],
|
|
||||||
|
|
||||||
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vx ],
|
|
||||||
|
|
||||||
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vy ],
|
|
||||||
|
|
||||||
( long* )&poly4->x0, ( long* )&poly4->x1, ( long* )&poly4->x2, ( long* )&poly4->x3,
|
|
||||||
|
|
||||||
&mesh->p,
|
|
||||||
|
|
||||||
&mesh->OTz,
|
|
||||||
|
|
||||||
Flag
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// No animation
|
|
||||||
// Use regulare vertex coords
|
|
||||||
|
|
||||||
nclip = RotAverageNclip4(
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.pad ],
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.vz],
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.vx ],
|
|
||||||
|
|
||||||
&mesh->tmesh->v[ mesh->index[t].order.vy ],
|
|
||||||
|
|
||||||
(long*)&poly4->x0, (long*)&poly4->x1, (long*)&poly4->x2, (long*)&poly4->x3,
|
|
||||||
|
|
||||||
&mesh->p,
|
|
||||||
|
|
||||||
&mesh->OTz,
|
|
||||||
|
|
||||||
Flag
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nclip > 0 && mesh->OTz > 0 && (mesh->p < 4096)) {
|
|
||||||
|
|
||||||
SetPolyGT4(poly4);
|
|
||||||
|
|
||||||
// FIXME : Polygon subdiv - is it working ?
|
|
||||||
|
|
||||||
//~ OTc = *mesh->OTz >> 4;
|
|
||||||
//~ FntPrint("OTC:%d", OTc);
|
|
||||||
|
|
||||||
//~ if (OTc < 4) {
|
|
||||||
|
|
||||||
//~ if (OTc > 1) div4.ndiv = 1; else div4.ndiv = 2;
|
|
||||||
|
|
||||||
//~ DivideGT4(
|
|
||||||
//~ // Vertex coord
|
|
||||||
//~ &mesh->tmesh->v[ mesh->index[t].order.pad ],
|
|
||||||
//~ &mesh->tmesh->v[ mesh->index[t].order.vz ],
|
|
||||||
//~ &mesh->tmesh->v[ mesh->index[t].order.vx ],
|
|
||||||
//~ &mesh->tmesh->v[ mesh->index[t].order.vy ],
|
|
||||||
//~ // UV coord
|
|
||||||
//~ mesh->tmesh->u[i+3],
|
|
||||||
//~ mesh->tmesh->u[i+2],
|
|
||||||
//~ mesh->tmesh->u[i+0],
|
|
||||||
//~ mesh->tmesh->u[i+1],
|
|
||||||
|
|
||||||
//~ // Color
|
|
||||||
//~ mesh->tmesh->c[i],
|
|
||||||
//~ mesh->tmesh->c[i+1],
|
|
||||||
//~ mesh->tmesh->c[i+2],
|
|
||||||
//~ mesh->tmesh->c[i+3],
|
|
||||||
|
|
||||||
//~ // Gpu packet
|
|
||||||
//~ poly4,
|
|
||||||
//~ &ot[db][*mesh->OTz],
|
|
||||||
//~ &div4);
|
|
||||||
|
|
||||||
//~ // Increment primitive list pointer
|
|
||||||
//~ *nextpri += ( (sizeof(POLY_GT4) + 3) / 4 ) * (( 1 << ( div4.ndiv )) << ( div4.ndiv ));
|
|
||||||
//~ triCount = ((1<<(div4.ndiv))<<(div4.ndiv));
|
|
||||||
|
|
||||||
//~ } else if (OTc < 48) {
|
|
||||||
|
|
||||||
// Transparency effect
|
|
||||||
|
|
||||||
if (mesh->isPrism){
|
|
||||||
|
|
||||||
// Use current DRAWENV clip as TPAGE
|
|
||||||
|
|
||||||
( (POLY_GT4 *) poly4)->tpage = getTPage(mesh->tim->mode&0x3, 0,
|
|
||||||
|
|
||||||
draw->clip.x,
|
|
||||||
|
|
||||||
draw->clip.y
|
|
||||||
);
|
|
||||||
|
|
||||||
// Use projected coordinates
|
|
||||||
|
|
||||||
setUV4( poly4,
|
|
||||||
|
|
||||||
(poly4->x0 < 0? 0 : poly4->x0 > 255? 255 : poly4->x0),
|
|
||||||
|
|
||||||
(poly4->y0 < 0? 0 : poly4->y0 > 224? 224 : poly4->y0),
|
|
||||||
|
|
||||||
(poly4->x1 < 0? 0 : poly4->x1 > 255? 255 : poly4->x1),
|
|
||||||
|
|
||||||
(poly4->y1 < 0? 0 : poly4->y1 > 224? 224 : poly4->y1),
|
|
||||||
|
|
||||||
(poly4->x2 < 0? 0 : poly4->x2 > 255? 255 : poly4->x2),
|
|
||||||
|
|
||||||
(poly4->y2 < 0? 0 : poly4->y2 > 224? 224 : poly4->y2),
|
|
||||||
|
|
||||||
(poly4->x3 < 0? 0 : poly4->x3 > 255? 255 : poly4->x3),
|
|
||||||
|
|
||||||
(poly4->y3 < 0? 0 : poly4->y3 > 224? 224 : poly4->y3)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Use regular TPAGE
|
|
||||||
( (POLY_GT4 *) poly4)->tpage = getTPage(
|
|
||||||
|
|
||||||
mesh->tim->mode&0x3, 0,
|
|
||||||
|
|
||||||
mesh->tim->prect->x,
|
|
||||||
|
|
||||||
mesh->tim->prect->y
|
|
||||||
);
|
|
||||||
|
|
||||||
// Use model UV coordinates
|
|
||||||
|
|
||||||
setUV4( poly4,
|
|
||||||
mesh->tmesh->u[i+3].vx, mesh->tmesh->u[i+3].vy + mesh->tim->prect->y,
|
|
||||||
|
|
||||||
mesh->tmesh->u[i+2].vx, mesh->tmesh->u[i+2].vy + mesh->tim->prect->y,
|
|
||||||
|
|
||||||
mesh->tmesh->u[i+0].vx, mesh->tmesh->u[i+0].vy + mesh->tim->prect->y,
|
|
||||||
|
|
||||||
mesh->tmesh->u[i+1].vx, mesh->tmesh->u[i+1].vy + mesh->tim->prect->y
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mesh->isSprite){
|
|
||||||
|
|
||||||
SetShadeTex( poly4, 1 );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// If tim mode == 0 | 1, set CLUT coordinates
|
|
||||||
if ( (mesh->tim->mode & 0x3) < 2 ) {
|
|
||||||
|
|
||||||
setClut(poly4,
|
|
||||||
|
|
||||||
mesh->tim->crect->x,
|
|
||||||
|
|
||||||
mesh->tim->crect->y
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
CVECTOR outCol = {128,128,128,0};
|
|
||||||
|
|
||||||
CVECTOR outCol1 = {128,128,128,0};
|
|
||||||
|
|
||||||
CVECTOR outCol2 = {128,128,128,0};
|
|
||||||
|
|
||||||
CVECTOR outCol3 = {128,128,128,0};
|
|
||||||
|
|
||||||
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.pad ] , &mesh->tmesh->c[ mesh->index[t].order.pad ], mesh->p, &outCol);
|
|
||||||
|
|
||||||
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.vz ], &mesh->tmesh->c[ mesh->index[t].order.vz ], mesh->p, &outCol1);
|
|
||||||
|
|
||||||
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.vx ], &mesh->tmesh->c[ mesh->index[t].order.vx ], mesh->p, &outCol2);
|
|
||||||
|
|
||||||
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.vy ], &mesh->tmesh->c[ mesh->index[t].order.vy ], mesh->p, &outCol3);
|
|
||||||
|
|
||||||
if (mesh->isPrism){
|
|
||||||
|
|
||||||
setRGB0(poly4, mesh->tmesh->c[i].r, mesh->tmesh->c[i].g, mesh->tmesh->c[i].b);
|
|
||||||
|
|
||||||
setRGB1(poly4, mesh->tmesh->c[i+1].r, mesh->tmesh->c[i+1].g, mesh->tmesh->c[i+1].b);
|
|
||||||
|
|
||||||
setRGB2(poly4, mesh->tmesh->c[i+2].r, mesh->tmesh->c[i+2].g, mesh->tmesh->c[i+2].b);
|
|
||||||
|
|
||||||
setRGB3(poly4, mesh->tmesh->c[i+3].r, mesh->tmesh->c[i+3].g, mesh->tmesh->c[i+3].b);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
setRGB0(poly4, outCol.r, outCol.g , outCol.b);
|
|
||||||
|
|
||||||
setRGB1(poly4, outCol1.r, outCol1.g, outCol1.b);
|
|
||||||
|
|
||||||
setRGB2(poly4, outCol2.r, outCol2.g, outCol2.b);
|
|
||||||
|
|
||||||
setRGB3(poly4, outCol3.r, outCol3.g, outCol3.b);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( (mesh->OTz > 0) /*&& (*mesh->OTz < OTLEN)*/ && (mesh->p < 4096) ) {
|
|
||||||
|
|
||||||
AddPrim( &ot[ mesh->OTz-3 ], poly4 );
|
|
||||||
}
|
|
||||||
|
|
||||||
*nextpri += sizeof( POLY_GT4 );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
t += 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
void drawBG(CAMANGLE * camPtr, char ** nextpri, u_long * otdisc, char * db) {
|
|
||||||
|
|
||||||
// Draw BG image in two SPRT since max width == 256 px
|
|
||||||
|
|
||||||
SPRT * sprt;
|
|
||||||
|
|
||||||
DR_TPAGE * tpage;
|
|
||||||
|
|
||||||
// Left part
|
|
||||||
|
|
||||||
sprt = ( SPRT * ) *nextpri;
|
|
||||||
|
|
||||||
setSprt( sprt );
|
|
||||||
|
|
||||||
setRGB0( sprt, 128, 128, 128 );
|
|
||||||
|
|
||||||
setXY0( sprt, 0, 0 );
|
|
||||||
|
|
||||||
setWH( sprt, 256, SCREENYRES );
|
|
||||||
|
|
||||||
setUV0( sprt, 0, 0 );
|
|
||||||
|
|
||||||
setClut( sprt,
|
|
||||||
|
|
||||||
camPtr->BGtim->crect->x,
|
|
||||||
|
|
||||||
camPtr->BGtim->crect->y
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
addPrim( otdisc[ OT2LEN - 1 ], sprt );
|
|
||||||
|
|
||||||
*nextpri += sizeof( SPRT );
|
|
||||||
|
|
||||||
|
|
||||||
// Change TPAGE
|
|
||||||
|
|
||||||
tpage = (DR_TPAGE *) *nextpri;
|
|
||||||
|
|
||||||
setDrawTPage(
|
|
||||||
|
|
||||||
tpage, 0, 1,
|
|
||||||
|
|
||||||
getTPage(
|
|
||||||
|
|
||||||
camPtr->BGtim->mode & 0x3, 0,
|
|
||||||
|
|
||||||
camPtr->BGtim->prect->x,
|
|
||||||
|
|
||||||
camPtr->BGtim->prect->y
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
addPrim( otdisc[OT2LEN-1], tpage);
|
|
||||||
|
|
||||||
*nextpri += sizeof(DR_TPAGE);
|
|
||||||
|
|
||||||
|
|
||||||
// Right part
|
|
||||||
|
|
||||||
sprt = ( SPRT * ) *nextpri;
|
|
||||||
|
|
||||||
setSprt( sprt );
|
|
||||||
|
|
||||||
setRGB0( sprt, 128, 128, 128 );
|
|
||||||
|
|
||||||
setXY0( sprt, SCREENXRES - ( SCREENXRES - 256 ), 0 );
|
|
||||||
|
|
||||||
setWH( sprt, SCREENXRES - 256, SCREENYRES );
|
|
||||||
|
|
||||||
setUV0( sprt, 0, 0 );
|
|
||||||
|
|
||||||
setClut( sprt,
|
|
||||||
|
|
||||||
camPtr->BGtim->crect->x,
|
|
||||||
|
|
||||||
camPtr->BGtim->crect->y
|
|
||||||
);
|
|
||||||
|
|
||||||
addPrim( otdisc[ OT2LEN-1 ], sprt );
|
|
||||||
|
|
||||||
*nextpri += sizeof( SPRT );
|
|
||||||
|
|
||||||
tpage = ( DR_TPAGE * ) *nextpri;
|
|
||||||
|
|
||||||
// Change TPAGE
|
|
||||||
|
|
||||||
setDrawTPage(
|
|
||||||
|
|
||||||
tpage, 0, 1,
|
|
||||||
|
|
||||||
getTPage(
|
|
||||||
|
|
||||||
camPtr->BGtim->mode & 0x3, 0,
|
|
||||||
|
|
||||||
// X offset width depends on TIM's mode
|
|
||||||
|
|
||||||
camPtr->BGtim->prect->x + ( 64 << ( camPtr->BGtim->mode & 0x3 ) ),
|
|
||||||
|
|
||||||
camPtr->BGtim->prect->y
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
addPrim( otdisc[ OT2LEN-1 ], tpage );
|
|
||||||
|
|
||||||
*nextpri += sizeof( DR_TPAGE );
|
|
||||||
|
|
||||||
};
|
|
13
graphics.h
13
graphics.h
@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "camera.h"
|
|
||||||
#include "physics.h"
|
|
||||||
#include "defines.h"
|
|
||||||
|
|
||||||
// Drawing
|
|
||||||
|
|
||||||
void transformMesh(CAMERA * camera, MESH * meshes);
|
|
||||||
|
|
||||||
void drawPoly(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw);
|
|
||||||
|
|
||||||
void drawBG(CAMANGLE * camPtr, char ** nextpri, u_long * otdisc, char * db);
|
|
34
macros.h
34
macros.h
@ -1,34 +0,0 @@
|
|||||||
// MACROS
|
|
||||||
|
|
||||||
// swap(x, y, buffer)
|
|
||||||
|
|
||||||
#define SWAP(a,b,c) {(c)=(a); (a)=(b); (b)=(c);}
|
|
||||||
|
|
||||||
// dotproduct of two vectors
|
|
||||||
|
|
||||||
#define dotProduct(v0, v1) \
|
|
||||||
(v0).vx * (v1).vx + \
|
|
||||||
(v0).vy * (v1).vy + \
|
|
||||||
(v0).vz * (v1).vz
|
|
||||||
|
|
||||||
// min value
|
|
||||||
|
|
||||||
#define min(a,b) \
|
|
||||||
(a)-(b)>0?(b):(a)
|
|
||||||
// max
|
|
||||||
|
|
||||||
#define max(a,b) \
|
|
||||||
(a)-(b)>0?(a):(b)
|
|
||||||
|
|
||||||
// substract vector
|
|
||||||
|
|
||||||
#define subVector(v0, v1) \
|
|
||||||
(v0).vx - (v1).vx, \
|
|
||||||
(v0).vy - (v1).vy, \
|
|
||||||
(v0).vz - (v1).vz
|
|
||||||
|
|
||||||
|
|
||||||
#define normalizeVector(v) \
|
|
||||||
((v)->vx << 12) >> 8, \
|
|
||||||
((v)->vy << 12) >> 8, \
|
|
||||||
((v)->vz << 12) >> 8
|
|
271
math.c
271
math.c
@ -1,271 +0,0 @@
|
|||||||
#include "math.h"
|
|
||||||
|
|
||||||
// Stolen from grumpycoder
|
|
||||||
// this is from here : https://github.com/grumpycoders/Balau/blob/master/tests/test-Handles.cc#L20-L102
|
|
||||||
|
|
||||||
// precalc costable
|
|
||||||
|
|
||||||
static int m_cosTable[512];
|
|
||||||
|
|
||||||
static const unsigned int DC_2PI = 2048;
|
|
||||||
|
|
||||||
static const unsigned int DC_PI = 1024;
|
|
||||||
|
|
||||||
static const unsigned int DC_PI2 = 512;
|
|
||||||
|
|
||||||
// f(n) = cos(n * 2pi / 2048) <- 2048 is == DC_2PI value
|
|
||||||
// f(n) = 2 * f(1) * f(n - 1) - f(n - 2)
|
|
||||||
|
|
||||||
void generateTable(void){
|
|
||||||
|
|
||||||
m_cosTable[0] = 16777216; // 2^24 * cos(0 * 2pi / 2048) => 2^24 * 1 = 2^24 : here, 2^24 defines the precision we want after the decimal point
|
|
||||||
|
|
||||||
static const long long C = 16777137; // 2^24 * cos(1 * 2pi / 2048) = C = f(1);
|
|
||||||
|
|
||||||
m_cosTable[1] = C;
|
|
||||||
|
|
||||||
for (int i = 2; i < 512; i++){
|
|
||||||
|
|
||||||
m_cosTable[i] = ((C * m_cosTable[i - 1]) >> 23) - m_cosTable[i - 2];
|
|
||||||
|
|
||||||
m_cosTable[511] = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int ncos(unsigned int t) {
|
|
||||||
|
|
||||||
t %= DC_2PI;
|
|
||||||
|
|
||||||
int r;
|
|
||||||
|
|
||||||
if (t < DC_PI2) {
|
|
||||||
|
|
||||||
r = m_cosTable[t];
|
|
||||||
|
|
||||||
} else if (t < DC_PI) {
|
|
||||||
|
|
||||||
r = -m_cosTable[DC_PI - 1 - t];
|
|
||||||
|
|
||||||
} else if (t < (DC_PI + DC_PI2)) {
|
|
||||||
|
|
||||||
r = -m_cosTable[t - DC_PI];
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
r = m_cosTable[DC_2PI - 1 - t];
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
return r >> 12;
|
|
||||||
};
|
|
||||||
|
|
||||||
// sin(x) = cos(x - pi / 2)
|
|
||||||
|
|
||||||
int nsin(unsigned int t) {
|
|
||||||
|
|
||||||
t %= DC_2PI;
|
|
||||||
|
|
||||||
if (t < DC_PI2){
|
|
||||||
|
|
||||||
return ncos(t + DC_2PI - DC_PI2);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
return ncos(t - DC_PI2);
|
|
||||||
};
|
|
||||||
|
|
||||||
// https://github.com/Arsunt/TR2Main/blob/411cacb35914c616cb7960c0e677e00c71c7ee88/3dsystem/phd_math.cpp#L432
|
|
||||||
long long patan(long x, long y){
|
|
||||||
|
|
||||||
long long result;
|
|
||||||
|
|
||||||
int swapBuf;
|
|
||||||
|
|
||||||
int flags = 0;
|
|
||||||
|
|
||||||
// if either x or y are 0, return 0
|
|
||||||
|
|
||||||
if( x == 0 && y == 0){
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if( x < 0 ) {
|
|
||||||
|
|
||||||
flags |= 4;
|
|
||||||
|
|
||||||
x = -x;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( y < 0 ) {
|
|
||||||
|
|
||||||
flags |= 2;
|
|
||||||
|
|
||||||
y = -y;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( y > x ) {
|
|
||||||
|
|
||||||
flags |= 1;
|
|
||||||
|
|
||||||
SWAP(x, y ,swapBuf);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
result = AtanBaseTable[flags] + AtanAngleTable[0x800 * y / x];
|
|
||||||
|
|
||||||
if ( result < 0 ){
|
|
||||||
|
|
||||||
result = -result;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
u_int psqrt(u_int n){
|
|
||||||
|
|
||||||
u_int result = 0;
|
|
||||||
|
|
||||||
u_int base = 0x40000000;
|
|
||||||
|
|
||||||
u_int basedResult;
|
|
||||||
|
|
||||||
for( ; base != 0; base >>= 2 ) {
|
|
||||||
|
|
||||||
for( ; base != 0; base >>= 2 ) {
|
|
||||||
|
|
||||||
basedResult = base + result;
|
|
||||||
|
|
||||||
result >>= 1;
|
|
||||||
|
|
||||||
if( basedResult > n ) {
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
n -= basedResult;
|
|
||||||
|
|
||||||
result |= base;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
// From : https://github.com/grumpycoders/pcsx-redux/blob/7438e9995833db5bc1e14da735bbf9dc78300f0b/src/mips/shell/math.h
|
|
||||||
|
|
||||||
int32_t dMul(int32_t a, int32_t b) {
|
|
||||||
|
|
||||||
long long r = a;
|
|
||||||
|
|
||||||
r *= b;
|
|
||||||
|
|
||||||
return r >> 24;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// standard lerp function
|
|
||||||
// s = source, an arbitrary number up to 2^24
|
|
||||||
// d = destination, an arbitrary number up to 2^24
|
|
||||||
// p = position, a number between 0 and 256, inclusive
|
|
||||||
// p = 0 means output = s
|
|
||||||
// p = 256 means output = d
|
|
||||||
|
|
||||||
uint32_t lerpU(uint32_t start, uint32_t dest, unsigned pos) {
|
|
||||||
|
|
||||||
return (start * (256 - pos) + dest * pos) >> 8;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
int32_t lerpS(int32_t start, int32_t dest, unsigned pos) {
|
|
||||||
|
|
||||||
return (start * (256 - pos) + dest * pos) >> 8;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// start, dest and pos have to be << x, then the result has to be >> x where x defines precision:
|
|
||||||
// precision = 2^24 - 2^x
|
|
||||||
// << x : 0 < pos < precision
|
|
||||||
// https://discord.com/channels/642647820683444236/646765703143227394/811318550978494505
|
|
||||||
// my angles are between 0 and 2048 (full circle), so 2^11 for the range of angles; with numbers on a 8.24 representation, a 1.0 angle (or 2pi) means it's 2^24, so to "convert" my angles from 8.24 to my internal discrete cos, I only have to shift by 13
|
|
||||||
|
|
||||||
int32_t lerpD(int32_t start, int32_t dest, int32_t pos) {
|
|
||||||
|
|
||||||
return dMul(start, 16777216 - pos) + dMul(dest, pos);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
long long lerpL(long long start, long long dest, long long pos) {
|
|
||||||
|
|
||||||
return dMul( (start << 12), 16777216 - (pos << 12) ) + dMul((dest << 12), (pos << 12) ) >> 12;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
int lerp(int start, int end, int factor){
|
|
||||||
|
|
||||||
// lerp interpolated cam movement
|
|
||||||
// InBetween = Value 1 + ( ( Value2 - Value1 ) * lerpValue ) ;
|
|
||||||
// lerpValue should be a int between 17 and 256.
|
|
||||||
|
|
||||||
|
|
||||||
return ( ( start ) + ( ( end - start ) * factor ) ) >> 12;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
long long easeIn(long long i){
|
|
||||||
|
|
||||||
return ((i << 7) * (i << 7) * (i << 7) / 32 ) >> 19;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
int easeOut(int i){
|
|
||||||
|
|
||||||
return (4096 >> 7) - ((4096 - (i << 7)) * (4096 - (i << 7))) >> 12;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
//~ int easeInOut(int i, int div){
|
|
||||||
|
|
||||||
//~ return lerp(easeIn(i, div), easeOut(i) , i);
|
|
||||||
|
|
||||||
//~ };
|
|
||||||
|
|
||||||
SVECTOR SVlerp(SVECTOR start, SVECTOR end, int factor){
|
|
||||||
|
|
||||||
SVECTOR output = {0,0,0,0};
|
|
||||||
|
|
||||||
output.vx = lerp(start.vx, end.vx, factor);
|
|
||||||
|
|
||||||
output.vy = lerp(start.vy, end.vy, factor);
|
|
||||||
|
|
||||||
output.vz = lerp(start.vz, end.vz, factor);
|
|
||||||
|
|
||||||
return output;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
VECTOR getVectorTo( VECTOR actor, VECTOR target ) {
|
|
||||||
|
|
||||||
// Returns a normalized vector that points from actor to target
|
|
||||||
|
|
||||||
VECTOR direction = { subVector(target, actor) };
|
|
||||||
|
|
||||||
VECTOR Ndirection = {0,0,0,0};
|
|
||||||
|
|
||||||
u_int distSq = (direction.vx * direction.vx) + (direction.vz * direction.vz);
|
|
||||||
|
|
||||||
direction.pad = psqrt(distSq);
|
|
||||||
|
|
||||||
VectorNormal(&direction, &Ndirection);
|
|
||||||
|
|
||||||
return Ndirection ;
|
|
||||||
|
|
||||||
};
|
|
53
math.h
53
math.h
@ -1,53 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <libgte.h>
|
|
||||||
|
|
||||||
#include "macros.h"
|
|
||||||
|
|
||||||
// Precalculated arctan values
|
|
||||||
|
|
||||||
#include "atan.c"
|
|
||||||
|
|
||||||
// fixed point math
|
|
||||||
|
|
||||||
int32_t dMul(int32_t a, int32_t b);
|
|
||||||
|
|
||||||
uint32_t lerpU(uint32_t start, uint32_t dest, unsigned pos);
|
|
||||||
|
|
||||||
int32_t lerpS(int32_t start, int32_t dest, unsigned pos);
|
|
||||||
|
|
||||||
int32_t lerpD(int32_t start, int32_t dest, int32_t pos);
|
|
||||||
|
|
||||||
long long lerpL(long long start, long long dest, long long pos);
|
|
||||||
|
|
||||||
// Sin/Cos Table
|
|
||||||
|
|
||||||
void generateTable(void);
|
|
||||||
|
|
||||||
int ncos(u_int t);
|
|
||||||
|
|
||||||
int nsin(u_int t);
|
|
||||||
|
|
||||||
// Atan table
|
|
||||||
|
|
||||||
long long patan(long x, long y);
|
|
||||||
|
|
||||||
// Sqrt
|
|
||||||
|
|
||||||
u_int psqrt(u_int n);
|
|
||||||
|
|
||||||
// Lerps
|
|
||||||
|
|
||||||
int lerp(int start, int end, int factor); // FIXME : not working as it should
|
|
||||||
|
|
||||||
SVECTOR SVlerp(SVECTOR start, SVECTOR end, int factor); // FIXME
|
|
||||||
|
|
||||||
long long easeIn(long long i);
|
|
||||||
|
|
||||||
int easeOut(int i);
|
|
||||||
|
|
||||||
//~ int easeInOut(int i, int div);
|
|
||||||
|
|
||||||
VECTOR getVectorTo(VECTOR actor, VECTOR target);
|
|
77
pad.c
77
pad.c
@ -1,77 +0,0 @@
|
|||||||
#include "pad.h"
|
|
||||||
|
|
||||||
void get_digital_direction( Controller_Data *c, int buttondata ) // get analog stick values
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = ~(buttondata);
|
|
||||||
|
|
||||||
if( i & 0x80 )
|
|
||||||
c->xpos -= 1;
|
|
||||||
|
|
||||||
if( i & 0x20 )
|
|
||||||
c->xpos += 1;
|
|
||||||
|
|
||||||
if( i & 0x40 )
|
|
||||||
c->ypos += 1;
|
|
||||||
|
|
||||||
if( i & 0x10 )
|
|
||||||
c->ypos -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_controller( Controller_Data *c, unsigned char *buf, int port ) // get the raw values from controller
|
|
||||||
{
|
|
||||||
register int mouse_x, mouse_y, x;
|
|
||||||
register Gun_Position *g;
|
|
||||||
|
|
||||||
c->status = buf[0]; // Copy over raw controller data
|
|
||||||
c->type = buf[1];
|
|
||||||
c->button1 = buf[2];
|
|
||||||
c->button2 = buf[3];
|
|
||||||
c->analog0 = buf[4];
|
|
||||||
c->analog1 = buf[5];
|
|
||||||
c->analog2 = buf[6];
|
|
||||||
c->analog3 = buf[7];
|
|
||||||
|
|
||||||
if( buf[0] == 0xff ) // If controller returns BAD status then bail on it.
|
|
||||||
{
|
|
||||||
c->type = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look at the controller type code & process controller data as indicated
|
|
||||||
|
|
||||||
switch( c->type )
|
|
||||||
{
|
|
||||||
case 0x12: // Sony Mouse
|
|
||||||
mouse_x = buf[4];
|
|
||||||
mouse_y = buf[5];
|
|
||||||
|
|
||||||
if( mouse_x & 0x80 )
|
|
||||||
mouse_x |= 0xffffff80;
|
|
||||||
if( mouse_y & 0x80 )
|
|
||||||
mouse_y |= 0xffffff80;
|
|
||||||
|
|
||||||
c->xpos += mouse_x;
|
|
||||||
c->ypos += mouse_y;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0x23: // Namco negCon
|
|
||||||
// Steering wheel
|
|
||||||
// Sankyo Pachinko controler
|
|
||||||
get_digital_direction( c, buf[2] );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0x53: // Analog 2-stick
|
|
||||||
get_digital_direction( c, buf[2] );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0x41: // Standard Sony PAD controller
|
|
||||||
get_digital_direction( c, buf[2] );
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: // If don't know what it is, treat it like standard controller
|
|
||||||
get_digital_direction( c, buf[2] );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
36
pad.h
36
pad.h
@ -1,36 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
// Structure for storing processed controller data
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int xpos, ypos; // Stored position for sprite(s)
|
|
||||||
int xpos2, ypos2; // controlled by this controller.
|
|
||||||
unsigned char status; // These 8 values are obtained
|
|
||||||
unsigned char type; // directly from the controller
|
|
||||||
unsigned char button1; // buffer we installed with InitPAD.
|
|
||||||
unsigned char button2;
|
|
||||||
unsigned char analog0;
|
|
||||||
unsigned char analog1;
|
|
||||||
unsigned char analog2;
|
|
||||||
unsigned char analog3;
|
|
||||||
} Controller_Data;
|
|
||||||
|
|
||||||
// All-purpose controller data buffer
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
unsigned char pad[34]; // 8-bytes w/o Multi-Tap, 34-bytes w/Multi-Tap
|
|
||||||
} Controller_Buffer;
|
|
||||||
|
|
||||||
// Structure for RAW hardware-based light gun position values
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
unsigned short v_count; // Y-axis (vertical scan counter)
|
|
||||||
unsigned short h_count; // H-axis (horizontal pixel clock value)
|
|
||||||
} Gun_Position;
|
|
||||||
|
|
||||||
void get_digital_direction( Controller_Data *c, int buttondata );
|
|
||||||
|
|
||||||
void read_controller( Controller_Data *c, unsigned char *buf, int port );
|
|
105
pcdrv.c
105
pcdrv.c
@ -1,105 +0,0 @@
|
|||||||
#include "pcdrv.h"
|
|
||||||
|
|
||||||
int waitForSIODone( int * flag ){
|
|
||||||
|
|
||||||
// This should wait for a signal from the SIO to tell when it's done
|
|
||||||
// Returns val < 0 if wrong
|
|
||||||
|
|
||||||
uint timeOut = 1000;
|
|
||||||
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
for ( uint t = 0; t < timeOut; t ++){
|
|
||||||
|
|
||||||
if ( * flag == 1 ){
|
|
||||||
|
|
||||||
result = * flag;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
void PCload( u_long * loadAddress, u_short * flagAddress, const char * filename ) {
|
|
||||||
|
|
||||||
// Send filename , load address, and flag address
|
|
||||||
// flag address points to an int16 that when set to 1 enable lvl/pointers/screen refresh
|
|
||||||
// Returns 1 if all good, 0 else
|
|
||||||
|
|
||||||
//~ int flag = 0;
|
|
||||||
|
|
||||||
printf("load:%08x:%08x:%s", loadAddress, flagAddress, filename);
|
|
||||||
|
|
||||||
//~ return ; // If all is well, returns a positive int . If -1, wrong
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
//~ int PCopen(const char * filename, int attributes) {
|
|
||||||
|
|
||||||
//~ // Send filename and attributes (ro,wo,rw..)
|
|
||||||
//~ // expects an int referring to a file descriptor on the PC
|
|
||||||
|
|
||||||
//~ int fd = 0; // File Descriptor https://en.wikipedia.org/wiki/File_descriptor
|
|
||||||
|
|
||||||
//~ printf("open:%s:%i:%08x", filename, attributes, &fd);
|
|
||||||
|
|
||||||
//~ waitForSIODone(0);
|
|
||||||
|
|
||||||
//~ return fd; // If all is well, returns a positive int . If -1, wrong
|
|
||||||
|
|
||||||
//~ };
|
|
||||||
|
|
||||||
//~ int PCcreate(const char * filename, int attributes) {
|
|
||||||
|
|
||||||
//~ // Send filename and attributes (ro,wo,rw..)
|
|
||||||
//~ // expects an int referring to a file descriptor on the PC
|
|
||||||
|
|
||||||
//~ int fd = 0; // File Descriptor https://en.wikipedia.org/wiki/File_descriptor
|
|
||||||
|
|
||||||
//~ printf("create:%s:%i:%08x", filename, attributes, &fd);
|
|
||||||
|
|
||||||
//~ waitForSIODone(5); // Should return int fd, -1 else
|
|
||||||
|
|
||||||
//~ return fd; // If all is well, returns a positive int . If -1, wrong
|
|
||||||
|
|
||||||
//~ };
|
|
||||||
|
|
||||||
//~ int PCclose( int fd ) {
|
|
||||||
|
|
||||||
//~ // Send the close command and fd as int
|
|
||||||
|
|
||||||
//~ printf("close:%d", fd);
|
|
||||||
|
|
||||||
//~ return waitForSIODone(1); // Should return 1 if ok, 0 if wrong, or -1 if wrong ?
|
|
||||||
|
|
||||||
//~ };
|
|
||||||
|
|
||||||
//~ int PCseek( int fd, int offset, int accessMode){
|
|
||||||
|
|
||||||
//~ // Move file pointer in fd at offset
|
|
||||||
//~ // Access mode can be 0 abs, 1 rel to start, 2 rel to end
|
|
||||||
|
|
||||||
//~ printf("seek:%i:%08x:%i", fd, offset, accessMode);
|
|
||||||
|
|
||||||
//~ return waitForSIODone(2);
|
|
||||||
|
|
||||||
//~ };
|
|
||||||
|
|
||||||
//~ int PCread( int fd, int len, char * buffer ){
|
|
||||||
|
|
||||||
//~ // Read len bytes of fd and put them in buff
|
|
||||||
|
|
||||||
//~ int count = 0;
|
|
||||||
|
|
||||||
//~ printf("read:%i:%08x:%i", fd, len, buffer, count);
|
|
||||||
|
|
||||||
//~ waitForSIODone(3);
|
|
||||||
|
|
||||||
//~ return count;
|
|
||||||
|
|
||||||
//~ };
|
|
||||||
|
|
27
pcdrv.h
27
pcdrv.h
@ -1,27 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define OPEN 0
|
|
||||||
#define CLOSE 1
|
|
||||||
#define SEEK 2
|
|
||||||
#define READ 3
|
|
||||||
#define WRITE 4
|
|
||||||
#define CREATE 5
|
|
||||||
#define LOAD 6
|
|
||||||
|
|
||||||
int waitForSIODone( int * flag );
|
|
||||||
|
|
||||||
void PCload( u_long * loadAddress, u_short * flagAddress, const char * filename );
|
|
||||||
|
|
||||||
int PCopen(const char * filename, int attributes );
|
|
||||||
|
|
||||||
int PCcreate(const char * filename, int attributes );
|
|
||||||
|
|
||||||
int PCclose( int fd );
|
|
||||||
|
|
||||||
int PCseek( int fd, int offset, int accessMode );
|
|
||||||
|
|
||||||
int PCread( int fd, int len, char * buffer );
|
|
||||||
|
|
313
physics.c
313
physics.c
@ -1,313 +0,0 @@
|
|||||||
#include "physics.h"
|
|
||||||
|
|
||||||
short checkLineW( VECTOR * pointA, VECTOR * pointB, MESH * mesh ) {
|
|
||||||
|
|
||||||
long val1 = ( ( mesh->body->position.vx + mesh->body->min.vx ) - pointA->vx ) * ( pointB->vy - pointA->vy ) - ( ( mesh->body->position.vz + mesh->body->min.vy ) - pointA->vy ) * ( pointB->vx - pointA->vx ) ;
|
|
||||||
|
|
||||||
long val2 = ( ( mesh->body->position.vx + mesh->body->max.vx ) - pointA->vx ) * ( pointB->vy - pointA->vy ) - ( ( mesh->body->position.vz + mesh->body->max.vy ) - pointA->vy ) * ( pointB->vx - pointA->vx ) ;
|
|
||||||
|
|
||||||
if ( val1 > 0 && val2 > 0 ) {
|
|
||||||
|
|
||||||
// right
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if ( val1 < 0 && val2 < 0 ) {
|
|
||||||
|
|
||||||
// left
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if ( val1 == 0 && val2 == 0 ) {
|
|
||||||
|
|
||||||
// identical
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (
|
|
||||||
|
|
||||||
( val1 > 0 && val2 == 0 ) ||
|
|
||||||
|
|
||||||
( val1 == 0 && val2 > 0 )
|
|
||||||
|
|
||||||
) {
|
|
||||||
|
|
||||||
// right
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (
|
|
||||||
|
|
||||||
( val1 < 0 && val2 == 0 ) ||
|
|
||||||
|
|
||||||
( val1 == 0 && val2 < 0 )
|
|
||||||
|
|
||||||
) {
|
|
||||||
|
|
||||||
// left
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (
|
|
||||||
|
|
||||||
( val1 < 0 && val2 > 0 ) ||
|
|
||||||
|
|
||||||
( val1 > 0 && val2 < 0 )
|
|
||||||
|
|
||||||
) {
|
|
||||||
|
|
||||||
// intersect
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// Screen space variant
|
|
||||||
short checkLineS( VECTOR * pointA, VECTOR * pointB, MESH * mesh ) {
|
|
||||||
|
|
||||||
// FIXME : mesh->body->min.vx is not in screen space
|
|
||||||
|
|
||||||
int val1 = ( ( mesh->pos2D.vx + mesh->body->min.vx ) - pointA->vx ) * ( pointB->vy - pointA->vy ) - ( ( mesh->pos2D.vy + mesh->body->min.vy ) - pointA->vy ) * ( pointB->vx - pointA->vx ) ;
|
|
||||||
|
|
||||||
int val2 = ( ( mesh->pos2D.vx + mesh->body->max.vx ) - pointA->vx ) * ( pointB->vy - pointA->vy ) - ( ( mesh->pos2D.vy + mesh->body->max.vy ) - pointA->vy ) * ( pointB->vx - pointA->vx ) ;
|
|
||||||
|
|
||||||
if ( val1 > 0 && val2 > 0 ) {
|
|
||||||
|
|
||||||
// right
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if ( val1 < 0 && val2 < 0 ) {
|
|
||||||
|
|
||||||
// left
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if ( val1 == 0 && val2 == 0 ) {
|
|
||||||
|
|
||||||
// identical
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (
|
|
||||||
|
|
||||||
( val1 > 0 && val2 == 0 ) ||
|
|
||||||
|
|
||||||
( val1 == 0 && val2 > 0 )
|
|
||||||
|
|
||||||
) {
|
|
||||||
|
|
||||||
// right
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (
|
|
||||||
|
|
||||||
( val1 < 0 && val2 == 0 ) ||
|
|
||||||
|
|
||||||
( val1 == 0 && val2 < 0 )
|
|
||||||
|
|
||||||
) {
|
|
||||||
|
|
||||||
// left
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (
|
|
||||||
|
|
||||||
( val1 < 0 && val2 > 0 ) ||
|
|
||||||
|
|
||||||
( val1 > 0 && val2 < 0 )
|
|
||||||
|
|
||||||
) {
|
|
||||||
|
|
||||||
// intersect
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// Physics
|
|
||||||
|
|
||||||
VECTOR getIntCollision(BODY one, BODY two){
|
|
||||||
|
|
||||||
VECTOR d1, d2, col;
|
|
||||||
|
|
||||||
short correction = 50;
|
|
||||||
|
|
||||||
d1.vx = (one.position.vx + one.max.vx) - (two.position.vx + two.min.vx);
|
|
||||||
|
|
||||||
d1.vy = (one.position.vy + one.max.vy) - (two.position.vy + two.min.vy);
|
|
||||||
|
|
||||||
d1.vz = (one.position.vz + one.max.vz) - (two.position.vz + two.min.vz);
|
|
||||||
|
|
||||||
|
|
||||||
d2.vx = (two.position.vx + two.max.vx) - (one.position.vx - one.max.vx);
|
|
||||||
|
|
||||||
d2.vy = (two.position.vy + two.max.vy) - (one.position.vy + one.min.vy);
|
|
||||||
|
|
||||||
d2.vz = (two.position.vz + two.max.vz) - (one.position.vz - one.max.vz);
|
|
||||||
|
|
||||||
|
|
||||||
col.vx = !(d1.vx > 0 && d2.vx > 0);
|
|
||||||
|
|
||||||
col.vy = d1.vy > 0 && d2.vy > 0;
|
|
||||||
|
|
||||||
col.vz = !(d1.vz > 0 && d2.vz > 0);
|
|
||||||
|
|
||||||
return col;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
VECTOR getExtCollision(BODY one, BODY two){
|
|
||||||
|
|
||||||
VECTOR d1, d2, col;
|
|
||||||
|
|
||||||
d1.vx = (one.position.vx + one.max.vx) - (two.position.vx + two.min.vx);
|
|
||||||
|
|
||||||
d1.vy = (one.position.vy + one.max.vy) - (two.position.vy + two.min.vy);
|
|
||||||
|
|
||||||
d1.vz = (one.position.vz + one.max.vz) - (two.position.vz + two.min.vz);
|
|
||||||
|
|
||||||
|
|
||||||
d2.vx = (two.position.vx + two.max.vx) - (one.position.vx + one.min.vx);
|
|
||||||
|
|
||||||
d2.vy = (two.position.vy + two.max.vy) - (one.position.vy + one.min.vy);
|
|
||||||
|
|
||||||
d2.vz = (two.position.vz + two.max.vz) - (one.position.vz + one.min.vz);
|
|
||||||
|
|
||||||
|
|
||||||
col.vx = d1.vx > 0 && d2.vx > 0;
|
|
||||||
|
|
||||||
col.vy = d1.vy > 0 && d2.vy > 0;
|
|
||||||
|
|
||||||
col.vz = d1.vz > 0 && d2.vz > 0;
|
|
||||||
|
|
||||||
|
|
||||||
return col;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
void applyAcceleration(BODY * actor){
|
|
||||||
|
|
||||||
short dt = 1;
|
|
||||||
|
|
||||||
VECTOR acceleration = {actor->invMass * actor->gForce.vx , (actor->invMass * actor->gForce.vy) + (GRAVITY * ONE), actor->invMass * actor->gForce.vz};
|
|
||||||
|
|
||||||
//~ FntPrint("acc: %d %d %d\n", acceleration.vx, acceleration.vy, acceleration.vz );
|
|
||||||
|
|
||||||
actor->velocity.vx += (acceleration.vx * dt) >> 12;
|
|
||||||
|
|
||||||
actor->velocity.vy += (acceleration.vy * dt) >> 12;
|
|
||||||
|
|
||||||
actor->velocity.vz += (acceleration.vz * dt) >> 12;
|
|
||||||
|
|
||||||
//~ FntPrint("acc: %d %d %d\n", acceleration.vx / ONE, acceleration.vy / ONE, acceleration.vz / ONE );
|
|
||||||
|
|
||||||
actor->position.vx += (actor->velocity.vx * dt);
|
|
||||||
|
|
||||||
actor->position.vy += (actor->velocity.vy * dt);
|
|
||||||
|
|
||||||
actor->position.vz += (actor->velocity.vz * dt);
|
|
||||||
|
|
||||||
//~ FntPrint("vel: %d %d %d\n", actor->velocity.vx, actor->velocity.vy, actor->velocity.vz );
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
//~ // https://gamedevelopment.tutsplus.com/tutorials/how-to-create-a-custom-2d-physics-engine-the-basics-and-impulse-resolution--gamedev-6331
|
|
||||||
|
|
||||||
void ResolveCollision( BODY * one, BODY * two ){
|
|
||||||
|
|
||||||
//~ FntPrint("rv: %d, %d, %d\n", one->velocity.vx, one->velocity.vy, one->velocity.vz);
|
|
||||||
|
|
||||||
// Calculate relative velocity
|
|
||||||
|
|
||||||
VECTOR rv = { subVector( one->velocity, two->velocity) };
|
|
||||||
|
|
||||||
//~ FntPrint("rv: %d, %d, %d\n", rv.vx,rv.vy,rv.vz);
|
|
||||||
|
|
||||||
// Collision normal
|
|
||||||
|
|
||||||
VECTOR normal = { subVector( two->position, one->position ) };
|
|
||||||
|
|
||||||
// Normalize collision normal
|
|
||||||
|
|
||||||
normal.vx = normal.vx > 0 ? 1 : normal.vx < 0 ? -1 : 0 ;
|
|
||||||
|
|
||||||
normal.vy = normal.vy > 256 ? 1 : normal.vy < -256 ? -1 : 0 ;
|
|
||||||
|
|
||||||
normal.vz = normal.vz > 0 ? 1 : normal.vz < 0 ? -1 : 0 ;
|
|
||||||
|
|
||||||
//~ FntPrint("norm: %d, %d, %d\n", normal.vx,normal.vy,normal.vz);
|
|
||||||
|
|
||||||
// Calculate relative velocity in terms of the normal direction
|
|
||||||
|
|
||||||
long velAlongNormal = dotProduct( rv, normal );
|
|
||||||
|
|
||||||
//~ FntPrint("velN: %d\n", velAlongNormal);
|
|
||||||
|
|
||||||
// Do not resolve if velocities are separating
|
|
||||||
|
|
||||||
if(velAlongNormal > 0)
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Calculate restitution
|
|
||||||
long e = min( one->restitution, two->restitution );
|
|
||||||
|
|
||||||
//~ FntPrint("e: %d\n", e);
|
|
||||||
|
|
||||||
//~ // Calculate impulse scalar
|
|
||||||
long j = -(1 + e) * velAlongNormal * ONE;
|
|
||||||
|
|
||||||
j /= one->invMass + two->invMass;
|
|
||||||
//~ j /= ONE;
|
|
||||||
|
|
||||||
//~ FntPrint("j: %d\n", j);
|
|
||||||
|
|
||||||
// Apply impulse
|
|
||||||
applyVector(&normal, j, j, j, *=);
|
|
||||||
|
|
||||||
//~ FntPrint("Cnormal %d %d %d\n",normal.vx,normal.vy,normal.vz);
|
|
||||||
|
|
||||||
VECTOR velOne = normal;
|
|
||||||
|
|
||||||
VECTOR velTwo = normal;
|
|
||||||
|
|
||||||
applyVector(&velOne,one->invMass,one->invMass,one->invMass, *=);
|
|
||||||
|
|
||||||
applyVector(&velTwo,two->invMass,two->invMass,two->invMass, *=);
|
|
||||||
|
|
||||||
//~ FntPrint("V1 %d %d %d\n", velOne.vx/4096,velOne.vy/4096,velOne.vz/4096);
|
|
||||||
//~ FntPrint("V2 %d %d %d\n", velTwo.vx/4096,velTwo.vy/4096,velTwo.vz/4096);
|
|
||||||
|
|
||||||
applyVector(&one->velocity, velOne.vx/4096/4096, velOne.vy/4096/4096, velOne.vz/4096/4096, +=);
|
|
||||||
|
|
||||||
applyVector(&two->velocity, velTwo.vx/4096/4096, velTwo.vy/4096/4096, velTwo.vz/4096/4096, -=);
|
|
||||||
|
|
||||||
//~ FntPrint("V1 %d %d %d\n", velOne.vx/4096/4096,velOne.vy/4096/4096,velOne.vz/4096/4096);
|
|
||||||
//~ FntPrint("V2 %d %d %d\n", velTwo.vx/4096/4096,velTwo.vy/4096/4096,velTwo.vz/4096/4096);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
VECTOR angularMom(BODY body){
|
|
||||||
|
|
||||||
// L = r * p
|
|
||||||
|
|
||||||
// p = m * v
|
|
||||||
|
|
||||||
VECTOR w = {0,0,0,0};
|
|
||||||
|
|
||||||
int r = (body.max.vx - body.min.vx) >> 1;
|
|
||||||
|
|
||||||
w.vx = (r * body.mass * body.velocity.vx) >> 2;
|
|
||||||
|
|
||||||
w.vy = (r * body.mass * body.velocity.vy) >> 2;
|
|
||||||
|
|
||||||
w.vz = (r * body.mass * body.velocity.vz) >> 2;
|
|
||||||
|
|
||||||
//~ FntPrint("v: %d, r:%d, w:%d\n", body.velocity.vz * r, r * r, w.vz);
|
|
||||||
|
|
||||||
return w;
|
|
||||||
|
|
||||||
};
|
|
25
physics.h
25
physics.h
@ -1,25 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <libgte.h>
|
|
||||||
#include <libgpu.h>
|
|
||||||
|
|
||||||
#include "defines.h"
|
|
||||||
|
|
||||||
#include "macros.h"
|
|
||||||
|
|
||||||
#include "custom_types.h"
|
|
||||||
|
|
||||||
short checkLineW( VECTOR * pointA, VECTOR * pointB, MESH * mesh );
|
|
||||||
|
|
||||||
short checkLineS( VECTOR * pointA, VECTOR * pointB, MESH * mesh );
|
|
||||||
|
|
||||||
VECTOR getIntCollision(BODY one, BODY two);
|
|
||||||
|
|
||||||
VECTOR getExtCollision(BODY one, BODY two);
|
|
||||||
|
|
||||||
void ResolveCollision( BODY * one, BODY * two );
|
|
||||||
|
|
||||||
VECTOR angularMom(BODY body);
|
|
||||||
|
|
||||||
void applyAcceleration(BODY * actor);
|
|
232
psx.c
232
psx.c
@ -1,232 +0,0 @@
|
|||||||
#include "psx.h"
|
|
||||||
|
|
||||||
void init(DISPENV disp[2], DRAWENV draw[2], short db, MATRIX * cmat, CVECTOR * BGc, VECTOR * BKc) {
|
|
||||||
|
|
||||||
ResetCallback();
|
|
||||||
|
|
||||||
// Init pad
|
|
||||||
|
|
||||||
//~ PadInit(0);
|
|
||||||
|
|
||||||
//~ InitPAD(controllers[0].pad, 34, controllers[1].pad, 34);
|
|
||||||
|
|
||||||
//~ StartPAD();
|
|
||||||
|
|
||||||
// Reset the GPU
|
|
||||||
|
|
||||||
ResetGraph( 0 );
|
|
||||||
|
|
||||||
// Initialize and setup the GTE
|
|
||||||
|
|
||||||
InitGeom();
|
|
||||||
|
|
||||||
SetGeomOffset( CENTERX, CENTERY ); // x, y offset
|
|
||||||
|
|
||||||
SetGeomScreen( FOV ); // Distance between eye and screen - Camera FOV
|
|
||||||
|
|
||||||
// Set the display and draw environments
|
|
||||||
|
|
||||||
SetDefDispEnv(&disp[0], 0, 0 , SCREENXRES, SCREENYRES);
|
|
||||||
|
|
||||||
SetDefDispEnv(&disp[1], 0, SCREENYRES, SCREENXRES, SCREENYRES);
|
|
||||||
|
|
||||||
|
|
||||||
SetDefDrawEnv(&draw[0], 0, SCREENYRES, SCREENXRES, SCREENYRES);
|
|
||||||
|
|
||||||
SetDefDrawEnv(&draw[1], 0, 0, SCREENXRES, SCREENYRES);
|
|
||||||
|
|
||||||
|
|
||||||
// If PAL , add 8 pix vertical offset ((256 - 240) /2)
|
|
||||||
|
|
||||||
if ( VMODE ) {
|
|
||||||
|
|
||||||
SetVideoMode(MODE_PAL);
|
|
||||||
|
|
||||||
disp[0].screen.y += 8;
|
|
||||||
|
|
||||||
disp[1].screen.y += 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set Draw area color
|
|
||||||
|
|
||||||
setRGB0(&draw[0], BGc->r, BGc->g, BGc->b);
|
|
||||||
|
|
||||||
setRGB0(&draw[1], BGc->r, BGc->g, BGc->b);
|
|
||||||
|
|
||||||
// Set Draw area clear flag
|
|
||||||
|
|
||||||
draw[0].isbg = 1;
|
|
||||||
|
|
||||||
draw[1].isbg = 1;
|
|
||||||
|
|
||||||
// Set the disp and draw env
|
|
||||||
|
|
||||||
PutDispEnv(&disp[db]);
|
|
||||||
|
|
||||||
PutDrawEnv(&draw[db]);
|
|
||||||
|
|
||||||
// Init font system
|
|
||||||
|
|
||||||
FntLoad(FNT_VRAM_X, FNT_VRAM_Y);
|
|
||||||
|
|
||||||
FntOpen( FNT_SCR_X,
|
|
||||||
|
|
||||||
FNT_SCR_Y,
|
|
||||||
|
|
||||||
FNT_SCR_W,
|
|
||||||
|
|
||||||
FNT_SCR_H,
|
|
||||||
|
|
||||||
FNT_SCR_BG,
|
|
||||||
|
|
||||||
FNT_SCR_MAX_CHAR
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
// Lighting setup
|
|
||||||
|
|
||||||
SetColorMatrix( cmat );
|
|
||||||
|
|
||||||
SetBackColor( BKc->vx, BKc->vy, BKc->vz );
|
|
||||||
|
|
||||||
SetFarColor( BGc->r, BGc->g, BGc->b );
|
|
||||||
|
|
||||||
SetFogNearFar( FOG_NEAR, FOG_FAR, SCREENXRES );
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
void ScrRst(void){
|
|
||||||
|
|
||||||
RECT scr;
|
|
||||||
|
|
||||||
VSync( 0 ); // Wait for current drawing to finish
|
|
||||||
|
|
||||||
SetDispMask( 0 ); // Set mask to not displayed
|
|
||||||
|
|
||||||
ResetGraph( 1 ); // Cancel current drawing
|
|
||||||
|
|
||||||
setRECT(&scr, 0, 0, SCREENXRES, SCREENYRES);
|
|
||||||
|
|
||||||
ClearImage(&scr, CLEAR_COLOR_R, CLEAR_COLOR_G, CLEAR_COLOR_B );
|
|
||||||
|
|
||||||
DrawSync( 0 );
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
void display(DISPENV * disp, DRAWENV * draw, u_long * otdisc, char * primbuff, char ** nextprim, char * db){
|
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/3526503/how-to-set-pointer-reference-through-a-function
|
|
||||||
|
|
||||||
DrawSync(0);
|
|
||||||
|
|
||||||
VSync(VSYNC); // Using VSync 2 insures constant framerate. 0 makes the fr polycount dependant.
|
|
||||||
|
|
||||||
ResetGraph(1);
|
|
||||||
|
|
||||||
PutDispEnv(disp);
|
|
||||||
|
|
||||||
PutDrawEnv(draw);
|
|
||||||
|
|
||||||
SetDispMask(1);
|
|
||||||
|
|
||||||
// Main OT
|
|
||||||
DrawOTag(otdisc + OT2LEN - 1);
|
|
||||||
|
|
||||||
*db = !*db;
|
|
||||||
|
|
||||||
*nextprim = primbuff;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void LvlPtrSet(LEVEL * curLevel, LEVEL * level){
|
|
||||||
|
|
||||||
curLevel->BGc = level->BGc;
|
|
||||||
|
|
||||||
curLevel->cmat = level->cmat;
|
|
||||||
|
|
||||||
curLevel->lgtmat = level->lgtmat;
|
|
||||||
|
|
||||||
curLevel->meshes = level->meshes;
|
|
||||||
|
|
||||||
curLevel->meshes_length = level->meshes_length;
|
|
||||||
|
|
||||||
curLevel->actorPtr = level->actorPtr;
|
|
||||||
|
|
||||||
curLevel->levelPtr = level->levelPtr;
|
|
||||||
|
|
||||||
curLevel->propPtr = level->propPtr;
|
|
||||||
|
|
||||||
curLevel->camPtr = level->camPtr;
|
|
||||||
|
|
||||||
curLevel->camPath = level->camPath;
|
|
||||||
|
|
||||||
curLevel->camAngles = level->camAngles;
|
|
||||||
|
|
||||||
curLevel->curNode = level->curNode; // Blank
|
|
||||||
|
|
||||||
// Move these to drawPoly()
|
|
||||||
|
|
||||||
curLevel->meshPlan = level->meshPlan;
|
|
||||||
|
|
||||||
//~ FntPrint("%x %x", curLevel->meshes, level->meshes);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
int LoadLevelCD(const char*const LevelName, u_long * LoadAddress){
|
|
||||||
|
|
||||||
int cdread = 0, cdsync = 1;
|
|
||||||
|
|
||||||
cdread = CdReadFile( (char *)(LevelName), LoadAddress, 0);
|
|
||||||
|
|
||||||
cdsync = CdReadSync(0, 0);
|
|
||||||
|
|
||||||
// return loaded size
|
|
||||||
|
|
||||||
return cdread;
|
|
||||||
};
|
|
||||||
|
|
||||||
void SwitchLevel( LEVEL * curLevel, LEVEL * loadLevel ){
|
|
||||||
|
|
||||||
//~ ScrRst();
|
|
||||||
|
|
||||||
LvlPtrSet( curLevel, loadLevel);
|
|
||||||
|
|
||||||
// Reload textures
|
|
||||||
|
|
||||||
for (int k = 0; k < *curLevel->meshes_length ; k++){
|
|
||||||
|
|
||||||
LoadTexture(curLevel->meshes[k]->tim_data, curLevel->meshes[k]->tim);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// BG texture
|
|
||||||
|
|
||||||
if (curLevel->camPtr->tim_data){
|
|
||||||
|
|
||||||
LoadTexture(curLevel->camPtr->tim_data, curLevel->camPtr->BGtim);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
void LoadTexture(u_long * tim, TIM_IMAGE * tparam){ // This part is from Lameguy64's tutorial series : lameguy64.net/svn/pstutorials/chapter1/3-textures.html login/pw: annoyingmous
|
|
||||||
|
|
||||||
OpenTIM(tim); // Open the tim binary data, feed it the address of the data in memory
|
|
||||||
|
|
||||||
ReadTIM(tparam); // This read the header of the TIM data and sets the corresponding members of the TIM_IMAGE structure
|
|
||||||
|
|
||||||
LoadImage(tparam->prect, tparam->paddr); // Transfer the data from memory to VRAM at position prect.x, prect.y
|
|
||||||
|
|
||||||
DrawSync(0); // Wait for the drawing to end
|
|
||||||
|
|
||||||
if (tparam->mode & 0x8){ // check 4th bit // If 4th bit == 1, TIM has a CLUT
|
|
||||||
|
|
||||||
LoadImage(tparam->crect, tparam->caddr); // Load it to VRAM at position crect.x, crect.y
|
|
||||||
|
|
||||||
DrawSync(0); // Wait for drawing to end
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
31
psx.h
31
psx.h
@ -1,31 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <libgte.h>
|
|
||||||
#include <libetc.h>
|
|
||||||
#include <libgpu.h>
|
|
||||||
#include <libapi.h>
|
|
||||||
#include <libcd.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include "defines.h"
|
|
||||||
#include "custom_types.h"
|
|
||||||
|
|
||||||
// PSX setup
|
|
||||||
|
|
||||||
void init(DISPENV disp[2], DRAWENV draw[2], short db, MATRIX * cmat, CVECTOR * BG, VECTOR * BK );
|
|
||||||
|
|
||||||
void ScrRst(void);
|
|
||||||
|
|
||||||
void display(DISPENV * disp, DRAWENV * draw, u_long * otdisc, char * primbuff, char ** nextprim, char * db);
|
|
||||||
|
|
||||||
// Utils
|
|
||||||
|
|
||||||
void LvlPtrSet( LEVEL * curLevel, LEVEL * level );
|
|
||||||
|
|
||||||
int LoadLevelCD(const char*const LevelName, u_long * LoadAddress);
|
|
||||||
|
|
||||||
void SwitchLevel( LEVEL * curLevel, LEVEL * loadLevel);
|
|
||||||
|
|
||||||
void LoadTexture(u_long * tim, TIM_IMAGE * tparam);
|
|
97
space.c
97
space.c
@ -1,97 +0,0 @@
|
|||||||
#include "space.h"
|
|
||||||
|
|
||||||
// From 'psyq/addons/graphics/ZIMEN/CLIP.C'
|
|
||||||
|
|
||||||
void worldToScreen( VECTOR * worldPos, VECTOR * screenPos ) {
|
|
||||||
|
|
||||||
int distToScreen; // corresponds to FOV
|
|
||||||
|
|
||||||
MATRIX curRot; // current rotation matrix
|
|
||||||
|
|
||||||
// Get current matrix and projection */
|
|
||||||
|
|
||||||
distToScreen = ReadGeomScreen();
|
|
||||||
|
|
||||||
ReadRotMatrix(&curRot);
|
|
||||||
|
|
||||||
// Get Rotation, Translation coordinates, apply perspective correction
|
|
||||||
|
|
||||||
// Muliply world coordinates vector by current rotation matrix, store in screenPos
|
|
||||||
|
|
||||||
ApplyMatrixLV(&curRot, worldPos, screenPos);
|
|
||||||
|
|
||||||
// Get world translation vectors from rot and add to screenPos vx, vy, vz
|
|
||||||
|
|
||||||
applyVector(screenPos, curRot.t[0], curRot.t[1], curRot.t[2], +=);
|
|
||||||
|
|
||||||
// Correct perspective
|
|
||||||
|
|
||||||
screenPos -> vx = screenPos -> vx * distToScreen / ( screenPos -> vz + 1 ) ; // Add 1 to avoid division by 0
|
|
||||||
|
|
||||||
screenPos -> vy = screenPos -> vy * distToScreen / ( screenPos -> vz + 1 ) ;
|
|
||||||
|
|
||||||
screenPos -> vz = distToScreen ;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
void screenToWorld( VECTOR * screenPos, VECTOR * worldPos ) {
|
|
||||||
|
|
||||||
int distToScreen; // corresponds to FOV
|
|
||||||
|
|
||||||
MATRIX curRot, invRot; // current rotation matrix, transpose matrix
|
|
||||||
|
|
||||||
VECTOR Trans; // working translation vector
|
|
||||||
|
|
||||||
// Get current matrix and projection
|
|
||||||
|
|
||||||
distToScreen = ReadGeomScreen();
|
|
||||||
|
|
||||||
ReadRotMatrix( &curRot );
|
|
||||||
|
|
||||||
PushMatrix(); // Store matrix on the stack (slow!)
|
|
||||||
|
|
||||||
//// worldTrans = invRot * (screenPos - Rot.t)
|
|
||||||
|
|
||||||
// Get world translation
|
|
||||||
|
|
||||||
Trans.vx = screenPos->vx - curRot.t[0]; // Substract world translation from screenpos
|
|
||||||
|
|
||||||
Trans.vy = screenPos->vy - curRot.t[1];
|
|
||||||
|
|
||||||
Trans.vz = screenPos->vz - curRot.t[2];
|
|
||||||
|
|
||||||
|
|
||||||
// We want the inverse of the current rotation matrix.
|
|
||||||
//
|
|
||||||
// Inverse matrix : M^-1 = 1 / detM * T(M)
|
|
||||||
// We know that the determinant of a rotation matrix is 1, thus:
|
|
||||||
// M^-1 = T(M)
|
|
||||||
//
|
|
||||||
// Get transpose of current rotation matrix
|
|
||||||
// > The transpose of a matrix is a new matrix whose rows are the columns of the original.
|
|
||||||
// https://www.quora.com/What-is-the-geometric-interpretation-of-the-transpose-of-a-matrix
|
|
||||||
|
|
||||||
TransposeMatrix( &curRot, &invRot );
|
|
||||||
|
|
||||||
// Multiply the transpose of current rotation matrix by the current translation vector
|
|
||||||
|
|
||||||
ApplyMatrixLV( &invRot, &Trans, worldPos );
|
|
||||||
|
|
||||||
// Get original rotation matrix back
|
|
||||||
|
|
||||||
PopMatrix();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
int cliptest3( short *v1 ) {
|
|
||||||
|
|
||||||
if( v1[0]<0 && v1[2]<0 && v1[4]<0 ) return 0;
|
|
||||||
|
|
||||||
if( v1[1]<0 && v1[3]<0 && v1[5]<0 ) return 0;
|
|
||||||
|
|
||||||
if( v1[0] > SCREENXRES && v1[2] > SCREENXRES && v1[4] > SCREENXRES) return 0;
|
|
||||||
|
|
||||||
if( v1[1] > SCREENYRES && v1[3] > SCREENYRES && v1[5] > SCREENYRES) return 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user