Compare commits
5 Commits
2ee8fe4e4a
...
ec49c37f1b
Author | SHA1 | Date |
---|---|---|
wgroeneveld | ec49c37f1b | |
wgroeneveld | 47d685a41c | |
wgroeneveld | 52b55d91e6 | |
wgroeneveld | ba64bc15c3 | |
wgroeneveld | 54b857bd9b |
|
@ -30,3 +30,4 @@ add_subdirectory(test)
|
|||
|
||||
add_subdirectory(demos/demo1-wireframes)
|
||||
add_subdirectory(demos/demo2-blender-import)
|
||||
add_subdirectory(demos/demo3-textures)
|
||||
|
|
36
README.md
36
README.md
|
@ -6,9 +6,11 @@ This is (very) loosely based on David's 3D soft engine in C#/JS: https://www.dav
|
|||
|
||||
Engine blueprint: a stripped-down version of [https://github.com/wgroeneveld/gba-sprite-engine/](https://github.com/wgroeneveld/gba-sprite-engine/) combined with more _tonc_ library functions.
|
||||
|
||||
#### Show me the money
|
||||
### Show me the money!
|
||||
|
||||
Sure thing. **Demo 1**: without wires
|
||||
Sure thing.
|
||||
|
||||
#### **Demo 1**: without wires
|
||||
|
||||
![design](https://github.com/wgroeneveld/gba-bitmap-engine/blob/master/img/wireless.gif?raw=true)
|
||||
|
||||
|
@ -17,7 +19,7 @@ You 'should' see a cube forming based on 8 vertices. It's a simple example to sh
|
|||
|
||||
60 FPS. Yay.
|
||||
|
||||
**Demo 1b**: with wires
|
||||
#### **Demo 1b**: with wires
|
||||
|
||||
![design](https://github.com/wgroeneveld/gba-bitmap-engine/blob/master/img/wired.gif?raw=true)
|
||||
|
||||
|
@ -28,7 +30,11 @@ MODE4's weird byte write problems are causing trouble. Time to consult _tonc_ an
|
|||
|
||||
30 FPS, winning 10 frames using `bmp8_line()`.
|
||||
|
||||
**Demo 2**: load actual vertex content from Blender/Babylon based on [this](https://david.blob.core.windows.net/softengine3d/part3/index.html):
|
||||
#### **Demo 2**: load actual vertex content
|
||||
|
||||
From Blender/Babylon based on [this](https://david.blob.core.windows.net/softengine3d/part3/index.html).
|
||||
|
||||
A JS script has been provided that generates the needed C++ code. It's not great, and not very performant.
|
||||
|
||||
![design](https://github.com/wgroeneveld/gba-bitmap-engine/blob/master/img/monkey.gif?raw=true)
|
||||
|
||||
|
@ -41,7 +47,26 @@ Use the `gba-sprite-engine` instead.
|
|||
I am aware of countless optimization opportunities but even thinking about that makes me sleepy.
|
||||
This is a high-level C++ engine, meaning redundant stack objects could also cause problems. And I'm okay with that - it's a proof-of-concept!
|
||||
|
||||
#### GBA-Specific problems
|
||||
#### **Demo 3**: rasterization
|
||||
|
||||
The `RasterizerRenderer` class draws triangles as 'fast' as possible, using horizontal scanlines.
|
||||
There is a fast way to lines into VRAM. I tried implementing Z-buffering, but the buffer was too big and too slow as z-coords also had to be interpolated...
|
||||
|
||||
![design](https://github.com/wgroeneveld/gba-bitmap-engine/blob/master/img/raster.gif?raw=true)
|
||||
|
||||
At this point, I do not think it's that interesting to go on to texture mapping other than the fun of it. Even with a lot of haxx and tricks, the colored monkey won't ever spin at 30FPS...
|
||||
|
||||
#### **Demo 3b**: with back-face culling
|
||||
|
||||
It did improve performance. I exported a few Babylon meshes, and the octahedron with 8 faces does run at 20FPS compared to 11FPS when back-face culling was implemented (that omits rendering certain faces if z < 0)
|
||||
|
||||
![design](https://github.com/wgroeneveld/gba-bitmap-engine/blob/master/img/octa.gif?raw=true)
|
||||
|
||||
Changing colors indicate certain triangles were not drawn (into the background). It does not help a lot with our monkey, alas. Too many vertices...
|
||||
|
||||
More examples of meshes (box, cylinder, octahedron, sphere, torus) included.
|
||||
|
||||
### GBA-Specific problems
|
||||
|
||||
**Fixed-point math** sums up things nicely.
|
||||
|
||||
|
@ -78,3 +103,4 @@ More details in `math.h`.
|
|||
|
||||
In any case, lots of rounding errors occur. It is luckily not a problem due to GBA's limited screen dimensions.
|
||||
|
||||
**Limited iWRAM** size is another problem. Use `const` arrays as much as possible!
|
|
@ -1,6 +1,6 @@
|
|||
#include <libgba-sprite-engine/scene.h>
|
||||
#include <libgba-sprite-engine/renderer/gba_engine.h>
|
||||
#include <libgba-sprite-engine/palette/palette_manager.h>
|
||||
#include <libgba-bitmap-engine/scene.h>
|
||||
#include <libgba-bitmap-engine/renderer/gba_engine.h>
|
||||
#include <libgba-bitmap-engine/palette/palette_manager.h>
|
||||
|
||||
#include "wirescene.h"
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
// Created by Wouter Groeneveld on 02/08/18.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/gba/tonc_memdef.h>
|
||||
#include <libgba-sprite-engine/renderer/gba_engine.h>
|
||||
#include <libgba-sprite-engine/background/text_stream.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_memdef.h>
|
||||
#include <libgba-bitmap-engine/renderer/gba_engine.h>
|
||||
#include <libgba-bitmap-engine/background/text_stream.h>
|
||||
#include "wirescene.h"
|
||||
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
#ifndef GBA_SPRITE_ENGINE_SAMPLE_START_SCENE_H
|
||||
#define GBA_SPRITE_ENGINE_SAMPLE_START_SCENE_H
|
||||
|
||||
#include <libgba-sprite-engine/scene.h>
|
||||
#include <libgba-sprite-engine/mesh.h>
|
||||
#include <libgba-sprite-engine/camera.h>
|
||||
#include <libgba-bitmap-engine/scene.h>
|
||||
#include <libgba-bitmap-engine/mesh.h>
|
||||
#include <libgba-bitmap-engine/camera.h>
|
||||
#include <memory>
|
||||
|
||||
class WireScene : public Scene {
|
||||
|
|
|
@ -1,20 +1,31 @@
|
|||
/*-----
|
||||
partially reverse-engineered https://david.blob.core.windows.net/softengine3d/part3/index.html
|
||||
added compatibility with newer Babylon export formats
|
||||
|
||||
try this in your browser:
|
||||
copy(BABYLON.SceneSerializer.SerializeMesh(BABYLON.MeshBuilder.CreateBox("bla", {}, scene), true, true))
|
||||
|
||||
What's possible with the MeshBuilder? See for example https://doc.babylonjs.com/how_to/polyhedra_shapes
|
||||
------*/
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
var jsonObject = JSON.parse(fs.readFileSync('monkey.babylon', 'utf8'));
|
||||
var args = process.argv.slice(2);
|
||||
var jsonObject = JSON.parse(fs.readFileSync(args[0], 'utf8'));
|
||||
|
||||
var result =
|
||||
"#include <libgba-sprite-engine/mesh.h>\n" +
|
||||
"#include <libgba-bitmap-engine/mesh.h>\n" +
|
||||
"Mesh* createMesh() { \n" +
|
||||
"\t auto obj = new Mesh();\n";
|
||||
|
||||
var meshes = 0;
|
||||
function addMesh(x, y, z) {
|
||||
result += `\t obj->add(VectorFx::fromFloat(${x}, ${y}, ${z}));\n`;
|
||||
meshes++;
|
||||
var vertices = 0;
|
||||
function addMeshWithNormals(x, y, z, nx, ny, nz, u, v) {
|
||||
result += `\t obj->add(VectorFx::fromFloat(${x}, ${y}, ${z}), VectorFx::fromFloat(${nx}, ${ny}, ${nz}), ${u}, ${v});\n`;
|
||||
vertices++;
|
||||
}
|
||||
var faces = 0;
|
||||
function addFace(a, b, c) {
|
||||
result += `\t obj->addFace({ ${a}, ${b}, ${c}});\n`;
|
||||
result += `\t obj->addFace(${a}, ${b}, ${c});\n`;
|
||||
faces++;
|
||||
}
|
||||
function setPosition(position) {
|
||||
|
@ -26,11 +37,18 @@ function done() {
|
|||
"}\n"
|
||||
}
|
||||
|
||||
// partially reverse-engineered https://david.blob.core.windows.net/softengine3d/part3/index.html
|
||||
for(var meshIndex = 0; meshIndex < jsonObject.meshes.length; meshIndex++) {
|
||||
var verticesArray = jsonObject.meshes[meshIndex].vertices;
|
||||
var indicesArray = jsonObject.meshes[meshIndex].indices;
|
||||
var uvCount = jsonObject.meshes[meshIndex].uvCount;
|
||||
const mesh = jsonObject.meshes[meshIndex];
|
||||
var data = undefined;
|
||||
var verticesArray = mesh.vertices;
|
||||
var indicesArray = mesh.indices;
|
||||
var uvCount = mesh.uvCount;
|
||||
if(mesh.geometryId) {
|
||||
data = jsonObject.geometries.vertexData.find(v => v.id === mesh.geometryId);
|
||||
verticesArray = data.positions;
|
||||
indicesArray = data.indices;
|
||||
}
|
||||
|
||||
var verticesStep = 1;
|
||||
switch(uvCount) {
|
||||
case 0:
|
||||
|
@ -42,28 +60,62 @@ for(var meshIndex = 0; meshIndex < jsonObject.meshes.length; meshIndex++) {
|
|||
case 2:
|
||||
verticesStep = 10;
|
||||
break;
|
||||
default:
|
||||
verticesStep = 3;
|
||||
break;
|
||||
}
|
||||
var verticesCount = verticesArray.length / verticesStep;
|
||||
var facesCount = indicesArray.length / 3;
|
||||
//var mesh = new SoftEngine.Mesh(jsonObject.meshes[meshIndex].name, verticesCount, facesCount);
|
||||
for(var index = 0; index < verticesCount; index++) {
|
||||
var x = verticesArray[index * verticesStep];
|
||||
var y = verticesArray[index * verticesStep + 1];
|
||||
var z = verticesArray[index * verticesStep + 2];
|
||||
var u = 0, v = 0;
|
||||
|
||||
addMesh(x, y, z);
|
||||
if(x !== undefined && y !== undefined && z !== undefined) {
|
||||
if(data && data.normals) {
|
||||
var nx = data.normals[index * verticesStep];
|
||||
var ny = data.normals[index * verticesStep + 1];
|
||||
var nz = data.normals[index * verticesStep + 2];
|
||||
if(data.uvs) {
|
||||
u = data.uvs[index];
|
||||
v = data.uvs[index + 1];
|
||||
}
|
||||
|
||||
addMeshWithNormals(x, y, z, nx, ny, nz, u, v);
|
||||
} else {
|
||||
var nx = verticesArray[index * verticesStep + 3];
|
||||
var ny = verticesArray[index * verticesStep + 4];
|
||||
var nz = verticesArray[index * verticesStep + 5];
|
||||
if(uvCount > 0) {
|
||||
u = verticesArray[index * verticesStep + 6];
|
||||
v = verticesArray[index * verticesStep + 7];
|
||||
}
|
||||
|
||||
addMeshWithNormals(x, y, z, nx, ny, nz, u, v);
|
||||
}
|
||||
} else {
|
||||
console.log(`WARN; vertices index ${index} with step ${verticesStep} contains invalid data: ${x}, ${y}, ${z}`)
|
||||
}
|
||||
}
|
||||
for(var index = 0; index < facesCount; index++) {
|
||||
var a = indicesArray[index * 3];
|
||||
var b = indicesArray[index * 3 + 1];
|
||||
var c = indicesArray[index * 3 + 2];
|
||||
|
||||
addFace(a, b, c);
|
||||
if(a !== undefined && b !== undefined && c !== undefined) {
|
||||
addFace(a, b, c);
|
||||
} else {
|
||||
console.log(`WARN; indices index ${index} contains invalid data: ${a}, ${b}, ${c}`)
|
||||
}
|
||||
}
|
||||
var position = jsonObject.meshes[meshIndex].position;
|
||||
var position = mesh.position;
|
||||
setPosition(position);
|
||||
}
|
||||
|
||||
done();
|
||||
fs.writeFileSync('src/mesh.cpp', result);
|
||||
console.log(`mesh.cpp written; ${meshes} meshes and ${faces} faces. GLHF!`)
|
||||
fs.writeFileSync(args[1], result);
|
||||
console.log(`mesh.cpp written; ${vertices} vertices and ${faces} faces. GLHF!`)
|
||||
if(vertices > 800) {
|
||||
console.log('WARNING lots of vertices detected, this will not run well...');
|
||||
}
|
|
@ -0,0 +1,327 @@
|
|||
{
|
||||
"geometries": {
|
||||
"boxes": [],
|
||||
"spheres": [],
|
||||
"cylinders": [],
|
||||
"toruses": [],
|
||||
"grounds": [],
|
||||
"planes": [],
|
||||
"torusKnots": [],
|
||||
"vertexData": [
|
||||
{
|
||||
"id": "78db452a-92d6-428a-badf-e5561ecc884e",
|
||||
"updatable": false,
|
||||
"positions": [
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5
|
||||
],
|
||||
"normals": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0
|
||||
],
|
||||
"uvs": [
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0
|
||||
],
|
||||
"indices": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
0,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
4,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
8,
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
12,
|
||||
14,
|
||||
15,
|
||||
16,
|
||||
17,
|
||||
18,
|
||||
16,
|
||||
18,
|
||||
19,
|
||||
20,
|
||||
21,
|
||||
22,
|
||||
20,
|
||||
22,
|
||||
23
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"meshes": [
|
||||
{
|
||||
"name": "bla",
|
||||
"id": "bla",
|
||||
"type": "Mesh",
|
||||
"position": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"rotation": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"scaling": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"localMatrix": {
|
||||
"0": 1,
|
||||
"1": 0,
|
||||
"2": 0,
|
||||
"3": 0,
|
||||
"4": 0,
|
||||
"5": 1,
|
||||
"6": 0,
|
||||
"7": 0,
|
||||
"8": 0,
|
||||
"9": 0,
|
||||
"10": 1,
|
||||
"11": 0,
|
||||
"12": 0,
|
||||
"13": 0,
|
||||
"14": 0,
|
||||
"15": 1
|
||||
},
|
||||
"isEnabled": true,
|
||||
"isVisible": true,
|
||||
"infiniteDistance": false,
|
||||
"pickable": true,
|
||||
"receiveShadows": false,
|
||||
"billboardMode": 0,
|
||||
"visibility": 1,
|
||||
"checkCollisions": false,
|
||||
"isBlocker": false,
|
||||
"overrideMaterialSideOrientation": null,
|
||||
"isUnIndexed": false,
|
||||
"geometryId": "78db452a-92d6-428a-badf-e5561ecc884e",
|
||||
"subMeshes": [
|
||||
{
|
||||
"materialIndex": 0,
|
||||
"verticesStart": 0,
|
||||
"verticesCount": 24,
|
||||
"indexStart": 0,
|
||||
"indexCount": 36
|
||||
}
|
||||
],
|
||||
"instances": [],
|
||||
"animations": [],
|
||||
"ranges": [],
|
||||
"layerMask": 268435455,
|
||||
"alphaIndex": 1.7976931348623157e+308,
|
||||
"hasVertexAlpha": false,
|
||||
"overlayAlpha": 0.5,
|
||||
"overlayColor": [
|
||||
1,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"applyFog": true
|
||||
}
|
||||
]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,315 @@
|
|||
{
|
||||
"geometries": {
|
||||
"boxes": [],
|
||||
"spheres": [],
|
||||
"cylinders": [],
|
||||
"toruses": [],
|
||||
"grounds": [],
|
||||
"planes": [],
|
||||
"torusKnots": [],
|
||||
"vertexData": [
|
||||
{
|
||||
"id": "c08fbf04-7758-4154-ab43-744f5d69019e",
|
||||
"updatable": false,
|
||||
"positions": [
|
||||
0,
|
||||
0,
|
||||
1.414214,
|
||||
1.414214,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1.414214,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1.414214,
|
||||
0,
|
||||
1.414214,
|
||||
0,
|
||||
-1.414214,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1.414214,
|
||||
-1.414214,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
-1.414214,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1.414214,
|
||||
0,
|
||||
-1.414214,
|
||||
0,
|
||||
1.414214,
|
||||
0,
|
||||
0,
|
||||
1.414214,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
-1.414214,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
-1.414214,
|
||||
1.414214,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
-1.414214,
|
||||
0,
|
||||
1.414214,
|
||||
0,
|
||||
0,
|
||||
1.414214,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
-1.414214,
|
||||
-1.414214,
|
||||
0,
|
||||
0,
|
||||
-1.414214,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
-1.414214,
|
||||
0,
|
||||
-1.414214,
|
||||
0
|
||||
],
|
||||
"normals": [
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258,
|
||||
-0.5773502691896258
|
||||
],
|
||||
"uvs": [
|
||||
1.3660254037844384,
|
||||
0,
|
||||
-0.3660254037844384,
|
||||
-1.1102230246251565e-16,
|
||||
0.4999999999999998,
|
||||
-1.4999999999999996,
|
||||
1.3660254037844384,
|
||||
0,
|
||||
-0.3660254037844384,
|
||||
-1.1102230246251565e-16,
|
||||
0.4999999999999998,
|
||||
-1.4999999999999996,
|
||||
1.3660254037844384,
|
||||
0,
|
||||
-0.3660254037844384,
|
||||
-1.1102230246251565e-16,
|
||||
0.4999999999999998,
|
||||
-1.4999999999999996,
|
||||
1.3660254037844384,
|
||||
0,
|
||||
-0.3660254037844384,
|
||||
-1.1102230246251565e-16,
|
||||
0.4999999999999998,
|
||||
-1.4999999999999996,
|
||||
1.3660254037844384,
|
||||
0,
|
||||
-0.3660254037844384,
|
||||
-1.1102230246251565e-16,
|
||||
0.4999999999999998,
|
||||
-1.4999999999999996,
|
||||
1.3660254037844384,
|
||||
0,
|
||||
-0.3660254037844384,
|
||||
-1.1102230246251565e-16,
|
||||
0.4999999999999998,
|
||||
-1.4999999999999996,
|
||||
1.3660254037844384,
|
||||
0,
|
||||
-0.3660254037844384,
|
||||
-1.1102230246251565e-16,
|
||||
0.4999999999999998,
|
||||
-1.4999999999999996,
|
||||
1.3660254037844384,
|
||||
0,
|
||||
-0.3660254037844384,
|
||||
-1.1102230246251565e-16,
|
||||
0.4999999999999998,
|
||||
-1.4999999999999996
|
||||
],
|
||||
"indices": [
|
||||
0,
|
||||
2,
|
||||
1,
|
||||
3,
|
||||
5,
|
||||
4,
|
||||
6,
|
||||
8,
|
||||
7,
|
||||
9,
|
||||
11,
|
||||
10,
|
||||
12,
|
||||
14,
|
||||
13,
|
||||
15,
|
||||
17,
|
||||
16,
|
||||
18,
|
||||
20,
|
||||
19,
|
||||
21,
|
||||
23,
|
||||
22
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"meshes": [
|
||||
{
|
||||
"name": "oct",
|
||||
"id": "oct",
|
||||
"type": "Mesh",
|
||||
"position": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"rotation": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"scaling": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"localMatrix": {
|
||||
"0": 1,
|
||||
"1": 0,
|
||||
"2": 0,
|
||||
"3": 0,
|
||||
"4": 0,
|
||||
"5": 1,
|
||||
"6": 0,
|
||||
"7": 0,
|
||||
"8": 0,
|
||||
"9": 0,
|
||||
"10": 1,
|
||||
"11": 0,
|
||||
"12": 0,
|
||||
"13": 0,
|
||||
"14": 0,
|
||||
"15": 1
|
||||
},
|
||||
"isEnabled": true,
|
||||
"isVisible": true,
|
||||
"infiniteDistance": false,
|
||||
"pickable": true,
|
||||
"receiveShadows": false,
|
||||
"billboardMode": 0,
|
||||
"visibility": 1,
|
||||
"checkCollisions": false,
|
||||
"isBlocker": false,
|
||||
"overrideMaterialSideOrientation": null,
|
||||
"isUnIndexed": false,
|
||||
"geometryId": "c08fbf04-7758-4154-ab43-744f5d69019e",
|
||||
"subMeshes": [
|
||||
{
|
||||
"materialIndex": 0,
|
||||
"verticesStart": 0,
|
||||
"verticesCount": 24,
|
||||
"indexStart": 0,
|
||||
"indexCount": 24
|
||||
}
|
||||
],
|
||||
"instances": [],
|
||||
"animations": [],
|
||||
"ranges": [],
|
||||
"layerMask": 268435455,
|
||||
"alphaIndex": 1.7976931348623157e+308,
|
||||
"hasVertexAlpha": false,
|
||||
"overlayAlpha": 0.5,
|
||||
"overlayColor": [
|
||||
1,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"applyFog": true
|
||||
}
|
||||
]
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -2,9 +2,9 @@
|
|||
// Created by Wouter Groeneveld on 11/07/20.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/scene.h>
|
||||
#include <libgba-sprite-engine/renderer/gba_engine.h>
|
||||
#include <libgba-sprite-engine/palette/palette_manager.h>
|
||||
#include <libgba-bitmap-engine/scene.h>
|
||||
#include <libgba-bitmap-engine/renderer/gba_engine.h>
|
||||
#include <libgba-bitmap-engine/palette/palette_manager.h>
|
||||
|
||||
#include "monkey.h"
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,11 +2,12 @@
|
|||
// Created by Wouter Groeneveld on 11/07/20.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/background/text_stream.h>
|
||||
#include <libgba-bitmap-engine/background/text_stream.h>
|
||||
#include "monkey.h"
|
||||
|
||||
const unsigned short pal[4] __attribute__((aligned(4))) = {
|
||||
0x0000, 0xFFFF, 0x3AE2
|
||||
// BLACK, [white->black] from 0xFFFF / 252
|
||||
const unsigned short pal[253] __attribute__((aligned(4))) = {
|
||||
0x0000, 65535,32767,21845,16383,13107,10922,9362,8191,7281,6553,5957,5461,5041,4681,4369,4095,3855,3640,3449,3276,3120,2978,2849,2730,2621,2520,2427,2340,2259,2184,2114,2047,1985,1927,1872,1820,1771,1724,1680,1638,1598,1560,1524,1489,1456,1424,1394,1365,1337,1310,1285,1260,1236,1213,1191,1170,1149,1129,1110,1092,1074,1057,1040,1023,1008,992,978,963,949,936,923,910,897,885,873,862,851,840,829,819,809,799,789,780,771,762,753,744,736,728,720,712,704,697,689,682,675,668,661,655,648,642,636,630,624,618,612,606,601,595,590,585,579,574,569,564,560,555,550,546,541,537,532,528,524,520,516,511,508,504,500,496,492,489,485,481,478,474,471,468,464,461,458,455,451,448,445,442,439,436,434,431,428,425,422,420,417,414,412,409,407,404,402,399,397,394,392,390,387,385,383,381,378,376,374,372,370,368,366,364,362,360,358,356,354,352,350,348,346,344,343,341,339,337,336,334,332,330,329,327,326,324,322,321,319,318,316,315,313,312,310,309,307,306,304,303,302,300,299,297,296,295,293,292,291,289,288,287,286,284,283,282,281,280,278,277,276,275,274,273,271,270,269,268,267,266,265,264,263,262,261,260
|
||||
};
|
||||
|
||||
std::vector<Mesh*> MonkeyScene::meshes() {
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
#ifndef GBA_BITMAP_ENGINE_PROJECT_MONKEY_H
|
||||
#define GBA_BITMAP_ENGINE_PROJECT_MONKEY_H
|
||||
|
||||
#include <libgba-sprite-engine/scene.h>
|
||||
#include <libgba-sprite-engine/mesh.h>
|
||||
#include <libgba-sprite-engine/camera.h>
|
||||
#include <libgba-sprite-engine/renderer/gba_engine.h>
|
||||
#include <libgba-bitmap-engine/scene.h>
|
||||
#include <libgba-bitmap-engine/mesh.h>
|
||||
#include <libgba-bitmap-engine/camera.h>
|
||||
#include <libgba-bitmap-engine/renderer/gba_engine.h>
|
||||
#include <memory>
|
||||
|
||||
// forward declaration of generated mesh.cpp file
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
project(textures)
|
||||
|
||||
add_executable(${PROJECT_NAME}.elf
|
||||
src/main.cpp
|
||||
src/mesh.cpp
|
||||
src/texturescene.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}.elf gba-bitmap-engine)
|
||||
|
||||
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
|
||||
COMMAND ${CMAKE_OBJCOPY} -v -O binary ${PROJECT_NAME}.elf ${PROJECT_NAME}.gba
|
||||
)
|
Binary file not shown.
After Width: | Height: | Size: 308 B |
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// Created by Wouter Groeneveld on 11/07/20.
|
||||
//
|
||||
|
||||
#include <libgba-bitmap-engine/scene.h>
|
||||
#include <libgba-bitmap-engine/renderer/gba_engine.h>
|
||||
#include <libgba-bitmap-engine/palette/palette_manager.h>
|
||||
|
||||
#include "texturescene.h"
|
||||
|
||||
int main() {
|
||||
std::shared_ptr<GBAEngine> engine(new GBAEngine());
|
||||
engine.get()->setRenderer(new RasterizerRenderer());
|
||||
|
||||
TextureScene* startScene = new TextureScene(engine);
|
||||
engine->setScene(startScene);
|
||||
|
||||
while (true) {
|
||||
engine->update();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
#include <libgba-bitmap-engine/mesh.h>
|
||||
Mesh* createMesh() {
|
||||
auto obj = new Mesh();
|
||||
obj->add(VectorFx::fromFloat(0.5, -0.5, 0.5), VectorFx::fromFloat(0, 0, 1), 1, 1);
|
||||
obj->add(VectorFx::fromFloat(-0.5, -0.5, 0.5), VectorFx::fromFloat(0, 0, 1), 1, 0);
|
||||
obj->add(VectorFx::fromFloat(-0.5, 0.5, 0.5), VectorFx::fromFloat(0, 0, 1), 0, 1);
|
||||
obj->add(VectorFx::fromFloat(0.5, 0.5, 0.5), VectorFx::fromFloat(0, 0, 1), 1, 0);
|
||||
obj->add(VectorFx::fromFloat(0.5, 0.5, -0.5), VectorFx::fromFloat(0, 0, -1), 0, 0);
|
||||
obj->add(VectorFx::fromFloat(-0.5, 0.5, -0.5), VectorFx::fromFloat(0, 0, -1), 0, 1);
|
||||
obj->add(VectorFx::fromFloat(-0.5, -0.5, -0.5), VectorFx::fromFloat(0, 0, -1), 1, 0);
|
||||
obj->add(VectorFx::fromFloat(0.5, -0.5, -0.5), VectorFx::fromFloat(0, 0, -1), 0, 1);
|
||||
obj->add(VectorFx::fromFloat(0.5, 0.5, -0.5), VectorFx::fromFloat(1, 0, 0), 1, 1);
|
||||
obj->add(VectorFx::fromFloat(0.5, -0.5, -0.5), VectorFx::fromFloat(1, 0, 0), 1, 0);
|
||||
obj->add(VectorFx::fromFloat(0.5, -0.5, 0.5), VectorFx::fromFloat(1, 0, 0), 0, 1);
|
||||
obj->add(VectorFx::fromFloat(0.5, 0.5, 0.5), VectorFx::fromFloat(1, 0, 0), 1, 0);
|
||||
obj->add(VectorFx::fromFloat(-0.5, 0.5, 0.5), VectorFx::fromFloat(-1, 0, 0), 0, 0);
|
||||
obj->add(VectorFx::fromFloat(-0.5, -0.5, 0.5), VectorFx::fromFloat(-1, 0, 0), 0, 1);
|
||||
obj->add(VectorFx::fromFloat(-0.5, -0.5, -0.5), VectorFx::fromFloat(-1, 0, 0), 1, 0);
|
||||
obj->add(VectorFx::fromFloat(-0.5, 0.5, -0.5), VectorFx::fromFloat(-1, 0, 0), 0, 1);
|
||||
obj->add(VectorFx::fromFloat(-0.5, 0.5, 0.5), VectorFx::fromFloat(0, 1, 0), 1, 1);
|
||||
obj->add(VectorFx::fromFloat(-0.5, 0.5, -0.5), VectorFx::fromFloat(0, 1, 0), 1, 0);
|
||||
obj->add(VectorFx::fromFloat(0.5, 0.5, -0.5), VectorFx::fromFloat(0, 1, 0), 0, 1);
|
||||
obj->add(VectorFx::fromFloat(0.5, 0.5, 0.5), VectorFx::fromFloat(0, 1, 0), 1, 0);
|
||||
obj->add(VectorFx::fromFloat(0.5, -0.5, 0.5), VectorFx::fromFloat(0, -1, 0), 0, 0);
|
||||
obj->add(VectorFx::fromFloat(0.5, -0.5, -0.5), VectorFx::fromFloat(0, -1, 0), 0, 1);
|
||||
obj->add(VectorFx::fromFloat(-0.5, -0.5, -0.5), VectorFx::fromFloat(0, -1, 0), 1, 0);
|
||||
obj->add(VectorFx::fromFloat(-0.5, -0.5, 0.5), VectorFx::fromFloat(0, -1, 0), 0, 1);
|
||||
obj->addFace(0, 1, 2);
|
||||
obj->addFace(0, 2, 3);
|
||||
obj->addFace(4, 5, 6);
|
||||
obj->addFace(4, 6, 7);
|
||||
obj->addFace(8, 9, 10);
|
||||
obj->addFace(8, 10, 11);
|
||||
obj->addFace(12, 13, 14);
|
||||
obj->addFace(12, 14, 15);
|
||||
obj->addFace(16, 17, 18);
|
||||
obj->addFace(16, 18, 19);
|
||||
obj->addFace(20, 21, 22);
|
||||
obj->addFace(20, 22, 23);
|
||||
obj->setPosition(VectorFx::fromInt(0, 0, 0));
|
||||
return obj;
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
//
|
||||
// Created by Wouter Groeneveld on 16/07/20.
|
||||
//
|
||||
|
||||
#ifndef GBA_BITMAP_ENGINE_PROJECT_TEXTURE_H
|
||||
#define GBA_BITMAP_ENGINE_PROJECT_TEXTURE_H
|
||||
|
||||
|
||||
//{{BLOCK(questionmark)
|
||||
|
||||
//======================================================================
|
||||
//
|
||||
// questionmark, 16x16@16,
|
||||
// + 4 tiles not compressed
|
||||
// Total size: 512 = 512
|
||||
//
|
||||
// Time-stamp: 2020-07-15, 20:38:24
|
||||
// Exported by Cearn's GBA Image Transmogrifier, v0.8.6
|
||||
// ( http://www.coranac.com/projects/#grit )
|
||||
//
|
||||
//======================================================================
|
||||
|
||||
// BLUE: 2
|
||||
// DARK: 3
|
||||
// LIGHT: 4
|
||||
// BLACK: 0
|
||||
|
||||
#define QUESTIONMARK_TILES_LENGTH 256
|
||||
|
||||
const unsigned short questionmarkTiles[QUESTIONMARK_TILES_LENGTH] __attribute__((aligned(4)))=
|
||||
{
|
||||
2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2,
|
||||
3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0,
|
||||
3, 4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 0,
|
||||
3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 0,
|
||||
3, 4, 4, 4, 3, 3, 0, 0, 3, 3, 3, 0, 4, 4, 4, 0,
|
||||
3, 4, 4, 4, 3, 3, 0, 4, 3, 3, 3, 0, 4, 4, 4, 0,
|
||||
3, 4, 4, 4, 3, 3, 0, 4, 3, 3, 3, 0, 4, 4, 4, 0,
|
||||
3, 4, 4, 4, 4, 0, 0, 4, 3, 0, 0, 0, 4, 4, 4, 0,
|
||||
3, 4, 4, 4, 4, 4, 4, 3, 3, 0, 0, 0, 4, 4, 4, 0,
|
||||
3, 4, 4, 4, 4, 4, 4, 3, 3, 0, 4, 4, 4, 4, 4, 0,
|
||||
3, 4, 4, 4, 4, 4, 4, 4, 0, 0, 4, 4, 4, 4, 4, 0,
|
||||
3, 4, 4, 4, 4, 4, 4, 3, 3, 4, 4, 4, 4, 4, 4, 0,
|
||||
3, 4, 4, 4, 4, 4, 4, 3, 3, 0, 4, 4, 4, 4, 4, 0,
|
||||
3, 4, 0, 4, 4, 4, 4, 4, 0, 0, 4, 4, 4, 0, 4, 0,
|
||||
3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
//}}BLOCK(questionmark)
|
||||
|
||||
//{{BLOCK(Shared)
|
||||
|
||||
//======================================================================
|
||||
//
|
||||
// Shared, 16x16@8,
|
||||
// + palette 4 entries, not compressed
|
||||
// Total size: 8 = 8
|
||||
//
|
||||
// Time-stamp: 2020-07-15, 20:38:24
|
||||
// Exported by Cearn's GBA Image Transmogrifier, v0.8.6
|
||||
// ( http://www.coranac.com/projects/#grit )
|
||||
//
|
||||
//======================================================================
|
||||
|
||||
unsigned short color(unsigned int r, unsigned int g, unsigned int b) {
|
||||
r = (float) r / 255 * 31;
|
||||
g = (float) g / 255 * 31;
|
||||
b = (float) b / 255 * 31;
|
||||
|
||||
unsigned short c = (b & 0x1f) << 10;
|
||||
c |= (g & 0x1f) << 5;
|
||||
c |= (r & 0x1f);
|
||||
return c;
|
||||
}
|
||||
|
||||
const unsigned short sharedPal[] __attribute__((aligned(4)))=
|
||||
{
|
||||
0x0000, color(255, 255, 255), color(92, 148, 252), color(200, 76, 12), color(252, 152, 56)
|
||||
};
|
||||
|
||||
//}}BLOCK(Shared)
|
||||
|
||||
|
||||
#endif //GBA_BITMAP_ENGINE_PROJECT_TEXTURE_H
|
|
@ -0,0 +1,25 @@
|
|||
//
|
||||
// Created by Wouter Groeneveld on 16/07/20.
|
||||
//
|
||||
|
||||
#include "texturescene.h"
|
||||
#include "texturedata.h"
|
||||
|
||||
std::vector<Mesh*> TextureScene::meshes() {
|
||||
return { box.get() };
|
||||
}
|
||||
|
||||
Camera TextureScene::camera() {
|
||||
return Camera(VectorFx::fromInt(0, 0, 10), VectorFx::fromInt(0, 0, 0));
|
||||
}
|
||||
|
||||
void TextureScene::load() {
|
||||
foregroundPalette = std::unique_ptr<ForegroundPaletteManager>(new ForegroundPaletteManager());
|
||||
backgroundPalette = std::unique_ptr<BackgroundPaletteManager>(new BackgroundPaletteManager(sharedPal, sizeof(sharedPal)));
|
||||
|
||||
box = std::unique_ptr<Mesh>(createMesh());
|
||||
}
|
||||
|
||||
void TextureScene::tick(u16 keys) {
|
||||
box->rotate(10, 10);
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
//
|
||||
// Created by Wouter Groeneveld on 16/07/20.
|
||||
//
|
||||
|
||||
#ifndef GBA_BITMAP_ENGINE_PROJECT_TEXTURESCENE_H
|
||||
#define GBA_BITMAP_ENGINE_PROJECT_TEXTURESCENE_H
|
||||
|
||||
#include <libgba-bitmap-engine/scene.h>
|
||||
#include <libgba-bitmap-engine/mesh.h>
|
||||
#include <libgba-bitmap-engine/camera.h>
|
||||
#include <libgba-bitmap-engine/renderer/gba_engine.h>
|
||||
#include <memory>
|
||||
|
||||
// forward declaration of generated mesh.cpp file
|
||||
Mesh* createMesh();
|
||||
|
||||
class TextureScene : public Scene {
|
||||
std::unique_ptr<Mesh> box;
|
||||
|
||||
public:
|
||||
|
||||
TextureScene(std::shared_ptr<GBAEngine> engine) : Scene(engine) {}
|
||||
|
||||
void load() override;
|
||||
void tick(u16 keys) override;
|
||||
std::vector<Mesh*> meshes() override;
|
||||
Camera camera() override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //GBA_BITMAP_ENGINE_PROJECT_TEXTURESCENE_H
|
|
@ -23,7 +23,7 @@ add_library(${PROJECT_NAME}
|
|||
src/renderer/pixelrenderer.cpp
|
||||
src/renderer/wirerenderer.cpp
|
||||
src/math.cpp
|
||||
src/sound_control.cpp src/scene.cpp src/timer.cpp src/vectorfx.cpp src/mesh.cpp src/renderer/raserizerrenderer.cpp)
|
||||
src/sound_control.cpp src/scene.cpp src/timer.cpp src/vectorfx.cpp src/mesh.cpp src/renderer/rasterizerrenderer.cpp)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include <libgba-sprite-engine/gba/tonc_types.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_types.h>
|
||||
|
||||
#define TEXT_WIDTH 8
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
#ifndef GBA_BITMAP_ENGINE_PROJECT_CAMERA_H
|
||||
#define GBA_BITMAP_ENGINE_PROJECT_CAMERA_H
|
||||
|
||||
#include <libgba-sprite-engine/vectorfx.h>
|
||||
#include <libgba-bitmap-engine/vectorfx.h>
|
||||
|
||||
class Camera {
|
||||
private:
|
|
@ -0,0 +1,32 @@
|
|||
//
|
||||
// Created by Wouter Groeneveld on 15/07/20.
|
||||
//
|
||||
|
||||
#ifndef GBA_BITMAP_ENGINE_PROJECT_FACE_H
|
||||
#define GBA_BITMAP_ENGINE_PROJECT_FACE_H
|
||||
|
||||
#include <libgba-bitmap-engine/vectorfx.h>
|
||||
|
||||
class Face {
|
||||
private:
|
||||
int theA, theB, theC;
|
||||
VectorFx norm;
|
||||
|
||||
public:
|
||||
Face(int newA, int newB, int newC, const Vertex& va, const Vertex& vb, const Vertex& vc) : theA(newA), theB(newB), theC(newC), norm(VectorFx()) {
|
||||
normalize(va, vb, vc);
|
||||
}
|
||||
|
||||
inline const VectorFx& normal() const { return norm; };
|
||||
inline int a() { return theA; };
|
||||
inline int b() { return theB; };
|
||||
inline int c() { return theC; };
|
||||
|
||||
inline void normalize(const Vertex& va, const Vertex& vb, const Vertex& vc) {
|
||||
norm = (va.normal() + vb.normal() + vc.normal()).scale(fxdiv(int2fx(1), int2fx(3)));
|
||||
norm.normalize();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //GBA_BITMAP_ENGINE_PROJECT_FACE_H
|
|
@ -6,8 +6,8 @@
|
|||
#ifndef GBA_BITMAP_ENGINE_PROJECT_TONC_VIDEO_H
|
||||
#define GBA_BITMAP_ENGINE_PROJECT_TONC_VIDEO_H
|
||||
|
||||
#include <libgba-sprite-engine/gba/tonc_types.h>
|
||||
#include <libgba-sprite-engine/gba/toolbox.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_types.h>
|
||||
#include <libgba-bitmap-engine/gba/toolbox.h>
|
||||
|
||||
void bmp8_plot(int x, int y, u32 clr, void *dstBase, uint dstP);
|
||||
|
|
@ -5,11 +5,11 @@
|
|||
#ifndef GBA_BITMAP_ENGINE_PROJECT_MATH_H
|
||||
#define GBA_BITMAP_ENGINE_PROJECT_MATH_H
|
||||
|
||||
#include <libgba-sprite-engine/gba/tonc_types.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_types.h>
|
||||
#ifdef CODE_COMPILED_AS_PART_OF_TEST
|
||||
#include <libgba-sprite-engine/gba/tonc_math_stub.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_math_stub.h>
|
||||
#else
|
||||
#include <libgba-sprite-engine/gba/tonc_math.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_math.h>
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
|
@ -6,15 +6,15 @@
|
|||
#define GBA_BITMAP_ENGINE_PROJECT_GBAMATRIX_H
|
||||
|
||||
#define MATRIX_DIMENSION 16
|
||||
#include <libgba-sprite-engine/math.h>
|
||||
#include <libgba-sprite-engine/vectorfx.h>
|
||||
#include <libgba-bitmap-engine/math.h>
|
||||
#include <libgba-bitmap-engine/vectorfx.h>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#ifdef CODE_COMPILED_AS_PART_OF_TEST
|
||||
#include <libgba-sprite-engine/gba/tonc_math_stub.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_math_stub.h>
|
||||
#else
|
||||
#include <libgba-sprite-engine/gba/tonc_math.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_math.h>
|
||||
#endif
|
||||
|
||||
class MatrixFx {
|
||||
|
@ -115,6 +115,13 @@ public:
|
|||
return "(" + mstr(12) + "," + mstr(13) + "," + mstr(14) + "," + mstr(15) +")";
|
||||
}
|
||||
|
||||
inline static VectorFx transformNormal(const VectorFx& vector, const MatrixFx &transformation) {
|
||||
FIXED x = fxmul(vector.x(), transformation.mAt(0)) + fxmul(vector.y(), transformation.mAt(4)) + fxmul(vector.z(), transformation.mAt(8));
|
||||
FIXED y = fxmul(vector.x(), transformation.mAt(1)) + fxmul(vector.y(), transformation.mAt(5)) + fxmul(vector.z(), transformation.mAt(9));
|
||||
FIXED z = fxmul(vector.x(), transformation.mAt(2)) + fxmul(vector.y(), transformation.mAt(6)) + fxmul(vector.z(), transformation.mAt(10));
|
||||
return VectorFx(x, y, z);
|
||||
}
|
||||
|
||||
inline static VectorFx transformCoordinates(const VectorFx &vector, const MatrixFx &transformation) {
|
||||
FIXED x = fxmul(vector.x(), transformation.mAt(0)) + fxmul(vector.y(), transformation.mAt(4)) + fxmul(vector.z(), transformation.mAt(8)) + transformation.mAt(12);
|
||||
FIXED y = fxmul(vector.x(), transformation.mAt(1)) + fxmul(vector.y(), transformation.mAt(5)) + fxmul(vector.z(), transformation.mAt(9)) + transformation.mAt(13);
|
|
@ -5,34 +5,33 @@
|
|||
#ifndef GBA_BITMAP_ENGINE_PROJECT_MESH_H
|
||||
#define GBA_BITMAP_ENGINE_PROJECT_MESH_H
|
||||
|
||||
#include "vectorfx.h"
|
||||
#include <libgba-bitmap-engine/vertex.h>
|
||||
#include <libgba-bitmap-engine/vectorfx.h>
|
||||
#include <libgba-bitmap-engine/face.h>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
typedef struct {
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
} Face;
|
||||
|
||||
class Mesh {
|
||||
private:
|
||||
VectorFx pos;
|
||||
VectorFx rot;
|
||||
u8 cIndex;
|
||||
|
||||
std::vector<std::unique_ptr<VectorFx>> verticesArr;
|
||||
std::vector<Face> facesArr;
|
||||
std::vector<std::unique_ptr<Vertex>> verticesArr;
|
||||
std::vector<std::unique_ptr<Face>> facesArr;
|
||||
|
||||
public:
|
||||
|
||||
void add(VectorFx coords, VectorFx normal);
|
||||
void add(VectorFx coords, VectorFx normal, float u, float v);
|
||||
void add(VectorFx v);
|
||||
void addFace(Face f);
|
||||
inline std::vector<std::unique_ptr<VectorFx>> const& vertices() const {
|
||||
void addFace(int a, int b, int c);
|
||||
|
||||
inline std::vector<std::unique_ptr<Vertex>> const& vertices() const {
|
||||
return verticesArr;
|
||||
}
|
||||
|
||||
inline std::vector<Face> const& faces() const {
|
||||
inline std::vector<std::unique_ptr<Face>> const& faces() const {
|
||||
return facesArr;
|
||||
}
|
||||
|
|
@ -5,8 +5,8 @@
|
|||
#ifndef GBA_SPRITE_ENGINE_PALETTE_MANAGER_H
|
||||
#define GBA_SPRITE_ENGINE_PALETTE_MANAGER_H
|
||||
|
||||
#include <libgba-sprite-engine/gba/tonc_memmap.h>
|
||||
#include <libgba-sprite-engine/gba/tonc_types.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_memmap.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_types.h>
|
||||
#include "combined_palette.h"
|
||||
|
||||
#define PALETTE_BANK_SIZE 16
|
|
@ -6,14 +6,14 @@
|
|||
#define GBA_SPRITE_ENGINE_GBAENGINE_H
|
||||
|
||||
|
||||
#include <libgba-sprite-engine/gba/tonc_memmap.h>
|
||||
#include <libgba-sprite-engine/gba/tonc_memmap.h>
|
||||
#include <libgba-sprite-engine/vectorfx.h>
|
||||
#include <libgba-sprite-engine/matrixfx.h>
|
||||
#include <libgba-sprite-engine/renderer/renderer.h>
|
||||
#include "libgba-sprite-engine/scene.h"
|
||||
#include "libgba-sprite-engine/sound_control.h"
|
||||
#include "libgba-sprite-engine/timer.h"
|
||||
#include <libgba-bitmap-engine/gba/tonc_memmap.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_memmap.h>
|
||||
#include <libgba-bitmap-engine/vectorfx.h>
|
||||
#include <libgba-bitmap-engine/matrixfx.h>
|
||||
#include <libgba-bitmap-engine/renderer/renderer.h>
|
||||
#include <libgba-bitmap-engine/scene.h>
|
||||
#include <libgba-bitmap-engine/sound_control.h>
|
||||
#include <libgba-bitmap-engine/timer.h>
|
||||
|
||||
|
||||
const unsigned int black[VRAM_PAGE_SIZE] = {};
|
|
@ -5,8 +5,8 @@
|
|||
#ifndef GBA_BITMAP_ENGINE_PROJECT_RENDERER_H
|
||||
#define GBA_BITMAP_ENGINE_PROJECT_RENDERER_H
|
||||
|
||||
#include <libgba-sprite-engine/matrixfx.h>
|
||||
#include <libgba-sprite-engine/mesh.h>
|
||||
#include <libgba-bitmap-engine/matrixfx.h>
|
||||
#include <libgba-bitmap-engine/mesh.h>
|
||||
|
||||
class GBAEngine;
|
||||
|
||||
|
@ -15,26 +15,27 @@ protected:
|
|||
std::shared_ptr<GBAEngine> engine;
|
||||
|
||||
public:
|
||||
virtual void render(const MatrixFx &transformationMatrix, const Mesh* mesh) = 0;
|
||||
virtual void render(const MatrixFx &transformationMatrix, const MatrixFx &worldView, const Mesh* mesh) = 0;
|
||||
};
|
||||
|
||||
class PixelRenderer : public Renderer {
|
||||
public:
|
||||
void render(const MatrixFx &transformationMatrix, const Mesh* mesh) override;
|
||||
void render(const MatrixFx &transformationMatrix, const MatrixFx &worldView, const Mesh* mesh) override;
|
||||
};
|
||||
|
||||
class WiredRenderer : public Renderer {
|
||||
public:
|
||||
void render(const MatrixFx &transformationMatrix, const Mesh* mesh) override;
|
||||
void render(const MatrixFx &transformationMatrix, const MatrixFx &worldView, const Mesh* mesh) override;
|
||||
};
|
||||
|
||||
class RasterizerRenderer : public Renderer {
|
||||
private:
|
||||
void plotTriangle(const VectorFx& p1, const VectorFx& p2, const VectorFx& p3, COLOR color);
|
||||
void processScanLine(FIXED y, const VectorFx& pa, const VectorFx& pb, const VectorFx& pc, const VectorFx& pd, COLOR color);
|
||||
bool backFaceCull(const Face* face, const MatrixFx& worldView);
|
||||
|
||||
public:
|
||||
void render(const MatrixFx &transformationMatrix, const Mesh* mesh) override;
|
||||
void render(const MatrixFx &transformationMatrix, const MatrixFx &worldView, const Mesh* mesh) override;
|
||||
};
|
||||
|
||||
#endif //GBA_BITMAP_ENGINE_PROJECT_RENDERER_H
|
|
@ -8,9 +8,9 @@
|
|||
#include <vector>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <libgba-sprite-engine/camera.h>
|
||||
#include <libgba-sprite-engine/mesh.h>
|
||||
#include <libgba-sprite-engine/palette/palette_manager.h>
|
||||
#include <libgba-bitmap-engine/camera.h>
|
||||
#include <libgba-bitmap-engine/mesh.h>
|
||||
#include <libgba-bitmap-engine/palette/palette_manager.h>
|
||||
|
||||
class GBAEngine;
|
||||
|
|
@ -5,10 +5,10 @@
|
|||
#ifndef GBA_SPRITE_ENGINE_SOUND_H
|
||||
#define GBA_SPRITE_ENGINE_SOUND_H
|
||||
|
||||
#include <libgba-sprite-engine/gba/tonc_types.h>
|
||||
#include <libgba-sprite-engine/gba/tonc_memdef.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_types.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_memdef.h>
|
||||
#include <memory>
|
||||
#include <libgba-sprite-engine/gba/tonc_memmap.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_memmap.h>
|
||||
|
||||
#define CLOCK 16777216
|
||||
#define CYCLES_PER_BLANK 280806
|
|
@ -9,13 +9,13 @@
|
|||
|
||||
#include <string>
|
||||
#include <deque>
|
||||
#include <libgba-sprite-engine/gba/tonc_bios.h>
|
||||
#include <libgba-sprite-engine/math.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_bios.h>
|
||||
#include <libgba-bitmap-engine/math.h>
|
||||
|
||||
#ifdef CODE_COMPILED_AS_PART_OF_TEST
|
||||
#include <libgba-sprite-engine/gba/tonc_math_stub.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_math_stub.h>
|
||||
#else
|
||||
#include <libgba-sprite-engine/gba/tonc_math.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_math.h>
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
//
|
||||
// Created by Wouter Groeneveld on 15/07/20.
|
||||
//
|
||||
|
||||
#ifndef GBA_BITMAP_ENGINE_PROJECT_VERTEX_H
|
||||
#define GBA_BITMAP_ENGINE_PROJECT_VERTEX_H
|
||||
|
||||
#include <libgba-bitmap-engine/vectorfx.h>
|
||||
|
||||
class Vertex {
|
||||
private:
|
||||
VectorFx coordinates;
|
||||
VectorFx norm;
|
||||
FIXED tU, tV;
|
||||
|
||||
public:
|
||||
Vertex(const VectorFx& coord) : coordinates(coord), norm(VectorFx()), tU(0), tV(0) {}
|
||||
Vertex(const VectorFx& coord, const VectorFx& theNorm) : coordinates(coord), norm(theNorm), tU(0), tV(0) {}
|
||||
Vertex(const VectorFx& coord, const VectorFx& theNorm, float theU, float theV) : coordinates(coord), norm(theNorm), tU(float2fx(theU)), tV(float2fx(theV)) {}
|
||||
|
||||
inline const VectorFx& coords() const { return coordinates; }
|
||||
inline const VectorFx& normal() const { return norm; }
|
||||
inline FIXED u() { return tU; }
|
||||
inline FIXED v() { return tV; }
|
||||
};
|
||||
|
||||
#endif //GBA_BITMAP_ENGINE_PROJECT_VERTEX_H
|
|
@ -2,9 +2,9 @@
|
|||
// Created by Wouter Groeneveld on 28/07/18.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/gba/tonc_memmap.h>
|
||||
#include <libgba-sprite-engine/palette/palette_manager.h>
|
||||
#include <libgba-sprite-engine/background/text_stream.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_memmap.h>
|
||||
#include <libgba-bitmap-engine/palette/palette_manager.h>
|
||||
#include <libgba-bitmap-engine/background/text_stream.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//! \author J Vijn
|
||||
//! \date 20071130 - 20090801
|
||||
|
||||
#include <libgba-sprite-engine/gba/tonc_asminc.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_asminc.h>
|
||||
|
||||
@ === SoftReset [00h] =================================================
|
||||
@ DECL: void SoftReset();
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
//
|
||||
|
||||
//! Plot a single pixel on a 8-bit buffer
|
||||
#include <libgba-sprite-engine/gba/tonc_types.h>
|
||||
#include <libgba-sprite-engine/gba/tonc_core.h>
|
||||
#include <libgba-sprite-engine/gba/toolbox.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_types.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_core.h>
|
||||
#include <libgba-bitmap-engine/gba/toolbox.h>
|
||||
|
||||
/*!
|
||||
\param x X-coord.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Created by Wouter Groeneveld on 08/07/20.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/math.h>
|
||||
#include <libgba-bitmap-engine/math.h>
|
||||
|
||||
FIXED HALF = float2fx(0.5);
|
||||
FIXED ONE = int2fx(1);
|
||||
|
|
|
@ -2,14 +2,26 @@
|
|||
// Created by Wouter Groeneveld on 08/07/20.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/mesh.h>
|
||||
#include <libgba-bitmap-engine/mesh.h>
|
||||
#include <memory>
|
||||
|
||||
|
||||
void Mesh::add(VectorFx v) {
|
||||
verticesArr.push_back(std::unique_ptr<VectorFx>(new VectorFx(v)));
|
||||
verticesArr.push_back(std::unique_ptr<Vertex>(new Vertex(v)));
|
||||
}
|
||||
|
||||
void Mesh::addFace(Face f) {
|
||||
facesArr.push_back(f);
|
||||
void Mesh::add(VectorFx coords, VectorFx normal) {
|
||||
verticesArr.push_back(std::unique_ptr<Vertex>(new Vertex(coords, normal)));
|
||||
}
|
||||
|
||||
void Mesh::add(VectorFx coords, VectorFx normal, float u, float v) {
|
||||
verticesArr.push_back(std::unique_ptr<Vertex>(new Vertex(coords, normal, u, v)));
|
||||
}
|
||||
|
||||
void Mesh::addFace(int a, int b, int c) {
|
||||
auto &vertexA = verticesArr[a];
|
||||
auto &vertexB = verticesArr[b];
|
||||
auto &vertexC = verticesArr[c];
|
||||
|
||||
facesArr.push_back(std::unique_ptr<Face>(new Face(a, b, c, *vertexA, *vertexB, *vertexC)));
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
//
|
||||
|
||||
|
||||
#include <libgba-sprite-engine/palette/palette_manager.h>
|
||||
#include <libgba-bitmap-engine/palette/palette_manager.h>
|
||||
|
||||
void CombinedPalette::increaseBrightness(PaletteManager& palette, int bank, int index, u32 intensity) {
|
||||
auto current = palette.get(bank, index);
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
//
|
||||
|
||||
#ifdef CODE_COMPILED_AS_PART_OF_TEST
|
||||
#include <libgba-sprite-engine/gba/tonc_core_stub.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_core_stub.h>
|
||||
#else
|
||||
#include <libgba-sprite-engine/gba/tonc_core.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_core.h>
|
||||
#endif
|
||||
#include <libgba-sprite-engine/palette/palette_manager.h>
|
||||
#include <libgba-bitmap-engine/palette/palette_manager.h>
|
||||
|
||||
const COLOR defaultPaletteData[PALETTE_MAX_SIZE] __attribute__((aligned(4))) = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
// Created by Wouter Groeneveld on 28/07/18.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/gba/tonc_memdef.h>
|
||||
#include <libgba-sprite-engine/gba/tonc_video.h>
|
||||
#include <libgba-sprite-engine/renderer/gba_engine.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_memdef.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_video.h>
|
||||
#include <libgba-bitmap-engine/renderer/gba_engine.h>
|
||||
#include <cstring>
|
||||
#include <libgba-sprite-engine/gba/tonc_core.h>
|
||||
#include <libgba-sprite-engine/matrixfx.h>
|
||||
#include <libgba-sprite-engine/background/text_stream.h>
|
||||
#include <libgba-sprite-engine/mesh.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_core.h>
|
||||
#include <libgba-bitmap-engine/matrixfx.h>
|
||||
#include <libgba-bitmap-engine/background/text_stream.h>
|
||||
#include <libgba-bitmap-engine/mesh.h>
|
||||
|
||||
std::unique_ptr<SoundControl> GBAEngine::activeChannelA;
|
||||
std::unique_ptr<SoundControl> GBAEngine::activeChannelB;
|
||||
|
@ -187,15 +187,17 @@ VectorFx GBAEngine::project(const VectorFx &coord, const MatrixFx &transMat) {
|
|||
return VectorFx(x, y, point.z());
|
||||
}
|
||||
|
||||
// does the mesh rendering - to write mem before flipping
|
||||
void GBAEngine::render() {
|
||||
// I tried optimizing this; without camera changes it does not need to be recalculated each time
|
||||
// However, 0 FPS difference... Most performance issues are inside mesh render()
|
||||
auto viewMatrix = MatrixFx::lookAtLH(currentCamera.getPosition(), currentCamera.getTarget(), VectorFx::up());
|
||||
|
||||
for(auto& mesh :currentScene->meshes()) {
|
||||
auto worldMatrix = MatrixFx::rotationYawPitchRoll(mesh->roty(), mesh->rotx(), mesh->rotz()) * MatrixFx::translation(mesh->position());
|
||||
auto transformMatrix = worldMatrix * viewMatrix * projectionMatrix;
|
||||
auto worldView = worldMatrix * viewMatrix;
|
||||
auto transformMatrix = worldView * projectionMatrix;
|
||||
|
||||
renderer->render(transformMatrix, mesh);
|
||||
renderer->render(transformMatrix, worldView, mesh);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
// Created by Wouter Groeneveld on 11/07/20.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/renderer/renderer.h>
|
||||
#include <libgba-sprite-engine/renderer/gba_engine.h>
|
||||
#include <libgba-bitmap-engine/renderer/renderer.h>
|
||||
#include <libgba-bitmap-engine/renderer/gba_engine.h>
|
||||
|
||||
void PixelRenderer::render(const MatrixFx &transformationMatrix, const Mesh* mesh) {
|
||||
void PixelRenderer::render(const MatrixFx &transformationMatrix, const MatrixFx &worldView, const Mesh* mesh) {
|
||||
for (auto &vertex : mesh->vertices()) {
|
||||
auto projectedPoint = engine->project(*vertex.get(), transformationMatrix);
|
||||
auto coords = vertex.get()->coords();
|
||||
auto projectedPoint = engine->project(coords, transformationMatrix);
|
||||
engine->plotPixel(projectedPoint, mesh->colorIndex());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
// Created by Wouter Groeneveld on 11/07/20.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/renderer/renderer.h>
|
||||
#include <libgba-sprite-engine/renderer/gba_engine.h>
|
||||
#include <libgba-sprite-engine/math.h>
|
||||
#include <libgba-sprite-engine/background/text_stream.h>
|
||||
#include <libgba-bitmap-engine/renderer/renderer.h>
|
||||
#include <libgba-bitmap-engine/renderer/gba_engine.h>
|
||||
#include <libgba-bitmap-engine/math.h>
|
||||
#include <libgba-bitmap-engine/background/text_stream.h>
|
||||
|
||||
// drawing line between 2 points from left to right
|
||||
// papb -> pcpd
|
||||
|
@ -64,19 +64,28 @@ void RasterizerRenderer::plotTriangle(const VectorFx& pt1, const VectorFx& pt2,
|
|||
}
|
||||
}
|
||||
|
||||
void RasterizerRenderer::render(const MatrixFx &transformationMatrix, const Mesh *mesh) {
|
||||
bool RasterizerRenderer::backFaceCull(const Face *face, const MatrixFx &worldView) {
|
||||
auto transformedNormal = MatrixFx::transformNormal(face->normal(), worldView);
|
||||
return transformedNormal.z() < 0;
|
||||
}
|
||||
|
||||
void RasterizerRenderer::render(const MatrixFx &transformationMatrix, const MatrixFx &worldView, const Mesh *mesh) {
|
||||
bool colorSwitch = false;
|
||||
int i = 0;
|
||||
for (auto &face : mesh->faces()) {
|
||||
auto &vertexA = mesh->vertices()[face.a];
|
||||
auto &vertexB = mesh->vertices()[face.b];
|
||||
auto &vertexC = mesh->vertices()[face.c];
|
||||
if(backFaceCull(face.get(), worldView)) {
|
||||
auto &vertexA = mesh->vertices()[face->a()];
|
||||
auto &vertexB = mesh->vertices()[face->b()];
|
||||
auto &vertexC = mesh->vertices()[face->c()];
|
||||
|
||||
auto pixelA = engine->project(*vertexA.get(), transformationMatrix);
|
||||
auto pixelB = engine->project(*vertexB.get(), transformationMatrix);
|
||||
auto pixelC = engine->project(*vertexC.get(), transformationMatrix);
|
||||
auto pixelA = engine->project(vertexA.get()->coords(), transformationMatrix);
|
||||
auto pixelB = engine->project(vertexB.get()->coords(), transformationMatrix);
|
||||
auto pixelC = engine->project(vertexC.get()->coords(), transformationMatrix);
|
||||
|
||||
plotTriangle(pixelA, pixelB, pixelC, colorSwitch ? 2 : 1);
|
||||
colorSwitch = !colorSwitch;
|
||||
COLOR cI = ONE + fxmul(fxdiv(int2fx(i), int2fx(mesh->faces().size())), int2fx(250));
|
||||
plotTriangle(pixelA, pixelB, pixelC, fx2int(cI));
|
||||
colorSwitch = !colorSwitch;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -2,18 +2,18 @@
|
|||
// Created by Wouter Groeneveld on 11/07/20.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/renderer/renderer.h>
|
||||
#include <libgba-sprite-engine/renderer/gba_engine.h>
|
||||
#include <libgba-bitmap-engine/renderer/renderer.h>
|
||||
#include <libgba-bitmap-engine/renderer/gba_engine.h>
|
||||
|
||||
void WiredRenderer::render(const MatrixFx &transformationMatrix, const Mesh* mesh) {
|
||||
void WiredRenderer::render(const MatrixFx &transformationMatrix, const MatrixFx &worldView, const Mesh* mesh) {
|
||||
for (auto &face : mesh->faces()) {
|
||||
auto &vertexA = mesh->vertices()[face.a];
|
||||
auto &vertexB = mesh->vertices()[face.b];
|
||||
auto &vertexC = mesh->vertices()[face.c];
|
||||
auto &vertexA = mesh->vertices()[face->a()];
|
||||
auto &vertexB = mesh->vertices()[face->b()];
|
||||
auto &vertexC = mesh->vertices()[face->c()];
|
||||
|
||||
auto pixelA = engine->project(*vertexA.get(), transformationMatrix);
|
||||
auto pixelB = engine->project(*vertexB.get(), transformationMatrix);
|
||||
auto pixelC = engine->project(*vertexC.get(), transformationMatrix);
|
||||
auto pixelA = engine->project(vertexA.get()->coords(), transformationMatrix);
|
||||
auto pixelB = engine->project(vertexB.get()->coords(), transformationMatrix);
|
||||
auto pixelC = engine->project(vertexC.get()->coords(), transformationMatrix);
|
||||
|
||||
engine->plotLine(pixelA, pixelB, mesh->colorIndex());
|
||||
engine->plotLine(pixelB, pixelC, mesh->colorIndex());
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
// Created by Wouter Groeneveld on 09/08/18.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/scene.h>
|
||||
#include <libgba-sprite-engine/renderer/gba_engine.h>
|
||||
#include <libgba-bitmap-engine/scene.h>
|
||||
#include <libgba-bitmap-engine/renderer/gba_engine.h>
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
// Created by Wouter Groeneveld on 07/08/18.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/gba/tonc_memmap.h>
|
||||
#include <libgba-sprite-engine/sound_control.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_memmap.h>
|
||||
#include <libgba-bitmap-engine/sound_control.h>
|
||||
|
||||
void SoundControl::accept(const void *data, int totalSamples, int ticksPerSample) {
|
||||
this->data = data;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Created by Wouter Groeneveld on 06/12/18.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/timer.h>
|
||||
#include <libgba-bitmap-engine/timer.h>
|
||||
#include <sstream>
|
||||
|
||||
void Timer::onvblank() {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Created by Wouter Groeneveld on 14/12/18.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/vectorfx.h>
|
||||
#include <libgba-bitmap-engine/vectorfx.h>
|
||||
|
||||
|
||||
std::deque<VECTOR> VectorFx::bresenhamLineTo(VECTOR dest) {
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 125 KiB |
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
|
@ -5,8 +5,8 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
#include <libgba-sprite-engine/gba/tonc_math_stub.h>
|
||||
#include <libgba-sprite-engine/math.h>
|
||||
#include <libgba-bitmap-engine/gba/tonc_math_stub.h>
|
||||
#include <libgba-bitmap-engine/math.h>
|
||||
|
||||
class FpSuite : public ::testing::Test {
|
||||
protected:
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
#include <math.h>
|
||||
#include <libgba-sprite-engine/matrixfx.h>
|
||||
#include <libgba-sprite-engine/math.h>
|
||||
#include <libgba-sprite-engine/mesh.h>
|
||||
#include <libgba-sprite-engine/camera.h>
|
||||
#include <libgba-sprite-engine/renderer/gba_engine.h>
|
||||
#include <libgba-sprite-engine/gba/toolbox.h>
|
||||
#include <libgba-bitmap-engine/matrixfx.h>
|
||||
#include <libgba-bitmap-engine/math.h>
|
||||
#include <libgba-bitmap-engine/mesh.h>
|
||||
#include <libgba-bitmap-engine/camera.h>
|
||||
#include <libgba-bitmap-engine/renderer/gba_engine.h>
|
||||
#include <libgba-bitmap-engine/gba/toolbox.h>
|
||||
|
||||
class MatrixFxSuite : public ::testing::Test {
|
||||
protected:
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Created by Wouter Groeneveld on 04/08/18.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/palette/palette_manager.h>
|
||||
#include <libgba-bitmap-engine/palette/palette_manager.h>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
class SomePaletteManager : public PaletteManager {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <libgba-sprite-engine/timer.h>
|
||||
#include <libgba-bitmap-engine/timer.h>
|
||||
|
||||
class TimerSuite : public ::testing::Test {
|
||||
protected:
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <libgba-sprite-engine/vectorfx.h>
|
||||
#include <libgba-bitmap-engine/vectorfx.h>
|
||||
#include "tonc_bios_stub.h"
|
||||
|
||||
class VectorFxSuite : public ::testing::Test {
|
||||
|
|
Loading…
Reference in New Issue