-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
136 lines (114 loc) · 4.26 KB
/
example.cpp
File metadata and controls
136 lines (114 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "game.hpp"
extern "C" {
#include "b3dlib.h"
#include "cat.h"
}
using namespace blit;
B3LMeshNoTexObj_t *pBox2;
B3LMeshObj_t *pBox;
render_t B3Lrender;
B3LMeshObj_t box;
vect3_t at ={.x=0.0f,.y=0.0f,.z=0.0f};
f32 i = 0.0f;
/* setup */
void init() {
set_screen_mode(screen_mode::lores);
//you need a 32bit framebuff here!
B3L_RenderInit(&B3Lrender,(fBuff_t *)fb.data);
pBox2 = (B3LMeshNoTexObj_t *)B3L_GetFreeObj(&B3Lrender);
pBox = (B3LMeshObj_t *)B3L_GetFreeObj(&B3Lrender);
B3L_InitBoxObj(&box,50.0f);
B3L_InitBoxObjNoTexture(pBox2,50.0f); //create a size 10 box
InitCatObj(pBox,4.0f); //create a size 10 box
B3L_AddObjToRenderList((B3LObj_t *)&box, &B3Lrender);
B3L_AddObjToRenderList((B3LObj_t *)pBox, &B3Lrender);
B3L_AddObjToRenderList((B3LObj_t *)pBox2, &B3Lrender);
box.transform.translation.y = 70.0f;
box.transform.translation.x = 50.0f;
box.transform.translation.z = -50.0f;
pBox2->transform.translation.y = 80.0f;
pBox2->transform.translation.x = 10.0f;
pBox2->transform.translation.z = -70.0f;
pBox->transform.translation.y = 0.0f;
pBox->transform.translation.x = 0.0f;
pBox->transform.translation.z = 0.0f;
B3Lrender.camera.transform.translation.x = 0.0f;
B3Lrender.camera.transform.translation.y = 0.0f;
B3Lrender.camera.transform.translation.z = -200.0f;
//B3Lrender.camera.transform.rotation.x = -0.125f;
//B3Lrender.camera.transform.rotation.y = 0.25f;
//B3Lrender.camera.transform.rotation.z = 0.0f;
B3L_CameraLookAt(&(B3Lrender.camera), &at);
//printf("init done\n");
}
void update(uint32_t time){
box.transform.rotation.x += 0.001f;
box.transform.rotation.y += 0.001f;
//pBox->transform.rotation.x -= 0.001f;
//pBox->transform.rotation.z -= 0.001f;
pBox2->transform.rotation.z -= 0.001f;
pBox2->transform.rotation.y -= 0.001f;
if (pressed(DPAD_UP)){
B3Lrender.camera.transform.translation.z +=1.01f;
}
if (pressed(DPAD_DOWN)){
B3Lrender.camera.transform.translation.z -=1.01f;
}
if (pressed(DPAD_LEFT)){
B3Lrender.camera.transform.translation.x += 1.0f;
}
if (pressed(DPAD_RIGHT)){
B3Lrender.camera.transform.translation.x -= 1.0f;
}
if (i>1.0f){
i=0.0f;
}
i +=0.002f;
B3Lrender.camera.transform.translation.z = B3L_sin(i)*200.0f;
B3Lrender.camera.transform.translation.x = B3L_cos(i)*200.0f;
B3L_CameraLookAt(&(B3Lrender.camera), &at);
}
#define RGB_BLEND(sr, sg, sb, dr, dg, db, a) \
uint8_t r = (sr * a) >> 8; \
uint8_t g = (sg * a) >> 8; \
uint8_t b = (sb * a) >> 8; \
uint16_t ia = 256 - a; \
dr = (r + ((dr * ia) >> 8)); \
dg = (g + ((dg * ia) >> 8)); \
db = (b + ((db * ia) >> 8)); \
void render(uint32_t time) {
B3L_NewRenderStart( &B3Lrender);
B3L_RenderScence(&B3Lrender);
/*
DrawTriColor(
0.0f,0.0f,0.1f,
12.0f,12.0f,0.1f,
0.0f,24.0f,0.1f,
1,0xff,0XFF7E2553,
(fBuff_t *)fb.data,B3Lrender.pZBuff);
*/
//printf("result is %d\n",result);
uint8_t *buff = (uint8_t *)fb.data;
uint32_t *u4buff = (uint32_t *)fb.data;
uint32_t backColor = B3Lrender.light.color;
uint8_t r,g,b;
uint32_t i;
uint32_t color;
/*
for (i=0;i<VIDEO_BUFF_LENTH;i++){
color = u4buff[i];
color = color>>24;
color = (color<<24)|(color<<16)|(color<<8)|0xff;
u4buff[i] = color;
}
*/
//on h750 you could use DMA2D mode DMA2D_CR/mode = 0b101 to do this transform
for (i=0;i<VIDEO_BUFF_LENTH;i++){
r = (backColor&(0x00FF0000))>>16;
g = (backColor &(0x0000FF00))>>8;
b = (backColor &(0x000000FF));
RGB_BLEND(buff[i*4+2],buff[i*4+1],buff[i*4],r,g,b,buff[i*4+3])
u4buff[i]=(r<<24)|(g<<16)|(b<<8);
}
fb.watermark();
}