Skip to content

Commit

Permalink
Use scene in accelTest
Browse files Browse the repository at this point in the history
  • Loading branch information
dylwhich committed Oct 22, 2023
1 parent 183eda6 commit b41345a
Showing 1 changed file with 55 additions and 31 deletions.
86 changes: 55 additions & 31 deletions main/modes/accelTest/accelTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "swadge2024.h"
#include "accelTest.h"
#include "hdw-imu.h"
#include "esp_log.h"
#include "trigonometry.h"
#include "shapes.h"
Expand Down Expand Up @@ -76,10 +77,14 @@ typedef struct
model_t bunny; ///< The bunny 3D model
model_t donut; ///< The donut 3D model

scene_t scene;

bool translateY;
float scale;
float translate[3];

uint8_t selectedModel;

uint16_t btnState; ///< The button state

int16_t x; ///< The latest X accelerometer reading
Expand Down Expand Up @@ -169,13 +174,24 @@ static void accelTestEnterMode(void)
ESP_LOGI("Model", "loadModel(bunny.mdl) returned %s", loadModel("bunny.mdl", &accelTest->bunny, true) ? "true" : "false");
loadModel("donut.mdl", &accelTest->donut, true);

accelTest->scale = 1.0;
accelTest->translate[0] = 0.0;
accelTest->translate[1] = 0.0;
accelTest->translate[2] = 0.0;
accelTest->scene.modelCount = 2;
accelTest->scene.models[0].model = &accelTest->donut;
accelTest->scene.models[0].scale = 0.5;
accelTest->scene.models[0].translate[0] = -25.0;
accelTest->scene.models[0].translate[1] = -25.0;
accelTest->scene.models[0].translate[2] = 0.0;

accelTest->scene.models[1].model = &accelTest->donut;
accelTest->scene.models[1].scale = 0.1;
accelTest->scene.models[1].translate[0] = 25.0;
accelTest->scene.models[1].translate[1] = 25.0;
accelTest->scene.models[1].translate[2] = -1.0;

// Ensure there's sufficient space to draw both models
initRendererScene(&accelTest->scene);

// Ensure there's sufficient space to draw either model
initRendererCustom(MAX(accelTest->bunny.vertCount, accelTest->donut.vertCount), MAX(accelTest->bunny.triCount, accelTest->donut.triCount));
//initRendererCustom(MAX(accelTest->bunny.vertCount, accelTest->donut.vertCount), MAX(accelTest->bunny.triCount, accelTest->donut.triCount));

// writeTextlabels doesn't get reset by accelTestReset(), so initialize that here
accelTest->writeTextLabels = true;
Expand Down Expand Up @@ -213,6 +229,20 @@ static void accelTestExitMode(void)
*/
static void accelTestMainLoop(int64_t elapsedUs)
{
int32_t angle, radius, intensity;
if (getTouchJoystick(&angle, &radius, &intensity))
{
int32_t x, y;
getTouchCartesian(angle, radius, &x, &y);

float minX = -126.0;
float maxX = 126.0;
float minY = -126.0;
float maxY = 126.0;

accelTest->scene.models[accelTest->selectedModel].translate[0] = minX + ((maxX - minX) * x / 1023.0);
accelTest->scene.models[accelTest->selectedModel].translate[1] = minY + ((maxY - minY) * y / 1023.0);
}
// Always process button events, regardless of control scheme, so the main menu button can be captured
buttonEvt_t evt = {0};
while (checkButtonQueueWrapper(&evt))
Expand All @@ -233,44 +263,27 @@ static void accelTestMainLoop(int64_t elapsedUs)

if (evt.down && (PB_B == evt.button))
{
accelTest->translateY = !accelTest->translateY;
accelTest->selectedModel = (accelTest->selectedModel + 1) % accelTest->scene.modelCount;
}

if (evt.down && (PB_UP == evt.button))
{
accelTest->scale += .1;
accelTest->scene.models[accelTest->selectedModel].scale += .1;
}

if (evt.down && (PB_DOWN == evt.button))
{
if (accelTest->scale > .15)
{
accelTest->scale -= .1;
}
accelTest->scene.models[accelTest->selectedModel].scale -= .1;
}

if (evt.down && (PB_LEFT == evt.button))
{
if (accelTest->translateY)
{
accelTest->translate[1] -= 5.0;
}
else
{
accelTest->translate[0] -= 5.0;
}
accelTest->scene.models[accelTest->selectedModel].translate[0] -= 5.0;
}

if (evt.down && (PB_RIGHT == evt.button))
{
if (accelTest->translateY)
{
accelTest->translate[1] += 5.0;
}
else
{
accelTest->translate[0] += 5.0;
}
accelTest->scene.models[accelTest->selectedModel].translate[0] += 5.0;
}

ESP_LOGI("Accel", "Scale: %f", accelTest->scale);
Expand Down Expand Up @@ -330,11 +343,22 @@ static void accelTestHandleInput(void)
static void accelDrawBunny(void)
{
// Get the orientation from the accelerometer
float orient[4];
memcpy(orient, LSM6DSL.fqQuat, sizeof(orient));
for (uint8_t i = 0; i < accelTest->scene.modelCount; i++)
{
memcpy(accelTest->scene.models[i].orient, LSM6DSL.fqQuat, sizeof(float) * 4);

if (i == 0)
{
float objRot[4] = {0};
objRot[3] = 600.0;
mathQuatApply(accelTest->scene.models[i].orient, accelTest->scene.models[i].orient, objRot);
}
}

drawScene(&accelTest->scene, 0, 0, TFT_WIDTH, TFT_HEIGHT);

drawModel(&accelTest->donut, orient, accelTest->scale / 2, accelTest->translate, 0, TFT_HEIGHT / 2, TFT_WIDTH / 2, TFT_HEIGHT / 2);
drawModel(&accelTest->bunny, orient, accelTest->scale / 2, accelTest->translate, TFT_WIDTH / 2, TFT_HEIGHT / 2, TFT_WIDTH / 2, TFT_HEIGHT / 2);
//drawModel(&accelTest->donut, orient, accelTest->scale / 2, accelTest->translate, 0, TFT_HEIGHT / 2, TFT_WIDTH / 2, TFT_HEIGHT / 2);
//drawModel(&accelTest->bunny, orient, accelTest->scale / 2, accelTest->translate, TFT_WIDTH / 2, TFT_HEIGHT / 2, TFT_WIDTH / 2, TFT_HEIGHT / 2);
}

/**
Expand Down

0 comments on commit b41345a

Please sign in to comment.