Roll sky by camera
This commit is contained in:
parent
e21d5b7825
commit
84163d0d3c
4 changed files with 60 additions and 36 deletions
|
@ -12,6 +12,9 @@
|
|||
#define LCR_FREE_CAMERA_STEP \
|
||||
(LCR_SETTING_FREE_CAMERA_SPEED / LCR_SETTING_FPS)
|
||||
|
||||
#define LCR_FREE_CAMERA_TURN_STEP \
|
||||
(LCR_SETTING_FREE_CAMERA_TURN_SPEED / LCR_SETTING_FPS)
|
||||
|
||||
/** Maximum number of triangles of a block shape. */
|
||||
#define LCR_MAP_BLOCK_SHAPE_MAX_TRIANGLES 32
|
||||
|
||||
|
|
21
game.h
21
game.h
|
@ -132,9 +132,18 @@ uint8_t LCR_gameStep(uint32_t time)
|
|||
|
||||
if (time >= LCR_nextRenderFrameTime)
|
||||
{
|
||||
LCR_drawBackground(0);
|
||||
LCR_drawSkyStrip(0,0); // TODO: do this AFTER 3D rendering
|
||||
int skyOffsetV = LCR_EFFECTIVE_RESOLUTION_Y / 2 +
|
||||
((LCR_EFFECTIVE_RESOLUTION_Y / 2) *
|
||||
LCR_rendererGetCameraPitch()) /
|
||||
(LCR_SQUARE_SIDE_LEN / LCR_SETTING_SKY_ROLL_MULTIPLIER_V);
|
||||
|
||||
int skyOffsetH = LCR_SKY_IMAGE_SIZE - 1 -
|
||||
(LCR_rendererGetCameraYaw() * LCR_SKY_IMAGE_SIZE) /
|
||||
(LCR_SQUARE_SIDE_LEN / LCR_SETTING_SKY_ROLL_MULTIPLIER_H);
|
||||
|
||||
LCR_drawBackground(skyOffsetV);
|
||||
LCR_rendererDraw();
|
||||
LCR_drawSkyStrip(skyOffsetV,skyOffsetH);
|
||||
|
||||
LCR_nextRenderFrameTime += 1000 / LCR_SETTING_FPS;
|
||||
|
||||
|
@ -146,14 +155,14 @@ uint8_t LCR_gameStep(uint32_t time)
|
|||
if (_LCR_keyStates[LCR_KEY_A])
|
||||
{
|
||||
if (_LCR_keyStates[LCR_KEY_UP])
|
||||
offsets[4] = 4;
|
||||
offsets[4] = LCR_FREE_CAMERA_TURN_STEP;
|
||||
else if (_LCR_keyStates[LCR_KEY_DOWN])
|
||||
offsets[4] -= 4;
|
||||
offsets[4] -= LCR_FREE_CAMERA_TURN_STEP;
|
||||
|
||||
if (_LCR_keyStates[LCR_KEY_RIGHT])
|
||||
offsets[3] -= 4;
|
||||
offsets[3] -= LCR_FREE_CAMERA_TURN_STEP;
|
||||
else if (_LCR_keyStates[LCR_KEY_LEFT])
|
||||
offsets[3] = 4;
|
||||
offsets[3] = LCR_FREE_CAMERA_TURN_STEP;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
60
renderer.h
60
renderer.h
|
@ -9,6 +9,8 @@
|
|||
#define S3L_RESOLUTION_Y LCR_SETTING_RESOLUTION_Y
|
||||
#define S3L_PIXEL_FUNCTION LCR_pixelFunc3D
|
||||
|
||||
#define S3L_Z_BUFFER 2
|
||||
|
||||
#include "small3dlib.h"
|
||||
|
||||
struct LCR_Renderer
|
||||
|
@ -35,17 +37,17 @@ uint8_t LCR_buildMapModel(void)
|
|||
{
|
||||
// TODO
|
||||
|
||||
LCR_vertices3D[0] = -400;
|
||||
LCR_vertices3D[0] = -2000;
|
||||
LCR_vertices3D[1] = -100;
|
||||
LCR_vertices3D[2] = 1000;
|
||||
|
||||
LCR_vertices3D[3] = 400;
|
||||
LCR_vertices3D[4] = -100;
|
||||
LCR_vertices3D[5] = 1000;
|
||||
LCR_vertices3D[5] = 2000;
|
||||
|
||||
LCR_vertices3D[6] = 0;
|
||||
LCR_vertices3D[7] = 400;
|
||||
LCR_vertices3D[8] = 1000;
|
||||
LCR_vertices3D[8] = 2000;
|
||||
|
||||
LCR_triangles3D[0] = 0;
|
||||
LCR_triangles3D[1] = 1;
|
||||
|
@ -90,29 +92,13 @@ void LCR_rendererMoveCamera(LCR_SpaceUnit forwRightUpOffset[3],
|
|||
|
||||
LCR_scene3D.camera.transform.rotation.x +=
|
||||
(yawPitchOffset[1] * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN;
|
||||
}
|
||||
|
||||
/*
|
||||
void LCR_getCameraPos(LCR_SpaceUnit pos[3])
|
||||
{
|
||||
pos[0] = (LCR_scene3D.camera.transform.translation.x *
|
||||
LCR_SQUARE_SIDE_LEN) / S3L_FRACTIONS_PER_UNIT;
|
||||
pos[1] = (LCR_scene3D.camera.transform.translation.y *
|
||||
LCR_SQUARE_SIDE_LEN) / S3L_FRACTIONS_PER_UNIT;
|
||||
pos[2] = (LCR_scene3D.camera.transform.translation.z *
|
||||
LCR_SQUARE_SIDE_LEN) / S3L_FRACTIONS_PER_UNIT;
|
||||
}
|
||||
if (LCR_scene3D.camera.transform.rotation.x > S3L_FRACTIONS_PER_UNIT / 4)
|
||||
LCR_scene3D.camera.transform.rotation.x = S3L_FRACTIONS_PER_UNIT / 4;
|
||||
|
||||
void LCR_setCameraPos(LCR_SpaceUnit pos[3])
|
||||
{
|
||||
LCR_scene3D.camera.transform.translation.x =
|
||||
(pos[0] * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN;
|
||||
LCR_scene3D.camera.transform.translation.y =
|
||||
(pos[1] * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN;
|
||||
LCR_scene3D.camera.transform.translation.z =
|
||||
(pos[2] * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN;
|
||||
if (LCR_scene3D.camera.transform.rotation.x < -1 * S3L_FRACTIONS_PER_UNIT / 4)
|
||||
LCR_scene3D.camera.transform.rotation.x = -1 * S3L_FRACTIONS_PER_UNIT / 4;
|
||||
}
|
||||
*/
|
||||
|
||||
void LCR_rendererDraw(void)
|
||||
{
|
||||
|
@ -168,16 +154,18 @@ void LCR_drawSkyStrip(int verticalOffset, uint8_t horizontalOffset)
|
|||
{
|
||||
for (int i = 0; i < LCR_EFFECTIVE_RESOLUTION_X; ++i)
|
||||
{
|
||||
// TODO: check z-buffer
|
||||
// only diraw background on empty pixels
|
||||
if (S3L_zBufferRead(i,verticalOffset) == S3L_MAX_DEPTH)
|
||||
{
|
||||
int offsetX = (i / LCR_SETTING_SKY_SIZE + horizontalOffset)
|
||||
% LCR_SKY_IMAGE_SIZE;
|
||||
|
||||
int offsetX = (i / LCR_SETTING_SKY_SIZE + horizontalOffset)
|
||||
% LCR_SKY_IMAGE_SIZE;
|
||||
uint16_t pixel = *(skyLine + offsetX / 2);
|
||||
|
||||
uint16_t pixel = *(skyLine + offsetX / 2);
|
||||
pixel = offsetX % 2 ? (pixel >> 8) : (pixel & 0x00ff);
|
||||
|
||||
pixel = offsetX % 2 ? (pixel >> 8) : (pixel & 0x00ff);
|
||||
|
||||
LCR_drawPixelUnsafe(i,verticalOffset,LCR_skyImages[pixel]);
|
||||
LCR_drawPixelUnsafe(i,verticalOffset,LCR_skyImages[pixel]);
|
||||
}
|
||||
}
|
||||
|
||||
verticalOffset++;
|
||||
|
@ -189,4 +177,16 @@ void LCR_drawSkyStrip(int verticalOffset, uint8_t horizontalOffset)
|
|||
#endif
|
||||
}
|
||||
|
||||
LCR_SpaceUnit LCR_rendererGetCameraYaw(void)
|
||||
{
|
||||
return (LCR_scene3D.camera.transform.rotation.y * LCR_SQUARE_SIDE_LEN) /
|
||||
S3L_FRACTIONS_PER_UNIT;
|
||||
}
|
||||
|
||||
LCR_SpaceUnit LCR_rendererGetCameraPitch(void)
|
||||
{
|
||||
return (LCR_scene3D.camera.transform.rotation.x * LCR_SQUARE_SIDE_LEN) /
|
||||
S3L_FRACTIONS_PER_UNIT;
|
||||
}
|
||||
|
||||
#endif // guard
|
||||
|
|
12
settings.h
12
settings.h
|
@ -23,6 +23,18 @@
|
|||
#define LCR_SETTING_FREE_CAMERA_SPEED 50
|
||||
#endif
|
||||
|
||||
#ifndef LCR_SETTING_FREE_CAMERA_TURN_SPEED
|
||||
#define LCR_SETTING_FREE_CAMERA_TURN_SPEED 1024
|
||||
#endif
|
||||
|
||||
#ifndef LCR_SETTING_SKY_ROLL_MULTIPLIER_V
|
||||
#define LCR_SETTING_SKY_ROLL_MULTIPLIER_V 8
|
||||
#endif
|
||||
|
||||
#ifndef LCR_SETTING_SKY_ROLL_MULTIPLIER_H
|
||||
#define LCR_SETTING_SKY_ROLL_MULTIPLIER_H 4
|
||||
#endif
|
||||
|
||||
#ifndef LCR_SETTING_MAX_VERTICES
|
||||
/** Maximum number of vertices for 3D rendering. Lower number will decrease
|
||||
RAM usage but will prevent larger maps from being loaded. */
|
||||
|
|
Loading…
Reference in a new issue