Archived

This topic is now archived and is closed to further replies.

Easy Pointer Problem

This topic is 4948 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)));

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites