Browse Source

Added loop-de-loop, vehicle auto reset

- Loop-de-loop, for fun
- Vehicle now auto-resets if falling through world
- Engine range is greater, idle is higher RPM (mostly to sound better)
Drivetrain
Macoy Madson 1 year ago
parent
commit
cb702ab9c4
8 changed files with 50 additions and 35 deletions
  1. +13
    -12
      Content/assets/World.scene.xml
  2. +1
    -1
      Content/assets/World_Material.002.material.xml
  3. +2
    -0
      ExportBlenderAssets.py
  4. BIN
      assets/World.blend
  5. +19
    -18
      src/Audio.cpp
  6. +11
    -2
      src/Main.cpp
  7. +2
    -2
      src/PhysicsVehicle.hpp
  8. +2
    -0
      src/PickUpObjective.cpp

+ 13
- 12
Content/assets/World.scene.xml View File

@ -1,15 +1,16 @@
<Model name="World" geometry="assets/World.geo">
<Mesh name="Cube.010" material="assets/World_Material.002.material.xml" tx="-13.7657" ty="-1.41756" tz="-212.941" rx="-2.91953" ry="-179.839" rz="-176.706" sx="-9.14516" sy="1.67537" sz="2.52904" batchStart="0" batchCount="36" vertRStart="0" vertREnd="23" />
<Mesh name="Cube.009" material="assets/World_Material.002.material.xml" tx="-44.0757" ty="-0.424649" tz="-212.958" rx="0" ry="-180" rz="-180" sx="-9.14516" sy="1.67537" sz="2.52905" batchStart="36" batchCount="36" vertRStart="24" vertREnd="47" />
<Mesh name="Cube.008" material="assets/World_Material.002.material.xml" tx="-13.7657" ty="-1.7357" tz="-32.0374" rx="-2.91953" ry="-179.839" rz="-179.873" sx="-9.14516" sy="1.67537" sz="2.52904" batchStart="72" batchCount="36" vertRStart="48" vertREnd="71" />
<Mesh name="Cube.007" material="assets/World_Material.002.material.xml" tx="-13.74" ty="-2.20242" tz="-22.8859" rx="-2.91953" ry="-179.839" rz="-179.873" sx="-9.14516" sy="1.67537" sz="2.52904" batchStart="108" batchCount="36" vertRStart="72" vertREnd="95" />
<Mesh name="Cube.006" material="assets/World_Material.002.material.xml" tx="-13.7158" ty="-2.64352" tz="-14.2369" rx="-2.91953" ry="-179.839" rz="-179.873" sx="-9.14516" sy="1.67537" sz="2.52904" batchStart="144" batchCount="36" vertRStart="96" vertREnd="119" />
<Mesh name="Cube.005" material="assets/World_Material.002.material.xml" tx="-13.6951" ty="-3.01944" tz="-6.86595" rx="-2.91953" ry="-179.839" rz="-179.873" sx="-9.14516" sy="1.67537" sz="2.52904" batchStart="180" batchCount="36" vertRStart="120" vertREnd="143" />
<Mesh name="Cube.004" material="assets/World_Material.002.material.xml" tx="-44.0757" ty="-0.424649" tz="-32.0544" rx="0" ry="-180" rz="-180" sx="-9.14516" sy="1.67537" sz="2.52905" batchStart="216" batchCount="36" vertRStart="144" vertREnd="167" />
<Mesh name="Cube.003" material="assets/World_Material.002.material.xml" tx="-44.0757" ty="-0.424649" tz="-22.8909" rx="0" ry="-180" rz="-180" sx="-9.14516" sy="1.67537" sz="2.52905" batchStart="252" batchCount="36" vertRStart="168" vertREnd="191" />
<Mesh name="Cube.002" material="assets/World_Material.002.material.xml" tx="-44.0757" ty="-0.424649" tz="-14.2307" rx="0" ry="-180" rz="-180" sx="-9.14516" sy="1.67537" sz="2.52905" batchStart="288" batchCount="36" vertRStart="192" vertREnd="215" />
<Mesh name="Cube.001" material="assets/World_Material.002.material.xml" tx="-44.0757" ty="-0.424649" tz="-6.85013" rx="0" ry="-180" rz="-180" sx="-9.14516" sy="1.67537" sz="2.52905" batchStart="324" batchCount="36" vertRStart="216" vertREnd="239" />
<Mesh name="Cube" material="assets/World_Material.002.material.xml" tx="-79.7957" ty="1.45783" tz="-6.85013" rx="0" ry="-180" rz="-180" sx="-9.14516" sy="9.14516" sz="9.14516" batchStart="360" batchCount="36" vertRStart="240" vertREnd="263" />
<Mesh name="Ground" material="assets/World_Material.001.material.xml" batchStart="396" batchCount="98304" vertRStart="264" vertREnd="98567" />
<Mesh name="Loop-de-loop" material="assets/World_Material.002.material.xml" tx="171.317" ty="-6.41571" tz="215.58" batchStart="0" batchCount="2448" vertRStart="0" vertREnd="2354" />
<Mesh name="Jump_Ramp2" material="assets/World_Material.002.material.xml" tx="-13.7657" ty="-1.41756" tz="-212.941" rx="-2.91953" ry="-179.839" rz="-176.706" sx="-9.14516" sy="1.67537" sz="2.52904" batchStart="2448" batchCount="36" vertRStart="2355" vertREnd="2378" />
<Mesh name="Jump_Ramp1" material="assets/World_Material.002.material.xml" tx="-44.0757" ty="-0.424649" tz="-212.958" rx="0" ry="-180" rz="-180" sx="-9.14516" sy="1.67537" sz="2.52905" batchStart="2484" batchCount="36" vertRStart="2379" vertREnd="2402" />
<Mesh name="Cube.008" material="assets/World_Material.002.material.xml" tx="-13.7657" ty="-1.7357" tz="-32.0374" rx="-2.91953" ry="-179.839" rz="-179.873" sx="-9.14516" sy="1.67537" sz="2.52904" batchStart="2520" batchCount="36" vertRStart="2403" vertREnd="2426" />
<Mesh name="Cube.007" material="assets/World_Material.002.material.xml" tx="-13.74" ty="-2.20242" tz="-22.8859" rx="-2.91953" ry="-179.839" rz="-179.873" sx="-9.14516" sy="1.67537" sz="2.52904" batchStart="2556" batchCount="36" vertRStart="2427" vertREnd="2450" />
<Mesh name="Cube.006" material="assets/World_Material.002.material.xml" tx="-13.7158" ty="-2.64352" tz="-14.2369" rx="-2.91953" ry="-179.839" rz="-179.873" sx="-9.14516" sy="1.67537" sz="2.52904" batchStart="2592" batchCount="36" vertRStart="2451" vertREnd="2474" />
<Mesh name="Cube.005" material="assets/World_Material.002.material.xml" tx="-13.6951" ty="-3.01944" tz="-6.86595" rx="-2.91953" ry="-179.839" rz="-179.873" sx="-9.14516" sy="1.67537" sz="2.52904" batchStart="2628" batchCount="36" vertRStart="2475" vertREnd="2498" />
<Mesh name="Cube.004" material="assets/World_Material.002.material.xml" tx="-44.0757" ty="-0.424649" tz="-32.0544" rx="0" ry="-180" rz="-180" sx="-9.14516" sy="1.67537" sz="2.52905" batchStart="2664" batchCount="36" vertRStart="2499" vertREnd="2522" />
<Mesh name="Cube.003" material="assets/World_Material.002.material.xml" tx="-44.0757" ty="-0.424649" tz="-22.8909" rx="0" ry="-180" rz="-180" sx="-9.14516" sy="1.67537" sz="2.52905" batchStart="2700" batchCount="36" vertRStart="2523" vertREnd="2546" />
<Mesh name="Cube.002" material="assets/World_Material.002.material.xml" tx="-44.0757" ty="-0.424649" tz="-14.2307" rx="0" ry="-180" rz="-180" sx="-9.14516" sy="1.67537" sz="2.52905" batchStart="2736" batchCount="36" vertRStart="2547" vertREnd="2570" />
<Mesh name="Cube.001" material="assets/World_Material.002.material.xml" tx="-44.0757" ty="-0.424649" tz="-6.85013" rx="0" ry="-180" rz="-180" sx="-9.14516" sy="1.67537" sz="2.52905" batchStart="2772" batchCount="36" vertRStart="2571" vertREnd="2594" />
<Mesh name="BigCube" material="assets/World_Material.002.material.xml" tx="-79.7957" ty="1.45783" tz="-6.85013" rx="0" ry="-180" rz="-180" sx="-9.14516" sy="9.14516" sz="9.14516" batchStart="2808" batchCount="36" vertRStart="2595" vertREnd="2618" />
<Mesh name="Ground" material="assets/World_Material.001.material.xml" batchStart="2844" batchCount="98304" vertRStart="2619" vertREnd="100922" />
</Model>

