问题描述:

I have two simple questions:

First question:

Given is an object in OpenGL in an android application.

I want to apply phyics on the object like Gravtiy.

For this I've implemented a Public PositionVector {x,y,z,1.0f};

In the Object Object. So for example: Sphere.PositionVector = {0f,0f,0f,1f}

for the center of screen.

When I do the movement now, I have a modelMatrix and to update the Position should I multiply the modelMatrix with the PositionVector? But then I will still get 0,0,0,1.

mulitplyMV(tempVector,0,modelMatrix,0,PositionVector,0);

Where is the mistake? Or: What is the usual way to do this?

My goal is to have always the current positionvector of the Sphere.

Second question:

Does the shader have to do anything with the physics? Or may I calculate the gravtiy and the resulting vectors in the javaCode and apply then a translateMatrix to the modelMatrix?

Greetings,

Phil

网友答案:

So the first thing that really jumped out at me, was the question about movement. Normally if the movement was only for a visual effect, multiplying your position with a model matrix would be fine, but obviously you'll be wanting to handle collisions and that sort of thing as well.

What I normally do, is I keep track of each objects position, and update that value whenever it moves. When I draw my object, I first do a pass to leave out all objects that aren't in view and then only draw what my camera is seeing. So in this case, you'll only be drawing what is actually visible on the phone's screen at the moment.

So if you have a view matrix for your camera, to keep it simple for now you can leave out view culling, but you'll multiply your objects current position with the model matrix(in this case it is just an identity so it doesn't have any impact), and additionally with the view matrix and projection matrix. So its something like vec3 viewSpacePosition = projectionMatrix * viewMatrix * modelMatrix * position; (assuming I'm remembering that one correctly.)

Your physics calculations can be done either in your shaders or in your java code, though I recommend doing it on the java side while still getting the hang of things. OpenCL and transform feedback buffers can be quite tricky when you're still learning how some of the stuff works.

For the physics portion of your code, I would highly recommend taking a look an Glen Fiedler's series on game physics, you can find it here.

If you have any more questions, or if there is something you're still uncertain of let me know. :) Good luck!

相关阅读:
Top