Newton Error

Previous topic - Next topic

matty47

Hi, I have been fiddling with the Newton examples and am sure that the dddCollision sample worked previously however now when I compile and run this file the ball drops throught the "ground" object. I am sure that I have note changed the code but here it is anyway
Code (glbasic) Select
LOCAL dtime
LOCAL org[] // just a dummy
LOCAL force[]

X_LOADOBJ  "ground.ddd", 0
LOADSPRITE "ground.bmp", 0
X_LOADOBJ  "sphere.ddd", 1
DIM force[3]

// initialize Newton Engine
NewtonCreate()

// default material
NewtonMaterialSetDefaults( 1, .9, .2, .9, .9)

ball = NewtonCreateSphere(.8, .8, .8, org[])
// position ball
NewtonBodySetPosition(ball, 0,12,3)
// enable dynamics
NewtonConvexCollisionCalculateInertialMatrix(ball, 1)
// enable gravity for ball
NewtonBodySetForceAndTorqueCallback(ball)
NewtonBodySetGravity(ball,0,-9.81,0)
NewtonBodySetAutoFreeze(ball, FALSE)


// solid, static ground
ground = NewtonCreateDDD(0, 0)

WHILE TRUE
NewtonUpdate(GETTIMER(), 6)
force[0] = -MOUSEAXIS(0)*3
force[2] = -MOUSEAXIS(1)*3
NewtonBodyAddTorque(ball, force[])
X_MAKE3D 1,100, 45
X_CAMERA 20, 20, -10, 0,0,0

X_AMBIENT_LT 0, RGB(255,255,255)

X_SCALING .8, .8, .8
NewtonDrawBody(ball, 1,0)
X_SCALING 1,1,1
X_SETTEXTURE 0,-1
NewtonDrawBody(ground, 0,0)
SHOWSCREEN
WEND


Using version 5.322
Thanks
Matthew

Kitty Hello

#1
There's a bug.
Please change this code:
Code (glbasic) Select

FUNCTION NewtonCreateDDD: id_ddd, frame
LOCAL tri[]
DIM tri[3][9] // uh-oh! Make sure GLBasic is aware of at least 2D arrays!


The problem was, that GLBasic tries to minimize the maximum array size for you. But the code is INLINE, thus GLBasic does not pay much attention to that. So, we have to inform the compiler that we need 2D arrays for sure, but doing a "DIM tri[3][9]" before the inline code.
I'll add it with the next update, but you can do it yourself, too.

matty47

Thanks for the quick reply
=D