[Resolved] old normals question.
Dx7 VB6
VB Code:
'Calculate Normals
' subtract point2 - point1 to find a vector
' no light, trying new method of point3 - point2
DataVector2.X = PointX(3) - PointX(2)
DataVector2.Y = PointY(3) - PointY(2)
DataVector2.Z = PointZ(3) - PointZ(2)
'subtract point3 - point1 to find another vector
DataVector3.X = PointX(2) - PointX(1)
DataVector3.Y = PointY(2) - PointY(1)
DataVector3.Z = PointZ(2) - PointZ(1)
' find vector cross product and store in DV1
DataVector1.X = (DataVector2.Y * DataVector3.Z) - (DataVector2.Z * DataVector1.Y)
DataVector1.Y = (DataVector2.Z * DataVector3.X) - (DataVector2.X * DataVector1.Z)
DataVector1.Z = (DataVector2.X * DataVector3.Y) - (DataVector2.Y * DataVector1.X)
' normalize vector for light
Dx.VectorNormalize DataVector1
when i run the program, and i check for the normal of the surface i collide with, i get this in my debug:
Impacted Normal----
-1.#IND
-1.#IND
-1.#IND
it doesn't matter what direction the normal is facing.
i need normals here, not because i'm working with light, but
because i'm working with collisions. it'll help me figure out the sliding.
Am i not doing something wrong?
Re: old normals question.
This is how I do it in DX8:
VB Code:
Public Function Generate_Triangle_Normals(p0 As UNLIT_VERTEX, p1 As UNLIT_VERTEX, p2 As UNLIT_VERTEX) As D3DVECTOR4
'//0. Variables required
Dim v01 As D3DVECTOR 'Vector from points 0 to 1
Dim v02 As D3DVECTOR 'Vector from points 0 to 2
Dim vNorm As D3DVECTOR 'The final vector
'//1. Create the vectors from points 0 to 1 and 0 to 2
D3DXVec3Subtract v01, Create_Vector(p1.X, p1.Y, p1.Z), Create_Vector(p0.X, p0.Y, p0.Z)
D3DXVec3Subtract v02, Create_Vector(p2.X, p2.Y, p2.Z), Create_Vector(p0.X, p0.Y, p0.Z)
'//2. Get the cross product
D3DXVec3Cross vNorm, v01, v02
'//3. Normalize this vector
D3DXVec3Normalize vNorm, vNorm
'//4. Return the value
Generate_Triangle_Normals.X = vNorm.X
Generate_Triangle_Normals.Y = vNorm.Y
Generate_Triangle_Normals.Z = vNorm.Z
End Function
Re: old normals question.
Thanks for the help, i translated it to DX7 but i get an error.
it's made progress but i've started coming with an 'Overflow'.
I set it to tell me the normals in the debug as it generates them.
here's what i come across as output:
VB Code:
Dx.VectorNormalize vNorm ', vNorm
Debug.Print "----vnorm"
Debug.Print vNorm.X
Debug.Print vNorm.Y
Debug.Print vNorm.Z
'//4. Return the value
If vNorm.Z > 0 Then '<----error line
debug output:
----vnorm
0
0
1
----vnorm
0
0
-1
----vnorm <---- error normal
-1.#IND
-1.#IND
-1.#IND
What could be causing this?
Re: old normals question.
What did you declare your variables as?
Re: old normals question.
D3DVECTORs.
but looking at the latest output it may be a mapping error i'm fighting with. look at the P0 and P1 for the last output.
Debug.Print "--------VNormals----------"
Debug.Print vNorm.X
Debug.Print vNorm.Y
Debug.Print vNorm.Z
Debug.Print "p0----"
Debug.Print p0.X
Debug.Print p0.Y
Debug.Print p0.Z
Debug.Print "p1----"
Debug.Print p1.X
Debug.Print p1.Y
Debug.Print p1.Z
Debug.Print "p2----"
Debug.Print p2.X
Debug.Print p2.Y
Debug.Print p2.Z
--------VNorm----------
0
0
-1
p0----
-8
392
-112
p1----
0
392
-112
p2----
0
248
-112
--------VNorm----------
-1.#IND
-1.#IND
-1.#IND
p0----
0
392
-112
p1----
0
392
-112
p2----
0
248
-112
Re: old normals question.
I accidently gave you the old code I had. Didn't have a choice really since I was at work and my latest DX stuff was at home, so the code I have above should do it. Can you upload the project you have?
Re: old normals question.
Too big.
File Too Large. Limit for this filetype is 500.0 KB. Your file is 1.40 MB.
i have to include certain textures, maps, and model files for it to work.
Re: old normals question.
Ever thought of using DirectX8 instead? They made D3D a lot easier to work with in that one, and DX8 is my strong point.
Re: old normals question.
Why not just go all out and use DX9c?
How much easier could it make it?
hell, to be honest, i can't even remember how i got it to work in Dx7 - been that
long sience i looked at it.
Re: old normals question.
You can't use DX9 in VB6. It's only for the .NET languages.
Re: old normals question.
Yeap, that's micro soft for you.
AKA = bill gate's weenie.
Re: old normals question.
He's forcing everyone to use his "oh I'm so proud of my" .NET framework.
Re: old normals question.
Re: old normals question.
Yep. Sad but true. It got to the point to where his new Windows Vista was rumored to run and only run .NET apps as well.
Re: old normals question.
Well, so much for using normals to calculate collisions.
i'm stumped.
I was thinking "hum... if i could use the normals to decide wich way the surface is
facing then i'd know what direction to slide the player/camera"
but now i see that apparently normals are allways possitive. that doesn't seem to
wook too good with my theory.
Re: old normals question.
oops, my bad. apparently i'm colliding into more than one surface at a time and it's
taking the first one it finds, that's all i need to fix. there may be hopes for me yet.
Re: old normals question.
So your problems resolved?
Re: old normals question.
Think so. i just have to figure out how to tell which surface is closest.