-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSample.cpp
More file actions
70 lines (58 loc) · 1.69 KB
/
Sample.cpp
File metadata and controls
70 lines (58 loc) · 1.69 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
#ifdef __MBED_SAMPLE__
#include "Jet.hpp"
using namespace Renderer;
Scene *scene;
Camera *camera;
DirectionalLight *dirLight;
AmbientLight *ambLight;
Material *redMaterial;
Material *greenMaterial;
Material *blueMaterial;
Object *cube;
Object *plane;
Object *sphere;
void setup()
{
// Initialize framebuffer and screen dimensions
uint16_t *framebuffer = new uint16_t[800 * 600];
int screenWidth = 800;
int screenHeight = 600;
// Create scene
scene = new Scene(framebuffer, screenWidth, screenHeight);
// Create and set camera
camera = new Camera();
camera->setPosition(0, 0, -500);
camera->setRotation(0, 0, 0);
camera->setFOV(90, screenWidth);
scene->setCamera(camera);
// Create and set lights
dirLight = new DirectionalLight({-90, 0}, {255, 255, 255});
ambLight = new AmbientLight({50, 50, 50});
scene->setDirectionalLight(dirLight);
scene->setAmbientLight(ambLight);
// Create materials
redMaterial = new Material(0xF800); // Red
greenMaterial = new Material(0x07E0); // Green
blueMaterial = new Material(0x001F); // Blue
// Create objects
cube = Primitives::createCube(100, 100, 100, redMaterial);
plane = Primitives::createPlane(500, 500, greenMaterial);
sphere = Primitives::createSphere(50, 16, blueMaterial);
// Set object transformations
cube->translate(0, 0, 200);
plane->translate(0, -100, 0);
sphere->translate(200, 0, 0);
// Add objects to scene
scene->addObject(cube);
scene->addObject(plane);
scene->addObject(sphere);
}
void loop()
{
// Rotate cube and sphere
cube->rotate(1, 1, 0);
sphere->rotate(0, 1, 1);
// Render scene
scene->render();
}
#endif