|
-
Aug 31st, 2002, 03:12 PM
#1
Thread Starter
Lively Member
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
-
Aug 31st, 2002, 03:36 PM
#2
Junior Member
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?!
-
Aug 31st, 2002, 03:47 PM
#3
Thread Starter
Lively Member
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
-
Aug 31st, 2002, 03:50 PM
#4
Frenzied Member
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.
-
Aug 31st, 2002, 04:00 PM
#5
Junior Member
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
-
Aug 31st, 2002, 04:20 PM
#6
Thread Starter
Lively Member
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.
-
Aug 31st, 2002, 04:53 PM
#7
Frenzied Member
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.
-
Aug 31st, 2002, 05:26 PM
#8
Thread Starter
Lively Member
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
-
Aug 31st, 2002, 09:21 PM
#9
Thread Starter
Lively Member
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
-
Sep 1st, 2002, 06:31 AM
#10
Junior Member
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
-
Sep 1st, 2002, 12:40 PM
#11
Thread Starter
Lively Member
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
-
Sep 1st, 2002, 12:41 PM
#12
Thread Starter
Lively Member
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
-
Sep 1st, 2002, 02:53 PM
#13
Junior Member
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
-
Sep 1st, 2002, 03:03 PM
#14
Frenzied Member
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.
-
Sep 1st, 2002, 03:22 PM
#15
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|