Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 676e03b

Browse files
committed
orbit
1 parent 04446fd commit 676e03b

File tree

3 files changed

+76
-7
lines changed

3 files changed

+76
-7
lines changed

cncvis/actor.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ void ucncActorRender(ucncActor *actor) {
104104
glMaterialfv(GL_FRONT, GL_SHININESS, matShininess);
105105

106106
// Logging actor rendering details (optional)
107-
printf("Rendering actor: %s, Position: (%.2f, %.2f, %.2f), Rotation: (%.2f, %.2f, %.2f)\n",
108-
actor->name, actor->positionX, actor->positionY, actor->positionZ,
109-
actor->rotationX, actor->rotationY, actor->rotationZ);
107+
// printf("Rendering actor: %s, Position: (%.2f, %.2f, %.2f), Rotation: (%.2f, %.2f, %.2f)\n",
108+
// actor->name, actor->positionX, actor->positionY, actor->positionZ,
109+
// actor->rotationX, actor->rotationY, actor->rotationZ);
110110

111111
// Render triangles from the STL data
112112
glBegin(GL_TRIANGLES);

cncvis/assembly.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ int ucncAssemblyAddAssembly(ucncAssembly *parent, ucncAssembly *child)
143143

144144
void ucncAssemblyRender(const ucncAssembly *assembly) {
145145

146+
146147
glPushMatrix(); // Save the current transformation matrix
147148

148149
// Apply assembly transformations
@@ -159,9 +160,9 @@ void ucncAssemblyRender(const ucncAssembly *assembly) {
159160
glTranslatef(-assembly->originX, -assembly->originY, -assembly->originZ);
160161

161162
// Debugging output: Print assembly details
162-
printf("Rendering assembly: %s at position (%.2f, %.2f, %.2f) with rotation (%.2f, %.2f, %.2f)\n",
163-
assembly->name, assembly->positionX, assembly->positionY, assembly->positionZ,
164-
assembly->rotationX, assembly->rotationY, assembly->rotationZ);
163+
// printf("Rendering assembly: %s at position (%.2f, %.2f, %.2f) with rotation (%.2f, %.2f, %.2f)\n",
164+
// assembly->name, assembly->positionX, assembly->positionY, assembly->positionZ,
165+
// assembly->rotationX, assembly->rotationY, assembly->rotationZ);
165166

166167
// Render all actors in this assembly
167168
for (int i = 0; i < assembly->actorCount; i++) {

main/src/main.c

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ int framebufferHeight = 600;
2222
static lv_obj_t *canvas = NULL;
2323
static uint8_t cbuf[LV_CANVAS_BUF_SIZE(CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_DEPTH, LV_DRAW_BUF_STRIDE_ALIGN)];
2424

25+
// Global variables for frame timing
26+
static double previousTime = 0.0;
27+
static double currentTime = 0.0;
28+
static int frameCount = 0;
29+
static float fps = 0.0f;
30+
float calculateFPS(void);
31+
void renderFPSData(int frameNumber, float fps);
32+
2533
/* Copy TinyGL framebuffer (ARGB8888) to LVGL buffer (XRGB8888) */
2634
void ZB_copyFrameBufferLVGL(ZBuffer *zb, lv_color32_t *lv_buf)
2735
{
@@ -134,7 +142,7 @@ int main(int argc, char **argv)
134142
printf("Init done..\n");
135143

136144
// Set up a timer to render the CNC scene using TinyGL and LVGL
137-
lv_timer_create(render_timer_cb, 40, NULL);
145+
lv_timer_create(render_timer_cb, 1, NULL);
138146

139147
#if LV_USE_OS == LV_OS_NONE
140148
while (1)
@@ -195,12 +203,17 @@ static void render_timer_cb(lv_timer_t *timer)
195203

196204
drawAxis(500.0f); // Draw a reference axis
197205

206+
// Calculate FPS and timing data
207+
float fps = calculateFPS();
208+
renderFPSData(frameCount, fps);
209+
198210
// Ensure OpenGL commands are executed
199211
glFlush();
200212

201213
// Copy the framebuffer to the LVGL canvas
202214
ZB_copyFrameBufferLVGL(globalFramebuffer, (lv_color32_t *)cbuf);
203215
lv_obj_invalidate(canvas);
216+
204217
}
205218

206219

@@ -286,3 +299,58 @@ static void update_camera_matrix(ucncCamera *camera) {
286299
camera->positionZ + camera->directionZ,
287300
camera->upX, camera->upY, camera->upZ);
288301
}
302+
303+
float calculateFPS(void)
304+
{
305+
306+
// Update the current time in seconds
307+
currentTime = (double)clock() / CLOCKS_PER_SEC;
308+
309+
// Calculate FPS every second
310+
if (currentTime - previousTime >= 1.0)
311+
{
312+
fps = (float)frameCount / (currentTime - previousTime);
313+
314+
// Reset for the next second
315+
previousTime = currentTime;
316+
frameCount = 0; // Reset frame count after calculating FPS
317+
}
318+
319+
return fps;
320+
}
321+
322+
323+
// Function to render FPS and performance data
324+
void renderFPSData(int frameNumber, float fps)
325+
{
326+
// Set up orthographic projection for 2D rendering
327+
glMatrixMode(GL_PROJECTION);
328+
glPushMatrix();
329+
glLoadIdentity();
330+
331+
glMatrixMode(GL_MODELVIEW);
332+
glPushMatrix();
333+
glLoadIdentity();
334+
335+
// Set text size and color (assuming these are implemented elsewhere)
336+
glTextSize(GL_TEXT_SIZE16x16);
337+
unsigned int color = 0x00FFFFFF; // White color
338+
339+
// Prepare the text to display
340+
char textBuffer[256];
341+
snprintf(textBuffer, sizeof(textBuffer), "FRM: %d", frameNumber);
342+
int x = 10; // Position from the left
343+
int y = 10; // Position from the top
344+
glDrawText((unsigned char *)textBuffer, x, y, color);
345+
346+
x = 10; // Position from the left
347+
y = 30; // Position from the top
348+
snprintf(textBuffer, sizeof(textBuffer), "FPS: %.1f", fps);
349+
glDrawText((unsigned char *)textBuffer, x, y, color);
350+
351+
// Restore matrices
352+
glPopMatrix();
353+
glMatrixMode(GL_PROJECTION);
354+
glPopMatrix();
355+
glMatrixMode(GL_MODELVIEW);
356+
}

0 commit comments

Comments
 (0)