Roll sky by camera
This commit is contained in:
parent
e21d5b7825
commit
84163d0d3c
4 changed files with 60 additions and 36 deletions
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue