Results 1 to 15 of 15

Thread: DirectX8 - Maths

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118

    DirectX8 - Maths

    Hi

    I am doing some heavy maths code at the mo.

    I found a practical use for Sin and Cos (to spin the camera around in a circle).

    I was wondering if any1 could enlighten me as to the use of Tan and Atn. I know Tan Angle = Opposite / Adjacent and I assume Atn Angle = Adjacent / Opposite (having briefly read a help file on Atn).

    Could any1 give me an example of their practical uses with reagrds to DX8 and Graphics. Also any SIMPLE and clear website links on this stuff would help loads.

    I guess since Im working with 100s of triangles I better brush up on my trigonometry.

    Cheers guys

    Dan

  2. #2
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    You first have to know what you want to do

    Have you worked oout camera rotation yourself? I've written an tutorial about that, you could find it on dx4vb.da.ru, but I had a problem rotating the cam. I've found an better way for my BSP renderer.

    Do you think that using sin() and cos() is the best way for vector rotations/camera rotation?!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Yeah I did work it out myself with the help of a few maths tutorials. As for wether or not it is the best method on offer is a totally different matter as this is the only method I know. However it does seem to be simple and works well (well wen rotating around 2 coords at least beyond that it gets a bit more difficult to keep things under 'control'). Also there seems to be some kind of DX related 'issue' wen using the D3DXMatrixLookAtLH function. Something to do with the third set of coords passed.

    The reason I mention Atn is that Im trying to understand some billboarding code. It is very poorly annotated. Bascially the code makes a shape face the camera (Im sure u know wot billboarding is). I think he is using spherical trigonometry to do it but I can find no tutorials on this stuff. Even the spherical trig sites on the web are really poorly written (well m sure they r good if u know ur symbols - which I dont).

    Anyway cheers for ur reply

    Dan

  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    ArcTan = The inverse of tangent. Given value = tan(value2), the inverse would be value2 = atan(value). There are some exceptions, so you would be best off doing a google search.

    Z.

  5. #5
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    Device.GetTransform D3DTS_VIEW, mat
    D3DXVec3Normalize rightVect, MakeVector(mat.m11, mat.m21, mat.m31)
    D3DXVec3Normalize upVect, MakeVector(mat.m12, mat.m22, mat.m32)

    rightVect.X = rightVect.X * (TexCaps.width \ 4)
    rightVect.Y = rightVect.Y * (TexCaps.width \ 4)
    rightVect.Z = rightVect.Z * (TexCaps.width \ 4)

    upVect.X = upVect.X * (TexCaps.height \ 4)
    upVect.Y = upVect.Y * (TexCaps.height \ 4)
    upVect.Z = upVect.Z * (TexCaps.height \ 4)


    tempv.X = mitte.X + rightVect.X - upVect.X
    tempv.Y = mitte.Y + rightVect.Y - upVect.Y
    tempv.Z = mitte.Z + rightVect.Z - upVect.Z
    Vertices(0) = CreateBBV(tempv.X, tempv.Y, tempv.Z, 1, 1)

    tempv.X = mitte.X - rightVect.X - upVect.X
    tempv.Y = mitte.Y - rightVect.Y - upVect.Y
    tempv.Z = mitte.Z - rightVect.Z - upVect.Z
    Vertices(1) = CreateBBV(tempv.X, tempv.Y, tempv.Z, 0, 1)

    tempv.X = mitte.X + rightVect.X + upVect.X
    tempv.Y = mitte.Y + rightVect.Y + upVect.Y
    tempv.Z = mitte.Z + rightVect.Z + upVect.Z
    Vertices(2) = CreateBBV(tempv.X, tempv.Y, tempv.Z, 1, 0)

    tempv.X = mitte.X - rightVect.X + upVect.X
    tempv.Y = mitte.Y - rightVect.Y + upVect.Y
    tempv.Z = mitte.Z - rightVect.Z + upVect.Z
    Vertices(3) = CreateBBV(tempv.X, tempv.Y, tempv.Z, 0, 0)



    This code does all you need to render billboards. It's the easiest way to render billboards, but you couldn't use the code for Y axis fixed billboards

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Cheers guys.

    I guess I just like to understand my code before I use it. Do u understand wat is actually happening with that code or do u just use it? I guess its better for me if i understand what is going on wiv code so (1) i can alter it as i need to (2) so if my lecturers ask me what the code does i can tell them else i might get done for plagariasm (copying - i dont know why i used that big word)

    Dan

    PS I am doing a DX8 project for college (explains the lecturers thing)

    PPS Any1 know of any other billboarding tutorials (Im using the Directx4vb.com one at the mo - its good but understandbly its hard to follow)

    PPPS I do understand wiv the code u gave that matrices are a 4x4 grid and that u are altering the values of matrix grid coords wiv the code but thats about as far as I understand.

    PPPPS Cheers for your help btw and dont worry if u cant explain it Ill prob just stick some code I dont understand in anyway if I have to.

  7. #7
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    I dont even understand the Billboarding matrix function I gave you =). I just use it =).

    Besides, its only plagarism if you claim it to be yours =).

    Z.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Z

    I think I could spend forever trying to work this out so I think Ill follow your lead. Just gonna work through the DX4VB tut on billboards a few more times then call it a day. At least Ill familiarise myself with the code a bit .

    Cheers mate

    Dan

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Lupin

    Hi

    I looked at the code u gave but couldnt suss of what 'TexCaps' is, the rest of it seems manageable.

    Could you explain please? Any offers elsewhere on this 1?

    TY

    Dan

  10. #10
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    TexCaps is simply the texture caps of my D3Dtexture, it describes the size of the billboard.

    The mitte-vector is the center position of the billboard ("mitte" = german word for center)

    I think this code is really easy to understand, it simply uses the view matrix and gets the "edges" of the view

    I've seen the tutorial for this code on an C++ website

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Lupin

    Cheers for your help. Z gave me some well good code for billboards that does pretty much the same as this. I think its more manageable than this code even though it is less 'understandable'. However, I am kinda on the hunt for some code that will render Y-Axis fixed billboards since I wanna render some trees using billboards. Do u know of any please?

    Thanks

    Dan

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Lupin

    By the way I do appreciate the code u gave and will play wiv it a bit to see which method I prefer. Cheers .

    Dan

  13. #13
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    I would like to see the code from Z too

    I don't know of any other billboard code (expect the one from dx4vb.da.ru) and I don't think that it's possible to change my code to be used for Y aligned billboards (I've tried it already ), sorry

  14. #14
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Code:
    Public Sub MatrixMatrixBillboardTranspose(result As D3DMATRIX8, a As D3DMATRIX8 , x As Single, y As Single, z As Single)
    	result._11 = a._11
    	result._12 = a._21
    	result._13 = a._31
    	result._14 = 0.0
    
    	result._21 = a._12
    	result._22 = a._22
    	result._23 = a._32
    	result._24 = 0.0
    
    	result._31 = a._13
    	result._32 = a._23
    	result._33 = a._33
    	result._34 = 0.0
    
    	result._41 = x
    	result._42 = y
    	result._43 = z
    	result._44 = a._44
    End Sub
    Pass in a matrix that will retrieve the result of the function. The second parameter is the current view matrix. The three Singles are the position of the billboard's center. The fucntion will then compute an appropriate billboard matrix. You then multiply the resulting matrix by the vertices that make up the billboard itself. It should align the billboard to the camera.

    Z.

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Lupin

    Check out the 'Z about the code u posted me thread', its all about advice from Z on billboards, great stuff! Testing it now!

    Dan

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