Easy Pointer Problem

Started by
1 comment, last by pebben 19 years, 11 months ago
Hi There! My problem is that I try to interpolate between two meshes, which works fine when I use the D3DXVec3Lerp function. But when I´ll try to do my own interpolation it doesn´t seem to work. And I think I know why. The lerp function always allocate a new adress for pVert. D3DXVec3Lerp(pVert, pVert, pVertGoal, 0.001 * elapsedMs); My Code doesn´t allocate a new adress. How do I make my code to always allocate a new adress in each frame like the lerp function? //This is my code. //V1 + s(V2-V1. (standard interpolation code) float s = 0.001f * elapsedMs; pVert = &(*pVert + s*((*pVertGoal - *pVert)));
/Have A Nice Day -Patrick
Advertisement
quote:
The lerp function always allocate a new adress for pVert.

No, this is not correct. D3DXVec3Lerp does not allocate any memory. It expects you to pass in the addresses of variables that have already been allocated. It would be bad design if DXVec3Lerp were to allocate memory, because it would then have to rely on the developer to free that memory. When writing software, whoever allocates memory should be responsible for freeing it as well.

To answer your question, try this:
//This is my code.
float s = 0.001f * elapsedMs;
D3DXVECTOR3 vTemp;
D3DXVec3Subtract( &vTemp, pVertGoal, pVert );
D3DXVec3Scale( &vTemp, &vTemp, s );
D3DXVec3Add( pVert, pVert, &vTemp );


When you use the overloaded operators, it''s really just making calls to these functions anyway. This way, your code is much cleaner and easier to mess with.

neneboricua
hehe, maybe I was wrong about the memory question. But now it works fine. Big Thanx!!!


/Have A Nice Day -Patrick
/Have A Nice Day -Patrick

This topic is closed to new replies.

Advertisement