Giter VIP home page Giter VIP logo

irrlicht-newton-game1's Introduction

Newton GD for Irrlicht game developers

Briefing

This repo contains the code for Irrlicht + Newton game tutorial.

Changelog

  • 9 Nov 2015 Added basic NewtonGD sample.
  • 8 Nov 2015 Added Lua scripting and all the interaction logic is now defined by the Lua scripts.
  • 7 Nov 2015 Sample Irrlicht program compiles with CMake build system.
  • 3 Oct 2017 Migrated to Buck build system.
  • 13 Apr 2018 Added many more improvements to the build configuration and some troubleshooting guides.
  • 16 Apr 2018 Upgraded to Irrlicht 1.8.4
  • 18 Apr 2018 Migrated to Bazel build system

TODO

  • Fix starting position/rotation for bodies when creating them
  • Fix impulse/force applying
  • Fix OSX window focus
  • Add automatic media/ copying to the bundle/binary directory
  • Generalize build rules for different platforms
  • Upgrade Irrlicht to 1.8.4
  • Upgrade NewtonGD to 3.14

Step-by-step build

  1. install Bazel from master branch
  2. to build project, run the command from the project root directory

a. for OSX:

bazel build //irrlicht-newton-game:irrlicht-newton-game --apple_platform_type=macos

b. for Linux & others:

bazel build //irrlicht-newton-game:irrlicht-newton-game
  1. run a demo with

a. for OSX:

bazel run //irrlicht-newton-game:irrlicht-newton-game

b. for others:

bazel run //irrlicht-newton-game:irrlicht-newton-game --apple_platform_type=macos

Important hints & troubleshooting

Newton bits

There is no more GetIdentityMatrix() - it was replaced with dGetIdentityMatrix(). There's also no more need to set m_w for dVector instances - it has the default value of 1.0. You can not multiply a dVector by a number - you have to call vector.Scale(x) to do this. There are no NewtonSetPlatformArchitecture and NewtonSetWorldSize anymore.

Clang 6.0 compilation errors for Irrlicht

I've ran into two error messages after an upgrade of Clang to 6.0:

vendor/irrlicht/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm:645:7: error: cast from pointer to smaller type 'NSOpenGLPixelFormatAttribute' (aka 'unsigned int') loses information
                                                (NSOpenGLPixelFormatAttribute)nil
                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vendor/irrlicht/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm:671:26: error: cast from pointer to smaller type 'NSOpenGLPixelFormatAttribute' (aka 'unsigned int') loses information
                                                        windowattribs[14]=(NSOpenGLPixelFormatAttribute)nil;

The fix was relatively easy, but required modifying the Irrlicht sources, which makes me sad.

// before:
windowattribs[14]=(NSOpenGLPixelFormatAttribute)nil;

// after:
windowattribs[14]=0;
// before:
NSOpenGLPixelFormatAttribute windowattribs[] =
{
    NSOpenGLPFANoRecovery,
    NSOpenGLPFAAccelerated,
    NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)depthSize,
    NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)CreationParams.Bits,
    NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)alphaSize,
    NSOpenGLPFASampleBuffers, (NSOpenGLPixelFormatAttribute)1,
    NSOpenGLPFASamples, (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias,
    NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
    NSOpenGLPFADoubleBuffer,
    (NSOpenGLPixelFormatAttribute)nil
};

// after:
NSOpenGLPixelFormatAttribute windowattribs[] =
{
    NSOpenGLPFANoRecovery,
    NSOpenGLPFAAccelerated,
    NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)depthSize,
    NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)CreationParams.Bits,
    NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)alphaSize,
    NSOpenGLPFASampleBuffers, (NSOpenGLPixelFormatAttribute)1,
    NSOpenGLPFASamples, (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias,
    NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
    NSOpenGLPFADoubleBuffer,
    0
};

Window is not shown on OSX

Change one line in ObjectiveC code of Irrlicht, in the CIrrDeviceMacOSX.mm file, the CIrrDeviceMacOSX::CIrrDeviceMacOSX method (constructor):

// before:
[NSApplication sharedApplication]

// after:
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];

And then rebuild the application.

How can I pack the OSX application?

First, you will need to alter all the paths in the application code (both in C++ code and the scripts) to use the paths relative to the parent directory, containing your application bundle (the .app/ directory):

scriptMgr->loadScript("irrlicht-newton-game.app/Contents/MacOS/media/media/media/scripts/test1.lua");

and

createMesh("colliseum", "irrlicht-newton-game.app/Contents/MacOS/media/media/media/models/ramp_floor.3ds", "./media/media/media/models/ramp_floor.png")

Then run these commands to create the bundle itself:

cd bazel-bin/irrlicht-newton-game/irrlicht-newton-game.runfiles/__main__/irrlicht-newton-game
mkdir -p irrlicht-newton-game.app/Contents/MacOS
cp -r media/ irrlicht-newton-game irrlicht-newton-game.app/Contents/MacOS

Now you might run your application using either Finder or open irrlicht-newton-game.app.

Could not build Newton on Windows

A "hard to detect and fix" error might be found on Windows:

vendor/newton-dynamics/sdk/dCustomJoints/dCustomJoint.cpp(20): error C2491: 'dCustomJoint::m_key': definition of dllimport static data member not allowed

This is due to the aambigous linkage type - VisualStudio does not know whether it is static or dynamic, whilst by default it assumes dynamic linkage for Windows platform. This is defined by the CUSTOM_JOINTS_API macro in the vendor/newton-dynamics/sdk/dCustomJoints/dCustomAlloc.h file. To prevent this, you will need to pass the _CUSTOM_JOINTS_STATIC_LIB preprocessor constant. In bazel this could be achieved by using the defines: [ "_CUSTOM_JOINTS_STATIC_LIB", ] property.

irrlicht-newton-game1's People

Contributors

shybovycha avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.