Imagination PowerVR SDK Blog

moving particular mesh in scene


#1

Hello,

I'm using the IntroducingPOD demo from the OGL 1.1 SDK, one the iPhone, as a basis/template for a game I'm working on. The scene file stores a mesh that serves as the track/level, a camera, lighting, and for now a sphere (I plan to include various other objects to which my question applies as well).

I also have a vec4 array that stores a path, that camera is placed on a node in that path and looks at a node X nodes ahead (x depending on interpolation steps of the path). I simply update the vFrom and vTo of the camera to make it follow the path.

Now I'm trying to place an object on a certain node, in this case the target node. Basically a sphere to show the target the camera is looking at. I have that sphere in the same scene file. Its props are stored in "ring" and the title of the model is ZTargetSphere.

My question: where in renderscene (assuming it shouldn't be done in drawmesh) should I override the "position" (and also rotation later on) of a particular mesh?  I've been trying different things but I'm kinda looking for the proper thing to do as well. I guess I could get it to work with gltranslate if I store the mesh in the scene on 0,0,0 but I think I should change the model matrix/view instead.

Code:
for(int i = 0; i < (int)m_Scene.nNumMeshNode; ++i)
    {
        SPODNode& Node = m_Scene.pNode;

        // Gets the node model matrix
        PVRTMat4 mWorld;
        m_Scene.GetWorldMatrix(mWorld, Node);
        
        const char  *sphereTitle;
        sphereTitle = "ZTargetSphere";
        int testi = strcmp(sphereTitle, Node.pszName);
        
        PVRTMat4 mModelView;
        if (testi==0) {
            //NSLog(@"loading ZTargetSphere");
            mWorld.f[12]=ring.position.x;
            mWorld.f[14]=ring.position.y;
            mWorld.f[13]=ring.position.z;
            
            // glTranslatef(ring.position.x, ring.position.y, ring.position.z);
            mModelView = m_mView * mWorld;
        } else {
            // Multiply the view matrix by the model (mWorld) matrix to get the model-view matrix
            mModelView = m_mView * mWorld;
        }
        
        myglLoadMatrix(mModelView.f);



JMan2010-10-14 22:25:27

#2

I just solved my problem. Besides flipping the y and the z… I was placing the target sphere way too close to the camera Embarrassed


#3

Glad you spotted the problem. Please post again if you have further questions and if you want to tell us how you’re getting on with your projectSmile