+ 1
- 1
Content/assets/World_Material.002.material.xml View File

@ -1,5 +1,5 @@
<Material>
<Shader source="shaders/model.shader" />
<Uniform name="matDiffuseCol" a="0.8" b="0.8" c="0.8" d="1" />
<Uniform name="matDiffuseCol" a="0.06" b="1.0" c="0.9" d="1" />
</Material>

+ 2
- 0
ExportBlenderAssets.py View File

@ -15,11 +15,13 @@ def exportBulletObj():
# use_mesh_modifiers = apply modifiers
# use_materials = (false) Don't export materials. We only use the .objs for collision
# use_triangles = triangulate. Bullet expects triangle meshes
# https://docs.blender.org/api/current/bpy.ops.export_scene.html?highlight=export_scene#bpy.ops.export_scene.obj
bpy.ops.export_scene.obj(filepath=outputFilename, check_existing=False,
use_mesh_modifiers=True, use_materials=False, use_triangles=True)
def exportHordeCollada():
outputFilename = makeRelativeFilename("dae")
# https://docs.blender.org/api/current/bpy.ops.wm.html?highlight=collada#bpy.ops.wm.collada_export
bpy.ops.wm.collada_export(filepath=outputFilename, check_existing=False, apply_modifiers=True, triangulate=True)
exportBulletObj()


