Jump to content
  • Advertisement
Sign in to follow this  
noatom

expression must have arithmetic or unscoped enum type

This topic is 2127 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

[source lang="cpp"]void CalculateTangentArray(long vertexCount, const D3DXVECTOR3 *vertex, const D3DXVECTOR3 *normal,
const D3DXVECTOR2 *texcoord, long triangleCount, const Triangle *triangle, D3DXVECTOR3 *tangent)
{
D3DXVECTOR3 *tan1 = new D3DXVECTOR3[vertexCount * 2];
D3DXVECTOR3 *tan2 = tan1 + vertexCount;
ZeroMemory(tan1, vertexCount * sizeof(D3DXVECTOR3) * 2);

for (long a = 0; a < triangleCount; a++)
{
long i1 = triangle->index[0];
long i2 = triangle->index[1];
long i3 = triangle->index[2];

const D3DXVECTOR3& v1 = vertex[i1];
const D3DXVECTOR3& v2 = vertex[i2];
const D3DXVECTOR3& v3 = vertex[i3];

const D3DXVECTOR2& w1 = texcoord[i1];
const D3DXVECTOR2& w2 = texcoord[i2];
const D3DXVECTOR2& w3 = texcoord[i3];

float x1 = v2.x - v1.x;
float x2 = v3.x - v1.x;
float y1 = v2.y - v1.y;
float y2 = v3.y - v1.y;
float z1 = v2.z - v1.z;
float z2 = v3.z - v1.z;

float s1 = w2.x - w1.x;
float s2 = w3.x - w1.x;
float t1 = w2.y - w1.y;
float t2 = w3.y - w1.y;

float r = 1.0F / (s1 * t2 - s2 * t1);
D3DXVECTOR3 sdir((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r,
(t2 * z1 - t1 * z2) * r);
D3DXVECTOR3 tdir((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r,
(s1 * z2 - s2 * z1) * r);

tan1[i1] += sdir;
tan1[i2] += sdir;
tan1[i3] += sdir;

tan2[i1] += tdir;
tan2[i2] += tdir;
tan2[i3] += tdir;

triangle++;
}

for (long a = 0; a < vertexCount; a++)
{
const D3DXVECTOR3* n = &normal[a];
const D3DXVECTOR3* t = &tan1[a];


// Gram-Schmidt orthogonalize


tangent[a] = (t - n * D3DXVec3Dot(n, t)).Normalize();




}

delete[] tan1;
}[/source]

The above function computes a 3d tangent vector.The problem is on this line:
tangent[a] = (t - n * D3DXVec3Dot(n, t)).Normalize();

The following error appears under 'n': const D3DXVECTOR3* n expression must have arithmetic or unscoped enum type

Share this post


Link to post
Share on other sites
Advertisement

const D3DXVECTOR3* n = &normal[a];
tangent[a] = (t - n * D3DXVec3Dot(n, t)).Normalize();


Your n is pointer; you cannot multiply pointer by float.

Share this post


Link to post
Share on other sites
Both t and n are pointers to D3DXVECTOR3 so you must dereference them to be able to do the subtraction.

Where did you get the code from? I'm personaly quite confused about the second part of the line. The D3DXVECTOR3 doesn't have any Normalize() method, does it?

I'd say the following should work:


tangent[a] = *t - *n * D3DXVec3Dot(n, t);
D3DXVec3Normalize(&tangent[a], &tangent[a]);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!