November 21, 2017, 03:54:47 PM

Author Topic: Animation/Lighting problem with OpenB3D  (Read 124 times)

Offline Kronos

  • Jr. Member
  • **
  • Posts: 4
Animation/Lighting problem with OpenB3D
« on: November 12, 2017, 12:34:47 PM »
Can someone confirm whether they see the same problem that I am seeing with OpenB3D.

I place a light behind the camera.
I load a model to animate.
Everything is fine so far. In my case model is facing away from camera with light on its back as I would expect.
When I set the animate command the model is now rotated 180 on the y axis and the light is still on its back which is now facing away from the camera. Any other non animating objects in scene are still lit correctly.

Here's some code to test. I am using Blitzmax but it should translate easily to other languages.

Code: [Select]
Strict

Framework Openb3d.b3dglgraphics

Local width%=800,height%=600,depth%=0,Mode%=2

Graphics3D width,height,depth,Mode


Local cam:TCamera=CreateCamera()
PositionEntity cam,0, 10,-60

Local light:TLight=CreateLight()
PositionEntity(light, 15, 50, -50)

Local ent:TMesh=LoadAnimMesh("D:\Models\Gupinas\Goblin.b3d")'insert your aniamting model here
Animate(ent, 1, 1.5, 0, 0);


' used by fps code
Local old_ms%=MilliSecs()
Local renders%=0, fps%=0


While Not KeyDown(KEY_ESCAPE)

' control camera
MoveEntity cam,KeyDown(KEY_D)-KeyDown(KEY_A),0,KeyDown(KEY_W)-KeyDown(KEY_S)
TurnEntity cam,KeyDown(KEY_DOWN)-KeyDown(KEY_UP),KeyDown(KEY_LEFT)-KeyDown(KEY_RIGHT),0


UpdateWorld
RenderWorld

' calculate fps
renders=renders+1
If MilliSecs()-old_ms>=1000
old_ms=MilliSecs()
fps=renders
renders=0
EndIf

Text 0,0,"FPS: "+fps
Text 0,40,"Arrows: turn camera, WSAD: move camera"

Flip

Wend
End


Offline Flanker

  • Jr. Member
  • **
  • Posts: 22
    • Youtube channel on Blitzmax programming prototypes
Re: Animation/Lighting problem with OpenB3D
« Reply #1 on: November 13, 2017, 03:26:20 PM »
Hello, I tried with different b3d models and the lighting works as it should. Can you share your b3d model ?
Everyone knew it was impossible, until someone who didn't know made it.

Offline Kronos

  • Jr. Member
  • **
  • Posts: 4
Re: Animation/Lighting problem with OpenB3D
« Reply #2 on: November 14, 2017, 08:38:06 PM »
OK I have been investigating further and it does appear to be an issue with certain models that I use. I happen to pick two that went wrong when testing initially and assumed issue applied to all.

I tried with both MiniB3D and OpenB3D which showed same results but loading same model into Blitz3D shows no issues. It would appear that the model is initially facing the wrong way when loaded into MiniB3D, but when animating is facing the right way(although lighting is screwed up), assuming Blitz3D is correct.

Weird but at least my faith in OpenB3D is restored (somewhat) ;)



Offline markcwm

  • Full Member
  • ***
  • Posts: 188
Re: Animation/Lighting problem with OpenB3D
« Reply #3 on: November 15, 2017, 04:28:02 AM »
Hi,

glad you fixed it, yes it's best to use Minib3d for comparison tests.

The difference with Blitz3d is that DirectX uses a left handed coordinate system and OpenGL is right: left handed is x axis to left, y up, z away from view, whereas right handed is x to right, y up, z away.

To make code more portable from Blitz3d CameraProject is inverted (on z axis) which means rotation, turn and pitch commands need to be inverted (on x axis), the library inverts the z but not pitch so the wrapper does it.