BIN
assets/World.blend View File


+ 19
- 18
src/Audio.cpp View File

@ -1,8 +1,9 @@
#include "Audio.hpp"
#include "Utilities.hpp"
#include "DebugDisplay.hpp"
#include "Logging.hpp"
#include "PhysicsVehicle.hpp"
#include "Utilities.hpp"
#include "btBulletDynamicsCommon.h"
#include "graphics/graphics.hpp"
@ -18,9 +19,9 @@
#include <iostream>
#include <sstream>
#include <stdlib.h> // rand
#include <cmath> // sin
#include <limits>
#include <stdlib.h> // rand
#include <cmath> // sin
sound sfxVehicleStartup;
sound sfxVehicleIdle;
@ -140,7 +141,7 @@ private:
SoundSample sampleBuffer[100];
unsigned int bufferOffset;
unsigned int sampleRate;
virtual bool onGetData(sf::SoundStream::Chunk& data)
{
float engineRpm = GetPlayerVehicleEngineRpmThreadSafe();
@ -155,9 +156,10 @@ private:
{
// TODO Overflow protection
// sampleBuffer[i] = lastSample + ((rand() % maxMotion) - maxMotion / 2);
// Sawtooth wave
// sampleBuffer[i] = ((i * 7) / (float)ArraySize(sampleBuffer)) * std::numeric_limits<short>::max();
// sampleBuffer[i] = ((i * 7) / (float)ArraySize(sampleBuffer)) *
// std::numeric_limits<short>::max();
// Square wave
// if (i < ArraySize(sampleBuffer) / 2)
@ -168,12 +170,11 @@ private:
// Triangle wave
// if (i == 0)
// sampleBuffer[i] = std::numeric_limits<short>::min();
// else if (sampleBuffer[i - 1] <= std::numeric_limits<short>::min() + triangleWaveSpeed)
// triangleWaveDirection = 1;
// else if (sampleBuffer[i - 1] >= std::numeric_limits<short>::max() - triangleWaveSpeed)
// triangleWaveDirection = -1;
// if (i > 0)
// sampleBuffer[i] = sampleBuffer[i - 1] + (triangleWaveDirection * triangleWaveSpeed);
// else if (sampleBuffer[i - 1] <= std::numeric_limits<short>::min() +
// triangleWaveSpeed) triangleWaveDirection = 1; else if (sampleBuffer[i - 1] >=
// std::numeric_limits<short>::max() - triangleWaveSpeed) triangleWaveDirection = -1; if
// (i > 0) sampleBuffer[i] = sampleBuffer[i - 1] + (triangleWaveDirection *
// triangleWaveSpeed);
// Sine wave - Not working
// sampleBuffer[i] =
@ -198,7 +199,7 @@ private:
}
// if (i < 10)
// std::cout << sampleBuffer[i] << "\n";
// LOGD << sampleBuffer[i];
lastSample = sampleBuffer[i];
}
@ -207,7 +208,7 @@ private:
data.samples = sampleBuffer;
bufferOffset += data.sampleCount;
// Keep playing forever
return true;
}
@ -220,7 +221,7 @@ private:
void updateAudio(PhysicsVehicle& vehicle, float frameTime)
{
const glm::vec3 vehiclePosition = vehicle.GetPosition();
// if (false)
{
static BrownianNoiseAudioStream noiseStream;
@ -234,7 +235,7 @@ void updateAudio(PhysicsVehicle& vehicle, float frameTime)
noiseStream.setPitch(vehicle.engineRpm / 10000.f);
noiseStream.setVolume(40.f);
noiseStream.setPosition(vehiclePosition[0], vehiclePosition[1], vehiclePosition[2]);
}
@ -330,10 +331,10 @@ void updateAudio(PhysicsVehicle& vehicle, float frameTime)
void playObjectiveGet()
{
sfxObjectiveGet.play();
sfxObjectiveGet.play();
}
void playVehicleShifting()
{
sfxVehicleShifting.play();
sfxVehicleShifting.play();
}

+ 11
- 2
src/Main.cpp View File

@ -293,8 +293,17 @@ int main()
}
// Physics
vehicle.Update(previousFrameTime * timeStepScale);
physicsWorld.Update(previousFrameTime * timeStepScale);
{
// Make sure vehicle isn't falling through the world
if (vehicle.GetPosition()[1] < -30.f)
{
// TODO: Make this put you back in the last known good position?
vehicle.Reset();
}
vehicle.Update(previousFrameTime * timeStepScale);
physicsWorld.Update(previousFrameTime * timeStepScale);
}
PickUpObjectives::Update(previousFrameTime);


+ 2
- 2
src/PhysicsVehicle.hpp View File

@ -92,8 +92,8 @@ public:
// TODO Make getter?
float engineRpm;
float idleEngineRpm = 100.f;
float maxEngineRpm = 2500.f;
float idleEngineRpm = 300.f;
float maxEngineRpm = 3000.f;
// "Realistic"
// float idleEngineRpm = 600.f;


+ 2
- 0
src/PickUpObjective.cpp View File

@ -94,6 +94,8 @@ void Initialize(PhysicsWorld* physicsWorld)
glm::vec3(249.6f, 3.254f, -128.6f),
// Big hill jump
glm::vec3(-125.4f, 37.37f, -0.975f),
// Loop-de-loop
glm::vec3(134.8f, 24.24f, 212.3f),
};
// Objectives


Loading…
Cancel
Save