-
Memcpy(); Errors...
I'll just start off with the code..
Code:
int nVertices = *( word* )pPtr;
NumVertices = nVertices;
Vertices = new Vertex[nVertices];
pPtr += sizeof( word );
int i;
for ( i = 0; i < nVertices; i++ )
{
MS3DVertex * pVertex = ( MS3DVertex* )pPtr;
// Vertices[i].BoneID = pVertex->m_boneID;
memcpy( Vertices[i].vx, pVertex->m_vertex[0], sizeof(float));
memcpy( Vertices[i].vy, pVertex->m_vertex[1], sizeof(float));
memcpy( Vertices[i].vz, pVertex->m_vertex[2], sizeof(float));
pPtr += sizeof( MS3DVertex );
}
Okay, so I'm copying pVertex->m_vertex elements to each element in my structure in code, I'll show you the definitions of each of these structs..
I'm copying from this one
Code:
// Vertex information
struct MS3DVertex
{
byte m_flags;
float m_vertex[3];
char m_boneID;
byte m_refCount;
} PACK_STRUCT;
To this one
Code:
struct Vertex
{
float vx;
float vy;
float vz;
float nx;
float ny;
float nz;
float s;
float t;
unsigned char r,g,b,a;
};
int NumVertices;
Vertex * Vertices;
That is all I'm doing, maybe I'm not using memcpy right?
Here are the errors..
Code:
--------------------Configuration: NeHeGL - Win32 Debug--------------------
Compiling...
MS3D.CPP
\\student\courses\cedar_cliff\computer\senior project\auditorium\engine source\ms3d.cpp(192) : error C2664: 'memcpy' : cannot convert parameter 1 from 'float' to 'void *'
There is no context in which this conversion is possible
\\student\courses\cedar_cliff\computer\senior project\auditorium\engine source\ms3d.cpp(193) : error C2664: 'memcpy' : cannot convert parameter 1 from 'float' to 'void *'
There is no context in which this conversion is possible
\\student\courses\cedar_cliff\computer\senior project\auditorium\engine source\ms3d.cpp(194) : error C2664: 'memcpy' : cannot convert parameter 1 from 'float' to 'void *'
There is no context in which this conversion is possible
Any ideas?
-
How about just doing an assignment like any normal person would?
Vertices[i].vx = pVertex->m_vertex[0];
Of course it doesn't work, you forgot a whole bunch of & to turn things into addresses.
-
For some reason this works though...
Code:
int nTriangles = *( word* )pPtr;
NumTriangles = nTriangles;
Triangles = new Triangle[nTriangles];
pPtr += sizeof( word );
for ( i = 0; i < nTriangles; i++ )
{
MS3DTriangle *pTriangle = ( MS3DTriangle* )pPtr;
int vertexIndices[3] = { pTriangle->m_vertexIndices[0], pTriangle->m_vertexIndices[1], pTriangle->m_vertexIndices[2] };
float t[3] = { 1.0f-pTriangle->m_t[0], 1.0f-pTriangle->m_t[1], 1.0f-pTriangle->m_t[2] };
memcpy( Triangles[i].VertexNormals, pTriangle->m_vertexNormals, sizeof( float )*3*3 );
memcpy( Triangles[i].Textures1, pTriangle->m_s, sizeof( float )*3 );
memcpy( Triangles[i].Textures2, t, sizeof( float )*3 );
memcpy( Triangles[i].VertexIndices, vertexIndices, sizeof( int )*3 );
pPtr += sizeof( MS3DTriangle );
}
Why's this work and that doesn't?
Strange...
I'll go ahead and use an assignment operator, but it is really strange why the code above works but the origional code in the op doesn't :\...
-
> memcpy( Triangles[i].Textures1, pTriangle->m_s, sizeof( float )*3 );
Probably because these are all ARRAYS, and hence become pointers to the first element of the array in this context.
-