Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use btTransform function getOpenGLMatrix? #20

Open
dvon opened this issue Apr 10, 2012 · 5 comments
Open

How to use btTransform function getOpenGLMatrix? #20

dvon opened this issue Apr 10, 2012 · 5 comments

Comments

@dvon
Copy link

dvon commented Apr 10, 2012

I can't get btTransform's getOpenGLMatrix function to work. Here's what I thought should work:

var m = new Array(16);
transform.getOpenGLMatrix(m);

I've tried various other things, but can't seem to get anything back from getOpenGLMatrix. I can get my code to work if I use getBasis().getRow()... and getOrigin(), and use that to make a matrix, but that seems like a very roundabout way to do it.

(I can't setOpenGLMatrix to work either, but I assume the issue is probably the same, since both functions expect a pointer to a btScalar array in the original Bullet version.)

@kripken
Copy link
Owner

kripken commented Apr 10, 2012

The bullet functions can't deal with a native JS object like that, I think that is the problem here. getOpenGLMatrix receives a simple float pointer. You should allocate some memory and pass it that pointer, then read from that memory. This might work but I haven't tested it:

var buffer = Ammo.malloc(16*4);
transform.getOpenGLMatrix(buffer);
var jsBuffer = HEAPF32.subarray(buffer/4, buffer/4 + 16)
Ammo.free(buffer);

@dvon
Copy link
Author

dvon commented Apr 10, 2012

malloc and free don't seem to be accessible. Here's something I tried. It runs, but doesn't seem to produce the correct matrix.

var buffer = Ammo.allocate(16, 'float', 1 /* ALLOC_STACK */);
var transform = new Ammo.btTransform();
transform.getOpenGLMatrix(buffer);
var matrix = Ammo.HEAPF32.subarray(buffer / 4, buffer / 4 + 16);

// Ammo.free(buffer);
Ammo.destroy(transform);

@kripken
Copy link
Owner

kripken commented Apr 11, 2012

@cjcliffe , you were doing something similar to this, I think? Do you remember what worked for you?

@kripken
Copy link
Owner

kripken commented Apr 11, 2012

Note that in the example above, you need to allocate 16*4 because each float takes 4 bytes.

@computersarecool
Copy link

Is there any update to this? I would like to use that function if it is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants