Skip to content

Commit

Permalink
Add skeletal mesh with inverse kinematics sample
Browse files Browse the repository at this point in the history
  • Loading branch information
schellingb committed Aug 1, 2018
1 parent 59a74a7 commit 5622ece
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 32-3d-materials.inl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct sMain : public ZL_Application
void Load(int argc, char *argv[])
{
//Initialize the game with depth buffer, 3d rendering and shadow mapping
ZL_Display::Init("Advanced 3D Materials", 1280, 720, ZL_DISPLAY_ALLOWRESIZEHORIZONTAL | ZL_DISPLAY_DEPTHBUFFER);
ZL_Display::Init("Advanced 3D Materials", 1280, 720, ZL_DISPLAY_DEPTHBUFFER);
ZL_Display3D::Init();
ZL_Display3D::InitShadowMapping();
ZL_Input::Init();
Expand Down
41 changes: 41 additions & 0 deletions 34-skeletal-mesh-ik.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
static ZL_Camera Camera;
static ZL_Light Light = ZL_Light(ZL_Vector3(2.f, 5.f, 8.f));
static ZL_SkeletalMesh SkeletalMesh;
static ZL_RenderList RenderList;

struct sMain : public ZL_Application
{
sMain() : ZL_Application() {}

void Load(int argc, char *argv[])
{
//Initialize the game with depth buffer and 3d rendering
ZL_Display::Init("Skeletal Mesh", 1280, 720, ZL_DISPLAY_DEPTHBUFFER);
ZL_Display3D::Init();
ZL_Input::Init();

//Load the skeletal mesh model file
SkeletalMesh = ZL_SkeletalMesh::FromGLTF("Data/human.glb.zip");
}

void AfterFrame()
{
if (ZL_Input::Down(ZLK_ESCAPE)) ZL_Application::Quit();

//Update the camera position every frame referencing the mouse coordinates
float HoirzontalAngleRad = (ZL_Display::PointerX-ZLHALFW)/ZLHALFW*PI+PIHALF;
float VerticalAngleRad = ((ZL_Display::PointerY-ZLHALFH)/ZLHALFH-.2f)*PIHALF*0.8f;
Camera.SetLookAt(ZL_Vector3::FromRotation(HoirzontalAngleRad, VerticalAngleRad) * 3.f + ZL_Vector3(0,0,1), ZL_Vector3(0,0,1));

//Update the foot positions with inverse kinematics (IK)
SkeletalMesh.TwoBoneIK(12, ZL_Vector3(-.1f, 0, .23f - .15f * ssin(ZLSECONDS * 5)), ZL_Vector3::Forward); //Left foot
SkeletalMesh.TwoBoneIK(15, ZL_Vector3( .1f, 0, .23f - .15f * scos(ZLSECONDS * 5)), ZL_Vector3::Forward); //Right foot
SkeletalMesh.Update();

//Setup and draw our dynamic render list with our skeletal mesh on a black background
RenderList.Reset();
RenderList.Add(SkeletalMesh, ZL_Matrix::Identity);
ZL_Display::ClearFill(ZL_Color::Black);
ZL_Display3D::DrawListWithLight(RenderList, Camera, Light);
}
} Main;
Binary file added Data/human.glb.zip
Binary file not shown.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Sample repository for the [ZillaLib](https://github.com/schellingb/ZillaLib) gam
**Saving Loading Settings**<p>Platform independent settings storage</p>[<img src="https://zillalib.github.io/samples/ZillaLibSample-25.png">](https://zillalib.github.io/samples/?25)<br>[- Run in Web Browser -](https://zillalib.github.io/samples/?25)<br>[Win32](https://zillalib.github.io/samples/ZillaLibSample-25_Win32.zip)/[Win64](https://zillalib.github.io/samples/ZillaLibSample-25_Win64.zip)/[Android](https://zillalib.github.io/samples/ZillaLibSample-25.apk)<br>[MacOSX](https://zillalib.github.io/samples/ZillaLibSample-25_osx.zip)/[Linux32](https://zillalib.github.io/samples/ZillaLibSample-25_linux_x86_32.zip)/[Linux64](https://zillalib.github.io/samples/ZillaLibSample-25_linux_x86_64.zip)<br>[View Source](https://github.com/schellingb/ZillaLibSamples/blob/master/25-saving-loading-settings.inl)|**Open Web Link**<p>Opening an URL in the browser</p>[<img src="https://zillalib.github.io/samples/ZillaLibSample-26.png">](https://zillalib.github.io/samples/?26)<br>[- Run in Web Browser -](https://zillalib.github.io/samples/?26)<br>[Win32](https://zillalib.github.io/samples/ZillaLibSample-26_Win32.zip)/[Win64](https://zillalib.github.io/samples/ZillaLibSample-26_Win64.zip)/[Android](https://zillalib.github.io/samples/ZillaLibSample-26.apk)<br>[MacOSX](https://zillalib.github.io/samples/ZillaLibSample-26_osx.zip)/[Linux32](https://zillalib.github.io/samples/ZillaLibSample-26_linux_x86_32.zip)/[Linux64](https://zillalib.github.io/samples/ZillaLibSample-26_linux_x86_64.zip)<br>[View Source](https://github.com/schellingb/ZillaLibSamples/blob/master/26-open-web-link.inl)|**JSON Reader and Writer**<p>Sample of how to read and write JSON formatted data</p>[<img src="https://zillalib.github.io/samples/ZillaLibSample-27.png">](https://zillalib.github.io/samples/?27)<br>[- Run in Web Browser -](https://zillalib.github.io/samples/?27)<br>[Win32](https://zillalib.github.io/samples/ZillaLibSample-27_Win32.zip)/[Win64](https://zillalib.github.io/samples/ZillaLibSample-27_Win64.zip)/[Android](https://zillalib.github.io/samples/ZillaLibSample-27.apk)<br>[MacOSX](https://zillalib.github.io/samples/ZillaLibSample-27_osx.zip)/[Linux32](https://zillalib.github.io/samples/ZillaLibSample-27_linux_x86_32.zip)/[Linux64](https://zillalib.github.io/samples/ZillaLibSample-27_linux_x86_64.zip)<br>[View Source](https://github.com/schellingb/ZillaLibSamples/blob/master/27-json-read-write.inl)
**Advanced Polygon Usage**<p>Polygons with multi contours and extrusion</p>[<img src="https://zillalib.github.io/samples/ZillaLibSample-28.png">](https://zillalib.github.io/samples/?28)<br>[- Run in Web Browser -](https://zillalib.github.io/samples/?28)<br>[Win32](https://zillalib.github.io/samples/ZillaLibSample-28_Win32.zip)/[Win64](https://zillalib.github.io/samples/ZillaLibSample-28_Win64.zip)/[Android](https://zillalib.github.io/samples/ZillaLibSample-28.apk)<br>[MacOSX](https://zillalib.github.io/samples/ZillaLibSample-28_osx.zip)/[Linux32](https://zillalib.github.io/samples/ZillaLibSample-28_linux_x86_32.zip)/[Linux64](https://zillalib.github.io/samples/ZillaLibSample-28_linux_x86_64.zip)<br>[View Source](https://github.com/schellingb/ZillaLibSamples/blob/master/28-advanced-polygon.inl)|**Blend Modes Visualizer**<p>Tool to visualize all kinds of blending modes</p>[<img src="https://zillalib.github.io/samples/ZillaLibSample-29.png">](https://zillalib.github.io/samples/?29)<br>[- Run in Web Browser -](https://zillalib.github.io/samples/?29)<br>[Win32](https://zillalib.github.io/samples/ZillaLibSample-29_Win32.zip)/[Win64](https://zillalib.github.io/samples/ZillaLibSample-29_Win64.zip)/[Android](https://zillalib.github.io/samples/ZillaLibSample-29.apk)<br>[MacOSX](https://zillalib.github.io/samples/ZillaLibSample-29_osx.zip)/[Linux32](https://zillalib.github.io/samples/ZillaLibSample-29_linux_x86_32.zip)/[Linux64](https://zillalib.github.io/samples/ZillaLibSample-29_linux_x86_64.zip)<br>[View Source](https://github.com/schellingb/ZillaLibSamples/blob/master/29-blend-modes.inl)|**Simple Game**<p>A simple game showing off various features</p>[<img src="https://zillalib.github.io/samples/ZillaLibSample-30.png">](https://zillalib.github.io/samples/?30)<br>[- Run in Web Browser -](https://zillalib.github.io/samples/?30)<br>[Win32](https://zillalib.github.io/samples/ZillaLibSample-30_Win32.zip)/[Win64](https://zillalib.github.io/samples/ZillaLibSample-30_Win64.zip)/[Android](https://zillalib.github.io/samples/ZillaLibSample-30.apk)<br>[MacOSX](https://zillalib.github.io/samples/ZillaLibSample-30_osx.zip)/[Linux32](https://zillalib.github.io/samples/ZillaLibSample-30_linux_x86_32.zip)/[Linux64](https://zillalib.github.io/samples/ZillaLibSample-30_linux_x86_64.zip)<br>[View Source](https://github.com/schellingb/ZillaLibSamples/blob/master/30-simple-game.inl)
**Basic 3D**<p>Basic example of rendering a 3D scene</p>[<img src="https://zillalib.github.io/samples/ZillaLibSample-31.png">](https://zillalib.github.io/samples/?31)<br>[- Run in Web Browser -](https://zillalib.github.io/samples/?31)<br>[Win32](https://zillalib.github.io/samples/ZillaLibSample-31_Win32.zip)/[Win64](https://zillalib.github.io/samples/ZillaLibSample-31_Win64.zip)/[Android](https://zillalib.github.io/samples/ZillaLibSample-31.apk)<br>[MacOSX](https://zillalib.github.io/samples/ZillaLibSample-31_osx.zip)/[Linux32](https://zillalib.github.io/samples/ZillaLibSample-31_linux_x86_32.zip)/[Linux64](https://zillalib.github.io/samples/ZillaLibSample-31_linux_x86_64.zip)<br>[View Source](https://github.com/schellingb/ZillaLibSamples/blob/master/31-basic-3d.inl)|**Advanced 3D Materials**<p>Using advanced and custom shaders for materials</p>[<img src="https://zillalib.github.io/samples/ZillaLibSample-32.png">](https://zillalib.github.io/samples/?32)<br>[- Run in Web Browser -](https://zillalib.github.io/samples/?32)<br>[Win32](https://zillalib.github.io/samples/ZillaLibSample-32_Win32.zip)/[Win64](https://zillalib.github.io/samples/ZillaLibSample-32_Win64.zip)/[Android](https://zillalib.github.io/samples/ZillaLibSample-32.apk)<br>[MacOSX](https://zillalib.github.io/samples/ZillaLibSample-32_osx.zip)/[Linux32](https://zillalib.github.io/samples/ZillaLibSample-32_linux_x86_32.zip)/[Linux64](https://zillalib.github.io/samples/ZillaLibSample-32_linux_x86_64.zip)<br>[View Source](https://github.com/schellingb/ZillaLibSamples/blob/master/32-3d-materials.inl)|**3D Particles**<p>A simple effect using the 3D particle system</p>[<img src="https://zillalib.github.io/samples/ZillaLibSample-33.png">](https://zillalib.github.io/samples/?33)<br>[- Run in Web Browser -](https://zillalib.github.io/samples/?33)<br>[Win32](https://zillalib.github.io/samples/ZillaLibSample-33_Win32.zip)/[Win64](https://zillalib.github.io/samples/ZillaLibSample-33_Win64.zip)/[Android](https://zillalib.github.io/samples/ZillaLibSample-33.apk)<br>[MacOSX](https://zillalib.github.io/samples/ZillaLibSample-33_osx.zip)/[Linux32](https://zillalib.github.io/samples/ZillaLibSample-33_linux_x86_32.zip)/[Linux64](https://zillalib.github.io/samples/ZillaLibSample-33_linux_x86_64.zip)<br>[View Source](https://github.com/schellingb/ZillaLibSamples/blob/master/33-3d-particles.inl)
**Skeletal Mesh IK**<p>Loading a skeletal mesh with inverse kinematics</p>[<img src="https://zillalib.github.io/samples/ZillaLibSample-34.png">](https://zillalib.github.io/samples/?34)<br>[- Run in Web Browser -](https://zillalib.github.io/samples/?34)<br>[Win32](https://zillalib.github.io/samples/ZillaLibSample-34_Win32.zip)/[Win64](https://zillalib.github.io/samples/ZillaLibSample-34_Win64.zip)/[Android](https://zillalib.github.io/samples/ZillaLibSample-34.apk)<br>[MacOSX](https://zillalib.github.io/samples/ZillaLibSample-34_osx.zip)/[Linux32](https://zillalib.github.io/samples/ZillaLibSample-34_linux_x86_32.zip)/[Linux64](https://zillalib.github.io/samples/ZillaLibSample-34_linux_x86_64.zip)<br>[View Source](https://github.com/schellingb/ZillaLibSamples/blob/master/34-skeletal-mesh-ik.inl)
16 changes: 14 additions & 2 deletions ZillaLibSampleMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
using namespace std;

#ifndef ZILLALIBSAMPLES_NUMBER
#define ZILLALIBSAMPLES_NUMBER 33
#define ZILLALIBSAMPLES_NUMBER 34
#define ZILLALIBSAMPLES_HASDATA 1
#endif

Expand Down Expand Up @@ -109,6 +109,8 @@ struct ZL_Display_Sample : public ZL_Display
#include "32-3d-materials.inl"
#elif ZILLALIBSAMPLES_NUMBER == 33
#include "33-3d-particles.inl"
#elif ZILLALIBSAMPLES_NUMBER == 34
#include "34-skeletal-mesh-ik.inl"
#endif

//Test compile all samples with ZILLALIBSAMPLES_NUMBER set to 0
Expand Down Expand Up @@ -162,6 +164,7 @@ namespace NS01 {
#undef SCENE_GAME
};namespace NS17 {
#include "17-surface-shader.inl"
#undef SCENE_GAME
};namespace NS18 {
#include "18-render-clipping.inl"
};namespace NS19 {
Expand All @@ -186,6 +189,15 @@ namespace NS01 {
#include "28-advanced-polygon.inl"
};namespace NS29 {
#include "29-blend-modes.inl"
};namespace NS30 {
#include "30-simple-game.inl"
};namespace NS31 {
#include "31-basic-3d.inl"
};namespace NS32 {
#include "32-3d-materials.inl"
};namespace NS33 {
#include "33-3d-particles.inl"
};namespace NS34 {
#include "34-skeletal-mesh-ik.inl"
};

#endif
3 changes: 2 additions & 1 deletion ZillaLibSamples-OSX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
101031 = { isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = "31-basic-3d.inl"; sourceTree = "<group>"; };
101032 = { isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = "32-3d-materials.inl"; sourceTree = "<group>"; };
101033 = { isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = "33-3d-particles.inl"; sourceTree = "<group>"; };
101034 = { isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = "34-skeletal-mesh-ik.inl"; sourceTree = "<group>"; };

202001 = { isa = PBXBuildFile; fileRef = 201001; }; 201001 = { isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "ZillaLibSampleMain.cpp"; sourceTree = "<group>"; };

Expand All @@ -60,7 +61,7 @@
800000 = { isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZillaLibSamples.app; sourceTree = BUILT_PRODUCTS_DIR; };

A00001 = { isa = PBXGroup; name = Products; children = (800000); sourceTree = "<group>"; };
A00002 = { isa = PBXGroup; name = Sources; children = (101001,101002,101003,101004,101005,101006,101007,101008,101009,101010,101011,101012,101013,101014,101015,101016,101017,101018,101019,101020,101021,101022,101023,101024,101025,101026,101027,101028,101029,101030,101031,101032,101033,201001); sourceTree = "<group>"; };
A00002 = { isa = PBXGroup; name = Sources; children = (101001,101002,101003,101004,101005,101006,101007,101008,101009,101010,101011,101012,101013,101014,101015,101016,101017,101018,101019,101020,101021,101022,101023,101024,101025,101026,101027,101028,101029,101030,101031,101032,101033,101034,201001); sourceTree = "<group>"; };
A00003 = { isa = PBXGroup; name = Resources; children = (301001,401001); sourceTree = "<group>"; };
A00004 = { isa = PBXGroup; name = Frameworks; children = (501001,501002,501003,501004,501005,501006,501007); sourceTree = "<group>"; };
A00005 = { isa = PBXGroup; name = CustomTemplate; children = (600001,A00001,A00002,A00003,A00004); sourceTree = "<group>"; };
Expand Down
3 changes: 2 additions & 1 deletion ZillaLibSamples-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
101031 = { isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = "31-basic-3d.inl"; sourceTree = "<group>"; };
101032 = { isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = "32-3d-materials.inl"; sourceTree = "<group>"; };
101033 = { isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = "33-3d-particles.inl"; sourceTree = "<group>"; };
101034 = { isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = "34-skeletal-mesh-ik.inl"; sourceTree = "<group>"; };

202001 = { isa = PBXBuildFile; fileRef = 201001; }; 201001 = { isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "ZillaLibSampleMain.cpp"; sourceTree = "<group>"; };

Expand Down Expand Up @@ -74,7 +75,7 @@
800000 = { isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZillaLibSamples.app; sourceTree = BUILT_PRODUCTS_DIR; };

A00001 = { isa = PBXGroup; name = Products; children = (800000); sourceTree = "<group>"; };
A00002 = { isa = PBXGroup; name = Sources; children = (101001,101002,101003,101004,101005,101006,101007,101008,101009,101010,101011,101012,101013,101014,101015,101016,101017,101018,101019,101020,101021,101022,101023,101024,101025,101026,101027,101028,101029,101030,101031,101032,101033,201001); sourceTree = "<group>"; };
A00002 = { isa = PBXGroup; name = Sources; children = (101001,101002,101003,101004,101005,101006,101007,101008,101009,101010,101011,101012,101013,101014,101015,101016,101017,101018,101019,101020,101021,101022,101023,101024,101025,101026,101027,101028,101029,101030,101031,101032,101033,101034,201001); sourceTree = "<group>"; };
A00003 = { isa = PBXGroup; name = Resources; children = (301001,401001,401002,401003,401004,401005,401006,401007,401008,401009,401010,401011); sourceTree = "<group>"; };
A00004 = { isa = PBXGroup; name = Frameworks; children = (501001,501002,501003,501004,501005,501006,501007,501008,501009,501010,501011); sourceTree = "<group>"; };
A00005 = { isa = PBXGroup; name = CustomTemplate; children = (600001,A00001,A00002,A00003,A00004); sourceTree = "<group>"; };
Expand Down
1 change: 1 addition & 0 deletions ZillaLibSamples-vs.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<None Include="31-basic-3d.inl" />
<None Include="32-3d-materials.inl" />
<None Include="33-3d-particles.inl" />
<None Include="34-skeletal-mesh-ik.inl" />
<ResourceCompile Include="ZillaLibSamples.rc" />
</ItemGroup>
</Project>

0 comments on commit 5622ece

Please sign in to comment.