1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-04 20:27:39 +02:00

#3 add water surface states, fix moving speed while roll, #4 add controller height for collisions, #8 add camera rotation (right mouse button), #10 add color dodge for caustics, #15 fix mouse buttons check for Windows, change canvas size of 1280x720 for HTML5

This commit is contained in:
XProger
2016-09-13 00:46:24 +03:00
parent e47f8c5fd7
commit dbd2a45bed
10 changed files with 319 additions and 153 deletions

Binary file not shown.

View File

@@ -137,7 +137,7 @@ struct Camera : Controller {
Frustum *frustum; Frustum *frustum;
float fov, znear, zfar; float fov, znear, zfar;
vec3 target, destPos, lastDest; vec3 target, destPos, lastDest, angleAdv;
int room; int room;
@@ -145,18 +145,18 @@ struct Camera : Controller {
fov = 75.0f; fov = 75.0f;
znear = 0.1f * 2048.0f; znear = 0.1f * 2048.0f;
zfar = 1000.0f * 2048.0f; zfar = 1000.0f * 2048.0f;
angle.y += PI; angleAdv = vec3(0.0f);
room = owner->getEntity().room; room = owner->getEntity().room;
pos = pos - getDir() * 1024.0f; pos = pos - owner->getDir() * 1024.0f;
} }
~Camera() { ~Camera() {
delete frustum; delete frustum;
} }
virtual TR::Room& getRoom() const { virtual int getRoomIndex() const {
return level->rooms[room]; return room;
} }
virtual void update() { virtual void update() {
@@ -170,24 +170,33 @@ struct Camera : Controller {
if (Input::down[ikA]) v = v - dir.cross(vec3(0, 1, 0)); if (Input::down[ikA]) v = v - dir.cross(vec3(0, 1, 0));
pos = pos + v.normal() * (Core::deltaTime * 2048.0f); pos = pos + v.normal() * (Core::deltaTime * 2048.0f);
#endif #endif
if (Input::down[ikMouseL]) { if (Input::down[ikMouseR]) {
vec2 delta = Input::mouse.pos - Input::mouse.start.L; vec2 delta = Input::mouse.pos - Input::mouse.start.L;
angle.x += delta.y * 0.01f; angleAdv.x += delta.y * 0.01f;
// angle.y -= delta.x * 0.01f; angleAdv.y += delta.x * 0.01f;
Input::mouse.start.L = Input::mouse.pos; Input::mouse.start.L = Input::mouse.pos;
} }
angle.y = PI - owner->angle.y; float height = 0.0f;
switch (owner->stand) {
case Controller::STAND_AIR :
case Controller::STAND_GROUND :
height = 768.0f;
break;
case Controller::STAND_UNDERWATER :
case Controller::STAND_ONWATER :
height = 256.0f;
break;
}
angle = owner->angle + angleAdv;
angle.z = 0.0f; angle.z = 0.0f;
//angle.x = min(max(angle.x, -80 * DEG2RAD), 80 * DEG2RAD);
angle.x = min(max(angle.x, -80 * DEG2RAD), 80 * DEG2RAD);
vec3 dir = getDir();
float height = owner->stand == Controller::STAND_UNDERWATER ? 256.0f : 768.0f;
target = vec3(owner->pos.x, owner->pos.y - height, owner->pos.z); target = vec3(owner->pos.x, owner->pos.y - height, owner->pos.z);
vec3 dir = getDir();
if (owner->state != Lara::STATE_BACK_JUMP) { if (owner->state != Lara::STATE_BACK_JUMP) {
destPos = target - dir * 1024.0f; destPos = target - dir * 1024.0f;
lastDest = destPos; lastDest = destPos;

View File

@@ -80,14 +80,19 @@ struct Controller {
return level->models[0]; return level->models[0];
} }
virtual TR::Room& getRoom() const { TR::Room& getRoom() const {
int index = getEntity().room; int index = getRoomIndex();
ASSERT(index >= 0 && index < level->roomsCount); ASSERT(index >= 0 && index < level->roomsCount);
return level->rooms[index]; return level->rooms[index];
} }
TR::Room::Sector& getSector(int x, int z, int &dx, int &dz) const { virtual int getRoomIndex() const {
TR::Room &room = getRoom(); return getEntity().room;
}
TR::Room::Sector& getSector(int roomIndex, int x, int z, int &dx, int &dz) const {
ASSERT(roomIndex >= 0 && roomIndex < level->roomsCount);
TR::Room &room = level->rooms[roomIndex];
int sx = x - room.info.x; int sx = x - room.info.x;
int sz = z - room.info.z; int sz = z - room.info.z;
@@ -105,7 +110,7 @@ struct Controller {
TR::Room::Sector& getSector(int &dx, int &dz) const { TR::Room::Sector& getSector(int &dx, int &dz) const {
TR::Entity &entity = getEntity(); TR::Entity &entity = getEntity();
return getSector(entity.x, entity.z, dx, dz); return getSector(entity.room, entity.x, entity.z, dx, dz);
} }
int setAnimation(int index, int frame = -1) { int setAnimation(int index, int frame = -1) {
@@ -145,7 +150,7 @@ struct Controller {
int getOverlap(int fromX, int fromY, int fromZ, int toX, int toZ, int &delta) const { int getOverlap(int fromX, int fromY, int fromZ, int toX, int toZ, int &delta) const {
int dx, dz; int dx, dz;
TR::Room::Sector &s = getSector(fromX, fromZ, dx, dz); TR::Room::Sector &s = getSector(getEntity().room, fromX, fromZ, dx, dz);
if (s.boxIndex == 0xFFFF) return NO_OVERLAP; if (s.boxIndex == 0xFFFF) return NO_OVERLAP;
@@ -162,7 +167,7 @@ struct Controller {
do { do {
TR::Box &ob = level->boxes[o->boxIndex]; TR::Box &ob = level->boxes[o->boxIndex];
if (ob.contains(toX, toZ)) { // get min delta if (ob.contains(toX, toZ)) { // get min delta
int d = abs(ob.floor - b.floor); int d = abs(ob.floor - fromY);
if (d < delta) { if (d < delta) {
floor = ob.floor; floor = ob.floor;
delta = d; delta = d;
@@ -177,11 +182,16 @@ struct Controller {
struct FloorInfo { struct FloorInfo {
int floor, ceiling; int floor, ceiling;
int roomNext, roomBelow, roomAbove; int roomNext, roomBelow, roomAbove;
int floorIndex;
}; };
FloorInfo getFloorInfo(int x, int z) { FloorInfo getFloorInfo(int x, int z) {
return getFloorInfo(getRoomIndex(), x, z);
}
FloorInfo getFloorInfo(int roomIndex, int x, int z) {
int dx, dz; int dx, dz;
TR::Room::Sector &s = getSector(x, z, dx, dz); TR::Room::Sector &s = getSector(roomIndex, x, z, dx, dz);
FloorInfo info; FloorInfo info;
info.floor = 256 * (int)s.floor; info.floor = 256 * (int)s.floor;
@@ -189,6 +199,7 @@ struct Controller {
info.roomNext = 255; info.roomNext = 255;
info.roomBelow = s.roomBelow; info.roomBelow = s.roomBelow;
info.roomAbove = s.roomAbove; info.roomAbove = s.roomAbove;
info.floorIndex = s.floorIndex;
if (!s.floorIndex) return info; if (!s.floorIndex) return info;
@@ -282,7 +293,22 @@ struct Controller {
} }
vec3 getDir() const { vec3 getDir() const {
return vec3(sinf(PI - angle.y) * cosf(-angle.x), -sinf(-angle.x), cosf(PI - angle.y) * cosf(-angle.x)); return vec3(angle.x, angle.y);
}
void turnToWall() {
float fx = pos.x / 1024.0f;
float fz = pos.z / 1024.0f;
fx -= (int)fx;
fz -= (int)fz;
float k;
if (fx > 1.0f - fz)
k = fx < fz ? 0 : 1;
else
k = fx < fz ? 3 : 2;
angle.y = k * PI * 0.5f; // clamp angle to n*PI/2
} }
void collide() { void collide() {
@@ -290,14 +316,6 @@ struct Controller {
FloorInfo info = getFloorInfo(entity.x, entity.z); FloorInfo info = getFloorInfo(entity.x, entity.z);
/*
float hmin = 0.0f, hmax = -768.0f;
if (inWater) {
hmin = 256.0f + 128.0f;
hmax = -256.0f - 128.0f;
}
*/
if (info.roomNext != 0xFF) if (info.roomNext != 0xFF)
entity.room = info.roomNext; entity.room = info.roomNext;
@@ -310,37 +328,27 @@ struct Controller {
entity.room = info.roomBelow; entity.room = info.roomBelow;
} }
if (entity.y <= info.ceiling) { int height = getHeight();
if (entity.y - getHeight() < info.ceiling) {
if (info.roomAbove == 0xFF) { if (info.roomAbove == 0xFF) {
entity.y = info.ceiling; pos.y = entity.y = info.ceiling + height;
pos.y = entity.y; velocity.y = fabsf(velocity.y);
velocity.y = -velocity.y; } else {
if (stand == STAND_UNDERWATER && !(level->rooms[info.roomAbove].flags & TR::ROOM_FLAG_WATER)) {
stand = STAND_ONWATER;
velocity.y = 0;
pos.y = info.ceiling;
} else } else
if (stand != STAND_ONWATER && entity.y < info.ceiling)
entity.room = info.roomAbove; entity.room = info.roomAbove;
} }
/*
if (pos.y + hmin >= floor) {
if (s.roomBelow == 0xFF) {
pos.y = floor - hmin;
velocity.y = 0.0f;
} else
entity.room = s.roomBelow;
} }
if (pos.y + hmax <= ceiling) {
if (s.roomAbove == 0xFF) {
pos.y = ceiling - hmax;
velocity.y = -velocity.y;
} else
entity.room = s.roomAbove;
}
*/
} }
virtual void updateVelocity() {} virtual void updateVelocity() {}
virtual void move() {} virtual void move() {}
virtual Stand getStand() { return STAND_AIR; } virtual Stand getStand() { return STAND_AIR; }
virtual int getHeight() { return 0; }
virtual int getStateAir() { return state; } virtual int getStateAir() { return state; }
virtual int getStateGround() { return state; } virtual int getStateGround() { return state; }
virtual int getStateUnderwater() { return state; } virtual int getStateUnderwater() { return state; }
@@ -389,14 +397,18 @@ struct Controller {
for (int i = 0; i < anim->acCount; i++) { for (int i = 0; i < anim->acCount; i++) {
int cmd = *ptr++; int cmd = *ptr++;
switch (cmd) { switch (cmd) {
case 0x01 : { // cmd position case TR::ANIM_CMD_MOVE : { // cmd position
int16 sx = *ptr++; int16 sx = *ptr++;
int16 sy = *ptr++; int16 sy = *ptr++;
int16 sz = *ptr++; int16 sz = *ptr++;
if (endFrame) {
pos = pos + vec3(sx, sy, sz).rotateY(angle.y);
updateEntity();
LOG("move: %d %d %d\n", (int)sx, (int)sy, (int)sz); LOG("move: %d %d %d\n", (int)sx, (int)sy, (int)sz);
}
break; break;
} }
case 0x02 : { // cmd jump speed case TR::ANIM_CMD_SPEED : { // cmd jump speed
int16 sy = *ptr++; int16 sy = *ptr++;
int16 sz = *ptr++; int16 sz = *ptr++;
if (endFrame) { if (endFrame) {
@@ -404,16 +416,15 @@ struct Controller {
velocity.x = sinf(angleExt) * sz; velocity.x = sinf(angleExt) * sz;
velocity.y = sy; velocity.y = sy;
velocity.z = cosf(angleExt) * sz; velocity.z = cosf(angleExt) * sz;
LOG("speed: %f\n", velocity.length());
stand = STAND_AIR; stand = STAND_AIR;
} }
break; break;
} }
case 0x03 : // empty hands case TR::ANIM_CMD_EMPTY : // empty hands
break; break;
case 0x04 : // kill case TR::ANIM_CMD_KILL : // kill
break; break;
case 0x05 : { // play sound case TR::ANIM_CMD_SOUND : { // play sound
int frame = (*ptr++); int frame = (*ptr++);
int id = (*ptr++) & 0x3FFF; int id = (*ptr++) & 0x3FFF;
int idx = frame - anim->frameStart; int idx = frame - anim->frameStart;
@@ -424,10 +435,14 @@ struct Controller {
} }
break; break;
} }
case 0x06 : // effect case TR::ANIM_CMD_SPECIAL : // special commands
if (frameIndex != animPrevFrame && frameIndex + anim->frameStart == ptr[0]) { if (frameIndex != animPrevFrame && frameIndex + anim->frameStart == ptr[0]) {
if (ptr[1] == 0) // rolling switch (ptr[1]) {
angle.y = angle.y + PI; case TR::ANIM_CMD_SPECIAL_FLIP : angle.y = angle.y + PI; break;
case TR::ANIM_CMD_SPECIAL_BUBBLE : /* playSound(TR::SND_BUBBLE); */ break;
case TR::ANIM_CMD_SPECIAL_CTRL : LOG("water out ?\n"); break;
default : LOG("unknown special cmd %d\n", (int)ptr[1]);
}
} }
ptr += 2; ptr += 2;
break; break;

View File

@@ -321,7 +321,7 @@ namespace Debug {
for (int z = 0; z < room.zSectors; z++) for (int z = 0; z < room.zSectors; z++)
for (int x = 0; x < room.xSectors; x++) { for (int x = 0; x < room.xSectors; x++) {
auto &s = room.sectors[x * room.zSectors + z]; TR::Room::Sector &s = room.sectors[x * room.zSectors + z];
float floor = s.floor * 256; float floor = s.floor * 256;
/* /*
if (s.boxIndex < 0xFFFF) { if (s.boxIndex < 0xFFFF) {

View File

@@ -20,6 +20,25 @@ namespace TR {
FD_KILL = 5, FD_KILL = 5,
}; };
enum {
ANIM_CMD_MOVE = 1,
ANIM_CMD_SPEED = 2,
ANIM_CMD_EMPTY = 3,
ANIM_CMD_KILL = 4,
ANIM_CMD_SOUND = 5,
ANIM_CMD_SPECIAL = 6,
};
enum {
ANIM_CMD_SPECIAL_FLIP = 0,
ANIM_CMD_SPECIAL_BUBBLE = 3,
ANIM_CMD_SPECIAL_CTRL = 12,
};
enum {
SND_BUBBLE = 37,
};
#define DATA_PORTAL 0x01 #define DATA_PORTAL 0x01
#define DATA_FLOOR 0x02 #define DATA_FLOOR 0x02
#define DATA_CEILING 0x03 #define DATA_CEILING 0x03
@@ -30,6 +49,7 @@ namespace TR {
#define ENTITY_FLAG_MASK 0x3E00 #define ENTITY_FLAG_MASK 0x3E00
#define ENTITY_LARA 0 #define ENTITY_LARA 0
#define ENTITY_LARA_CUT 77
#define ENTITY_ENEMY_TWIN 6 #define ENTITY_ENEMY_TWIN 6
#define ENTITY_ENEMY_WOLF 7 #define ENTITY_ENEMY_WOLF 7

View File

@@ -24,7 +24,14 @@ struct Lara : Controller {
ANIM_SMASH_RUN_LEFT = 53, ANIM_SMASH_RUN_LEFT = 53,
ANIM_SMASH_RUN_RIGHT = 54, ANIM_SMASH_RUN_RIGHT = 54,
ANIM_WATER_FALL = 112, ANIM_WATER_FALL = 112,
ANIM_STAND_ROLL = 146, ANIM_TO_ONWATER = 114,
ANIM_STAND_ROLL_BEGIN = 146,
ANIM_STAND_ROLL_END = 147,
ANIM_TO_UNDERWATER = 119,
ANIM_HIT_FRONT = 125,
ANIM_HIT_BACK = 126,
ANIM_HIT_LEFT = 127,
ANIM_HIT_RIGHT = 128,
}; };
// http://www.tombraiderforums.com/showthread.php?t=211681 // http://www.tombraiderforums.com/showthread.php?t=211681
@@ -112,13 +119,42 @@ struct Lara : Controller {
angle = vec3(0.0f, PI, 0.0f); angle = vec3(0.0f, PI, 0.0f);
getEntity().room = 14; getEntity().room = 14;
*/ */
// updateEntity();
} }
bool isMovingState(int state) { bool isMovingState(int state) {
return state == STATE_RUN || state == STATE_WALK || state == STATE_STEP_LEFT || state == STATE_STEP_RIGHT; return state == STATE_RUN || state == STATE_FAST_BACK || state == STATE_ROLL || state == STATE_WALK || state == STATE_STEP_LEFT || state == STATE_STEP_RIGHT;
}
bool waterOut(int &outState) {
vec3 dst = pos + getDir() * 32.0f;
FloorInfo infoCur = getFloorInfo((int)pos.x, (int)pos.z),
infoDst = getFloorInfo(infoCur.roomAbove, (int)dst.x, (int)dst.z);
if (infoDst.roomBelow == 0xFF && pos.y - infoDst.floor <= 256) { // possibility check
if (!setState(STATE_STOP)) { // can't set water out state
outState = STATE_STOP;
return true;
}
outState = state;
turnToWall();
dst.y -= pos.y - infoDst.floor;
pos = dst; // set new position
getEntity().room = infoCur.roomAbove;
updateEntity();
return true;
}
return false;
} }
virtual Stand getStand() { virtual Stand getStand() {
if (stand == STAND_ONWATER && state != STATE_DIVE && state != STATE_STOP)
return stand;
if (getRoom().flags & TR::ROOM_FLAG_WATER) if (getRoom().flags & TR::ROOM_FLAG_WATER)
return STAND_UNDERWATER; // TODO: ONWATER return STAND_UNDERWATER; // TODO: ONWATER
@@ -132,6 +168,12 @@ struct Lara : Controller {
return STAND_AIR; return STAND_AIR;
} }
virtual int getHeight() {
if (stand == STAND_GROUND || stand == STAND_AIR)
return 768;
return 0;
}
virtual int getStateAir() { virtual int getStateAir() {
angle.x = 0.0f; angle.x = 0.0f;
@@ -147,9 +189,20 @@ struct Lara : Controller {
virtual int getStateGround() { virtual int getStateGround() {
angle.x = 0.0f; angle.x = 0.0f;
/*
// hit test
if (animIndex != ANIM_HIT_FRONT)
for (int i = 0; i < level->entitiesCount; i++) {
TR::Entity &e = level->entities[i];
if (e.id != ENTITY_ENEMY_WOLF) continue;
vec3 v = vec3(e.x, e.y, e.z) - pos;
if (v.length2() < 128 * 128) {
return setAnimation(ANIM_HIT_FRONT);
}
}
*/
if ( (mask & (FORTH | BACK)) == (FORTH | BACK) && (state == STATE_STOP || state == STATE_RUN) ) if ( (mask & (FORTH | BACK)) == (FORTH | BACK) && (state == STATE_STOP || state == STATE_RUN) )
return setAnimation(ANIM_STAND_ROLL); return setAnimation(ANIM_STAND_ROLL_BEGIN);
// ready to jump // ready to jump
if (state == STATE_COMPRESS) { if (state == STATE_COMPRESS) {
@@ -201,6 +254,28 @@ struct Lara : Controller {
virtual int getStateOnwater() { virtual int getStateOnwater() {
angle.x = 0.0f; angle.x = 0.0f;
if (state == STATE_WATER_OUT) return state;
if (state != STATE_SURF_TREAD && state != STATE_SURF_LEFT && state != STATE_SURF_RIGHT && state != STATE_SURF_SWIM && state != STATE_SURF_BACK && state != STATE_STOP)
return setAnimation(ANIM_TO_ONWATER);
if (mask & FORTH) {
if (mask & JUMP) {
angle.x = -PI * 0.25f;
return setAnimation(ANIM_TO_UNDERWATER);
}
if ((mask & ACTION) && waterOut(state)) return state;
return STATE_SURF_SWIM;
}
if (mask & BACK) return STATE_SURF_BACK;
if (mask & WALK) {
if (mask & LEFT) return STATE_SURF_LEFT;
if (mask & RIGHT) return STATE_SURF_RIGHT;
}
return STATE_SURF_TREAD; return STATE_SURF_TREAD;
} }
@@ -244,21 +319,24 @@ struct Lara : Controller {
if (Input::down[ikEnter]) { if (Input::down[ikEnter]) {
if (!lState) { if (!lState) {
lState = true; lState = true;
static int snd_id = 0; static int snd_id = 0;//160;
playSound(snd_id); playSound(snd_id);
// setAnimation(snd_id);
LOG("sound: %d\n", snd_id++); LOG("sound: %d\n", snd_id++);
}
/*
LOG("state: %d\n", anim->state); LOG("state: %d\n", anim->state);
for (int i = 0; i < anim->scCount; i++) { for (int i = 0; i < anim->scCount; i++) {
auto &sc = level->states[anim->scOffset + i]; auto &sc = level->states[anim->scOffset + i];
LOG("-> %d : ", (int)sc.state); LOG("-> %d : ", (int)sc.state);
for (int j = 0; j < sc.rangesCount; j++) { for (int j = 0; j < sc.rangesCount; j++) {
AnimRange &range = level->ranges[sc.rangesOffset + j]; TR::AnimRange &range = level->ranges[sc.rangesOffset + j];
LOG("%d ", range.nextAnimation); LOG("%d ", range.nextAnimation);
} }
LOG("\n"); LOG("\n");
}*/ }
}
} else } else
lState = false; lState = false;
#endif #endif
@@ -281,7 +359,7 @@ struct Lara : Controller {
if (state == STATE_SWIM || state == STATE_GLIDE) if (state == STATE_SWIM || state == STATE_GLIDE)
w = TURN_WATER_FAST; w = TURN_WATER_FAST;
else if (state == STATE_TREAD) else if (state == STATE_TREAD || state == STATE_SURF_TREAD || state == STATE_SURF_SWIM || state == STATE_SURF_BACK)
w = TURN_WATER_SLOW; w = TURN_WATER_SLOW;
else if (state == STATE_RUN || state == STATE_FAST_TURN) else if (state == STATE_RUN || state == STATE_FAST_TURN)
w = TURN_FAST; w = TURN_FAST;
@@ -308,16 +386,19 @@ struct Lara : Controller {
angleExt = angle.y; angleExt = angle.y;
switch (state) { switch (state) {
case STATE_BACK : case STATE_BACK :
case STATE_SURF_BACK :
case STATE_BACK_JUMP : case STATE_BACK_JUMP :
case STATE_FAST_BACK : case STATE_FAST_BACK :
angleExt += PI; angleExt += PI;
break; break;
case STATE_STEP_LEFT :
case STATE_LEFT_JUMP : case STATE_LEFT_JUMP :
case STATE_STEP_LEFT :
case STATE_SURF_LEFT :
angleExt -= PI * 0.5f; angleExt -= PI * 0.5f;
break; break;
case STATE_STEP_RIGHT :
case STATE_RIGHT_JUMP : case STATE_RIGHT_JUMP :
case STATE_STEP_RIGHT :
case STATE_SURF_RIGHT :
angleExt += PI * 0.5f; angleExt += PI * 0.5f;
break; break;
} }
@@ -327,74 +408,115 @@ struct Lara : Controller {
// calculate moving speed // calculate moving speed
float dt = Core::deltaTime * 30.0f; float dt = Core::deltaTime * 30.0f;
if (stand == STAND_AIR) {
velocity.y += GRAVITY * dt;
} else if (stand == STAND_ONWATER) {
} else if (stand == STAND_UNDERWATER) {
if (state == STATE_SWIM)
velocity = vec3(angle.x, angle.y) * 35.0f;
else
velocity = velocity - velocity * min(1.0f, Core::deltaTime * 2.0f);
// TODO: apply flow velocity
} else if (stand == STAND_GROUND) {
TR::Animation *anim = &level->anims[animIndex]; TR::Animation *anim = &level->anims[animIndex];
float speed = anim->speed + anim->accel * (animTime * 30.0f); //if (anim->speed != 0.0f || anim->accel != 0.0f)
// LOG("speed: %f accel: %f\n", (float)anim->speed, (float)anim->accel);
switch (stand) {
case STAND_AIR :
velocity.y += GRAVITY * dt;
break;
case STAND_GROUND :
case STAND_ONWATER : {
float speed = 0.0f;
switch (state) {
case STATE_SURF_SWIM :
case STATE_SURF_BACK :
case STATE_SURF_LEFT :
case STATE_SURF_RIGHT :
speed = 15.0f;
break;
default :
speed = anim->speed + anim->accel * (animTime * 30.0f);
if (animIndex == ANIM_STAND_ROLL_END)
speed = -speed;
}
velocity.x = sinf(angleExt) * speed; velocity.x = sinf(angleExt) * speed;
velocity.z = cosf(angleExt) * speed; velocity.z = cosf(angleExt) * speed;
if (stand == STAND_GROUND)
velocity.y += GRAVITY * dt; velocity.y += GRAVITY * dt;
else
velocity.y = 0.0f;
break;
}
case STAND_UNDERWATER : {
float speed = 0.0f;
if (animIndex == ANIM_TO_UNDERWATER)
speed = 15.0f;
if (state == STATE_SWIM)
speed = 35.0f;
if (speed != 0.0f)
velocity = vec3(angle.x, angle.y) * speed;
else
velocity = velocity - velocity * min(1.0f, Core::deltaTime * 2.0f);
// TODO: apply flow velocity
break;
}
} }
} }
virtual void move() { virtual void move() { // TORO: as part of Controller
if (velocity.length() < EPS) return;
vec3 offset = velocity * Core::deltaTime * 30.0f; vec3 offset = velocity * Core::deltaTime * 30.0f;
vec3 p = pos; vec3 p = pos;
pos = pos + offset; pos = pos + offset;
FloorInfo info = getFloorInfo((int)pos.x, (int)pos.z);
int delta; int delta;
int d = getOverlap((int)p.x, (int)p.y, (int)p.z, (int)pos.x, (int)pos.z, delta); int d = getOverlap((int)p.x, (int)p.y, (int)p.z, (int)pos.x, (int)pos.z, delta);
int state = level->anims[animIndex].state; int height = getHeight();
bool stop = false; bool canPassGap;
if ((d == NO_OVERLAP) || switch (stand) {
((state == STATE_WALK || state == STATE_BACK || state == STATE_STEP_LEFT || state == STATE_STEP_RIGHT) && delta > 256) /*|| case STAND_AIR :
(delta < -256) */) { canPassGap = ((int)p.y - d) <= 512 && (pos.y - height - info.ceiling > -256);
break;
pos = p; case STAND_UNDERWATER :
canPassGap = ((int)p.y - d) < 128;
TR::Animation *anim = &level->anims[animIndex]; break;
case STAND_ONWATER : {
// smashes canPassGap = info.roomAbove != 0xFF;
if (stand == STAND_GROUND) { // onGround break;
if (d >= 256 * 4 && anim->state == STATE_RUN) }
setAnimation(ANIM_SMASH_RUN_LEFT); // TODO: RIGHT default : // TODO: height
if (state == STATE_WALK || state == STATE_BACK || state == STATE_STEP_LEFT || state == STATE_STEP_RIGHT)
canPassGap = delta <= 256;
else else
setAnimation(ANIM_STAND); canPassGap = delta >= -256 - 16;
}
velocity.x = velocity.z = 0.0f; if (d == NO_OVERLAP || !canPassGap) {
} else if (stand == STAND_UNDERWATER) { // in water pos = p; // TODO: use smart ejection
// do nothing
//velocity.x = velocity.z = 0.0f; // hit the wall
} else { // in the air switch (stand) {
case STAND_AIR :
setAnimation(ANIM_SMASH_JUMP); setAnimation(ANIM_SMASH_JUMP);
velocity.x = -velocity.x * 0.5f; velocity.x = -velocity.x * 0.5f;
velocity.z = -velocity.z * 0.5f; velocity.z = -velocity.z * 0.5f;
velocity.y = 0.0f; velocity.y = 0.0f;
break;
case STAND_GROUND :
if (delta >= 256 * 4 && state == STATE_RUN)
setAnimation(ANIM_SMASH_RUN_LEFT); // TODO: RIGHT
else
setAnimation(ANIM_STAND);
velocity.x = velocity.z = 0.0f;
break;
case STAND_UNDERWATER :
case STAND_ONWATER :
break;
} }
} else
} else { updateEntity();
TR::Entity &entity = getEntity();
entity.x = (int)pos.x;
entity.y = (int)pos.y;
entity.z = (int)pos.z;
}
} }
}; };

View File

@@ -29,7 +29,7 @@ struct Level {
float time; float time;
Level(Stream &stream) : level{stream}, time(0.0f) { Level(Stream &stream) : level{stream}, time(0.0f), lara(NULL) {
#ifdef _DEBUG #ifdef _DEBUG
Debug::init(); Debug::init();
#endif #endif
@@ -43,6 +43,7 @@ struct Level {
TR::Entity &entity = level.entities[i]; TR::Entity &entity = level.entities[i];
switch (entity.id) { switch (entity.id) {
case ENTITY_LARA : case ENTITY_LARA :
case ENTITY_LARA_CUT :
entity.controller = (lara = new Lara(&level, i)); entity.controller = (lara = new Lara(&level, i));
break; break;
case ENTITY_ENEMY_WOLF : case ENTITY_ENEMY_WOLF :
@@ -354,7 +355,6 @@ struct Level {
int fSize = sizeof(TR::AnimFrame) + model.mCount * sizeof(uint16) * 2; int fSize = sizeof(TR::AnimFrame) + model.mCount * sizeof(uint16) * 2;
k = k - fIndex; k = k - fIndex;
int fIndexA = fIndex % fCount, fIndexB = (fIndex + 1) % fCount; int fIndexA = fIndex % fCount, fIndexB = (fIndex + 1) % fCount;
TR::AnimFrame *frameA = (TR::AnimFrame*)&level.frameData[(anim->frameOffset + fIndexA * fSize) >> 1]; TR::AnimFrame *frameA = (TR::AnimFrame*)&level.frameData[(anim->frameOffset + fIndexA * fSize) >> 1];

View File

@@ -36,7 +36,7 @@ varying vec4 vColor;
#ifdef CAUSTICS #ifdef CAUSTICS
float sum = coord.x + coord.y + coord.z; float sum = coord.x + coord.y + coord.z;
vColor.xyz *= abs(sin(sum / 512.0 + uParam.x)) * 0.75 + 0.25; vColor.xyz *= abs(sin(sum / 512.0 + uParam.x)) * 1.5 + 0.5; // color dodge
#endif #endif
#ifndef SPRITE #ifndef SPRITE

View File

@@ -163,7 +163,7 @@ EM_BOOL mouseCallback(int eventType, const EmscriptenMouseEvent *e, void *userDa
int main() { int main() {
initGL(); initGL();
emscripten_set_canvas_size(Core::width = 800, Core::height = 600); emscripten_set_canvas_size(Core::width = 1280, Core::height = 720);
emscripten_set_keydown_callback(0, 0, 1, keyCallback); emscripten_set_keydown_callback(0, 0, 1, keyCallback);
emscripten_set_keyup_callback(0, 0, 1, keyCallback); emscripten_set_keyup_callback(0, 0, 1, keyCallback);

View File

@@ -31,8 +31,8 @@ InputKey keyToInputKey(int code) {
} }
InputKey mouseToInputKey(int msg) { InputKey mouseToInputKey(int msg) {
return (msg >= WM_LBUTTONDOWN || msg <= WM_LBUTTONDBLCLK) ? ikMouseL : return (msg >= WM_LBUTTONDOWN && msg <= WM_LBUTTONDBLCLK) ? ikMouseL :
(msg >= WM_RBUTTONDOWN || msg <= WM_RBUTTONDBLCLK) ? ikMouseR : ikMouseM; (msg >= WM_RBUTTONDOWN && msg <= WM_RBUTTONDBLCLK) ? ikMouseR : ikMouseM;
} }
#define JOY_DEAD_ZONE_STICK 0.3f #define JOY_DEAD_ZONE_STICK 0.3f