Updating vertex buffer removes transform [Solved]

Jerdak

09-07-2012 02:34:02

This follows on my last post regarding manually loading data. I have a method that allows me to update my vertices:

public void UpdateVertexPositions(List<Vector3> new_vertices){
unsafe {
float* vdata = (float*)vertex_buffer_.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
AxisAlignedBox aabox = new AxisAlignedBox();

//Fill vertex array
for (int i = 0; i < new_vertices.Count; i++)
{
Vector3 pos = new_vertices;
//pos = (OgreViewNode.Orientation * (pos * OgreViewNode.GetScale())) + OgreViewNode.Position;
*vdata++ = pos.x;
*vdata++ = pos.y;
*vdata++ = pos.z;
aabox.Merge(pos);

}
//OgreEntity.GetMesh()._setBounds(aabox);
//OgreEntity.GetMesh()._setBoundingSphereRadius((float)(aabox.Maximum - aabox.Minimum).Length / 2.0f);
vertex_buffer_.Unlock();
}

}

The code itself runs fine, I can see the vertices updating in real-time. The problem I'm having is that when I update the vertices, the object's in my scene shift back to origin, or what looks to be origin. I've double checked that the updated vertices aren't just way out of alignment by loading them first. When I do that, the models look fine.

So for example I'll have model A that is at position Vector3(10,0,0). When I call my update function the model appears back at 0,0,0 even though the position is still set to Vector3(10,0,0).

My first thought was maybe updating the vertices manually was messing up the boundaries (sphere,boundingbox). Above I have those lines commented out as they did not work. My other thought was that perhaps updating the vertices like this is somehow bypassing the SceneNode's update function so I set the orientation and position of each of my scenenodes again, just after the update, to see if it changed anything. Still nothing.

Any thoughts?

Jerdak

09-07-2012 02:52:03

Turns out I'm an idiot. The problem was unrelated to Ogre. For completeness: When the points are first loaded they are normalized and centered around the origin. I neglected to apply that same process to the points when I would load the next set to update my point clouds. Like I said, I'm an idiot. :oops: