Results 1 to 18 of 18

Thread: [Resolved] old normals question.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    Question [Resolved] old normals question.

    Dx7 VB6

    VB Code:
    1. 'Calculate Normals
    2.                     ' subtract point2 - point1 to find a vector
    3.                     ' no light, trying new method of point3 - point2
    4.                     DataVector2.X = PointX(3) - PointX(2)
    5.                     DataVector2.Y = PointY(3) - PointY(2)
    6.                     DataVector2.Z = PointZ(3) - PointZ(2)
    7.                    
    8.                     'subtract point3 - point1 to find another vector
    9.                     DataVector3.X = PointX(2) - PointX(1)
    10.                     DataVector3.Y = PointY(2) - PointY(1)
    11.                     DataVector3.Z = PointZ(2) - PointZ(1)
    12.                    
    13.                    
    14.                     ' find vector cross product and store in DV1
    15.                     DataVector1.X = (DataVector2.Y * DataVector3.Z) - (DataVector2.Z * DataVector1.Y)
    16.                     DataVector1.Y = (DataVector2.Z * DataVector3.X) - (DataVector2.X * DataVector1.Z)
    17.                     DataVector1.Z = (DataVector2.X * DataVector3.Y) - (DataVector2.Y * DataVector1.X)
    18.                    
    19.                     ' normalize vector for light
    20.                     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?
    Last edited by Waxy; Nov 17th, 2005 at 01:30 AM.
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

  2. #2
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: old normals question.

    This is how I do it in DX8:

    VB Code:
    1. Public Function Generate_Triangle_Normals(p0 As UNLIT_VERTEX, p1 As UNLIT_VERTEX, p2 As UNLIT_VERTEX) As D3DVECTOR4
    2.  
    3. '//0. Variables required
    4.     Dim v01 As D3DVECTOR 'Vector from points 0 to 1
    5.     Dim v02 As D3DVECTOR 'Vector from points 0 to 2
    6.     Dim vNorm As D3DVECTOR 'The final vector
    7.  
    8. '//1. Create the vectors from points 0 to 1 and 0 to 2
    9.     D3DXVec3Subtract v01, Create_Vector(p1.X, p1.Y, p1.Z), Create_Vector(p0.X, p0.Y, p0.Z)
    10.     D3DXVec3Subtract v02, Create_Vector(p2.X, p2.Y, p2.Z), Create_Vector(p0.X, p0.Y, p0.Z)
    11.  
    12. '//2. Get the cross product
    13.     D3DXVec3Cross vNorm, v01, v02
    14.  
    15. '//3. Normalize this vector
    16.     D3DXVec3Normalize vNorm, vNorm
    17.  
    18. '//4. Return the value
    19.    
    20.     Generate_Triangle_Normals.X = vNorm.X
    21.     Generate_Triangle_Normals.Y = vNorm.Y
    22.     Generate_Triangle_Normals.Z = vNorm.Z
    23.    
    24. End Function

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    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:
    1. Dx.VectorNormalize vNorm ', vNorm
    2.    
    3. Debug.Print "----vnorm"
    4. Debug.Print vNorm.X
    5. Debug.Print vNorm.Y
    6. Debug.Print vNorm.Z
    7.  
    8. '//4. Return the value
    9.  
    10.     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?
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

  4. #4
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: old normals question.

    What did you declare your variables as?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

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

    Missing the days of GWBasic 1.1
    WaxyStudios.com

  6. #6
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    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?

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    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.
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

  8. #8
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    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.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    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.
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

  10. #10
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: old normals question.

    You can't use DX9 in VB6. It's only for the .NET languages.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    Re: old normals question.

    Yeap, that's micro soft for you.

    AKA = bill gate's weenie.
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

  12. #12
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: old normals question.

    He's forcing everyone to use his "oh I'm so proud of my" .NET framework.

  13. #13
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: old normals question.

    Is that a fact?

  14. #14
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    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.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    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.
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    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.
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

  17. #17
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: old normals question.

    So your problems resolved?

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    Re: old normals question.

    Think so. i just have to figure out how to tell which surface is closest.
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width