Results 1 to 15 of 15

Thread: DirectX8 - Z, about the code u posted me

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118

    DirectX8 - Z, about the code u posted me

    Hi Z

    I gave up with billboarding using the code on the site so now I am attempting to use yours.

    You mentioned multiplying a vertex by a matrix is there a special function for that or do u just use *.

    I only know D3DXMatrixMultiply which as u know multiplies 2 matrices.

    Thanks

    Dan

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    D3DXVec3Transform() is the function you want. Look it up in the SDK Docs =).

    Z.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Cheers Z

    Ive seen that function 2 or 3 times iiin the last hour time to work out what it is all about I guess .

    TY

    Dan

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    lol what can i say, thanks again mate, that buildboard faces the camera so damn well.

    Im just playing wiv angles now to see if it is fixed on any axis.

    Top code (and its not too scary either)

    I O U 1, well I must O U 5 by now .........

    Cheers v much

    Dan

  5. #5
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    My pleasure =).

    Z.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Z

    Hi. Well it seems pretty muched fixed on all 3 axis which I can see would be good for the sun or something. I was wondering if you can tell me if Im being inefficent in my use of the function (I know DrawPrimitiveUP is crappy but other than that).

    MatrixBB is your function altered a little but you'll know the parameters passed to it (I take it it was written in C++ originally)

    Square1 is the vertex data.

    VResult is just a temp d3dvector4

    -------------------- CODE ------------------------

    MatTemp = MatrixBB(MatView, MakeVector(0, 0, 0))

    For i = 0 To 3

    D3DXVec3Transform VResult(i), Square1(i).pos, MatTemp

    VertexTemp(i) = MakeTLVertex(MakeVector(VResult(i).x, VResult(i).y, VResult(i).z), Square1(i).colour, Square1(i).tex)

    Next i

    D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, VertexTemp(0), Len(VertexTemp(0))

    -------------- END CODE -------------------------------

    I seemed to make an awful lot of temp variables there that was I was thinking maybe it was inefficient.

    D3DXVec3Transform returns a d3dvector4. I take it u just ignore the 4th value and use x,y and z only.

    Also I dont suppose you have any code for a Y-Axis fixed billboard please so I can use it for trees in my project?

    Cheers for your help Z that function is great

    Dan

  7. #7
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    When you get a D3DXVECTOR4, you divide the X, Y, and Z valuse by the W value. The W is a scaler value.

    About fixing an axis... I will have to get back to you on that. I believe that I can find out for you in a little bit.

    As to your code... Yes, there are a few temp variables, but it is essentially what I use.

    And yes, the function was written in C++. I converted it over for you when I posted it =).

    Z.

  8. #8
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Ok, there is a C++ Billboarding sample that comes with the SDK. The code is here:
    Code:
    if( vDir.x > 0.0f )
            D3DXMatrixRotationY( &m_matBillboardMatrix, -atanf(vDir.z/vDir.x)+D3DX_PI/2 );
        else
            D3DXMatrixRotationY( &m_matBillboardMatrix, -atanf(vDir.z/vDir.x)-D3DX_PI/2 );
    Easy enough, A little trig, using the direction vector from the eye point to the look at point.

    Now, we just want to rotate around the Y axis, so lets see if this works =):
    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 = 0.0 'a._21
    	result._13 = a._31
    	result._14 = 0.0
    
    	result._21 = 0.0 'a._12
    	result._22 = 1.0 'a._22
    	result._23 = 0.0 'a._32
    	result._24 = 0.0
    
    	result._31 = a._13
    	result._32 = 0.0 '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
    I simply omitted values from the transpose that are not included in a Y axis rotation matrix. Try it out =).

    Z.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Z

    Im sure this is the right code Z. It seems to tilt by the Y axis only but I think that is an optical illusion since the camera is moving so therefore the Y axis must be fixed and X and Z face the camera. Correct?

    I think I should put some ground in my little billboard project so it doesnt get too confusing .

    By the way I wasnt sure wot u meant by the trig stuff so I left that out.

    Thanks for making billboarding so much easier for me Z, I was sure getting confused b4 u saved me on this 1. I take it u skipped the direcx4vb.com billboarding lesson 2 .

    Cheers mate. I will make sure I put by Z and Dan on my project . Maybe they will give u a degree 2 (or a second degree to add to the one u prob have already).

    Dan

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    PS

    Z U have been great and I know u must have work to do so ignore this if u r busy but if u do have tme how did you work out which values to change in the function?

    I dont mind not knowing this if u dont have time but if u do it would be interesting to know.

    Cheers

    Dan

  11. #11
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Glad it works =). Do some more tests with it, and let me know if it really is correct =).

    What it SHOULD do is NOT rotate on either the X or Z axes. Take something sitting on your desk, and hold it up. If you imagine that there is an invisible line sticking through the top and bottom of the object, and you rotate around this line, you are rotating on the Y axis. If the line is sticking from left to right, you are rotating around the x axis, and if the line sticks through the front and back, you rotate around the z axis.

    The trig I gave you was just a little reference. That is how the MS sample does it.

    I actually started with point sprites, but decided that they were too slow when I needed scaled particles.

    As for the matrix thing. Each type of transformation matrix is set up the same way, like so:
    Code:
    Translation
    [1 0 0 0]
    [0 1 0 0]
    [0 0 1 0]
    [x y z 1]
    
    Scaling
    [x 0 0 0]
    [0 y 0 0]
    [0 0 z 0]
    [0 0 0 1]
    
    Rotation X
    [1 0        0       0]
    [0 cos(t) sin(t) 0]
    [0 -sin(t) cos(t) 0]
    [0 0 0 1]
    
    Rotation Y
    [cos(t) 0 -sin(t) 0]
    [0 1 0 0]
    [sin(t) 0 cos(t) 0]
    [0 0 0 1]
    
    Rotation Z
    [cos(t) sin(t) 0 0]
    [-sin(t) cos(t) 0 0]
    [0 0 1 0]
    [0 0 0 1]
    I simply omitted the values that werent rotations around the Y axis.

    Z.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Cheers Z I see what u did now

    Is this matrix info in the SDK, Im looking for it there but no luck just yet.

    Anyway Im off to do some testing now, some ground, a few trees and a sun should do the job

    Cheers mate

    Dan

  13. #13
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    No, it isnt in the SDK Docs. There are a few for some of the more complicated matrices (projection matrices, and such). You can usually find them on the net.

    Z.

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Z

    After spending hours last nite on it I am having troubles with billboards still .

    I made a project and had probs wiv it so I made another one and had exactly the same prob.

    Everything works but only if the ground (the vertices making up the forest floor or wotever ground used) has a y value of 0.

    If not the billboards start 'sinking' below ground level (boo hoo)

    I understand if u r busy Z but if not would u mind have a quikc look at these projects please (I hate to ask u but u r the only one who is familiar with the BB code used).

    Thanks

    Dan

    PS Both projects attempt the same thing and are set to a sreen res of 1600 x 1200. The project attaced to this reply has better GFX (and therefore an increased amount of code that is irrelevant to billboarding). The next project is attached to the next reply.
    Attached Files Attached Files

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Soz the first 1 is the 1 wiv the bad GFX. I cant post the 1 wiv good GFX coz its too big. The 1 i attached above is better for demonstration purposes neway. It demonstrates both Y-Axis fixed bb's (and by uncommenting one line of code) bb's that are not fixed on any axis.

    Hey Z u have helped me loads already its cool if u r too busy at the mo

    Cheers either way

    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