Rotating each triangle in a surface individually?
Blitz3D Forums/Blitz3D Programming/Rotating each triangle in a surface individually?
| ||
Before I ask, I should point out that I'm allergic to matrices and the only way I know how to do vertex transformations is matrices... so hopefully there's an easier way. I have a surface made up of lots of triangles. Each triangle is separate, however. Think single surface particle engine. That's the deal. I can move each triangle without too much fuss. But How do I rotate each triangle around it's respective center? |
| ||
A bit of Sine and Cosine. And it depends whether you want to rotate it about its Pitch, Yaw or Roll. It would be something like this for pitch: pitch#=pitch#+1 yaw#=yaw#+.5 For i=0 To 2 ang# = 120*i ;<-- Triangle Point x# = Sin(ang)*Cos(yaw) y# = Sin(ang)*Sin(pitch) z# = Cos(ang)*Cos(pitch)+Sin(ang)*Sin(yaw) VertexCoords surf,i,x,y,z Next A good way of working out whether to multiply by Sin or Cos is to remember that Sin starts off as 0 and goes to 1 at 90 degrees, whereas Cos is the other way round. So in terms of the x,y,z coordinates, think whether your vertex coordinate is stretched out at the start or if it is 0. |
| ||
I've looked it over several times, but I can't honestly say as I understand it. Like I said, I never got taught 3d geometry and I really don't get much of it. Blitz usually handles it for me. /EDIT : removed all the old waffle I wrote before. Basically I just want a function which will rotate a triangle from a single surface mesh as though it was a separate entity. If each triangle was a separate entity I could use : TurnEntity triangle,ax#,ay#,az# Well I need an equivalent to that. I'm gonna post a request in the features request forum. It'd be nice if we didn't have to struggle with the maths. Particularly since multiple surfaces cause such a performance hit. |
| ||
Hi Sybixsus, I didn't see your post here. Same reply. The below will rotate a selected triangle in increments of ax#,ay#,az# Any use ? :) Function TurnTriangle(surf,index,ax#,ay#,az#) Local CosAX#=Cos(ax),SinAX#=Sin(ax) Local CosAY#=Cos(ay),SinAY#=Sin(ay) Local CosAZ#=Cos(az),SinAZ#=Sin(az) Local x#[2],y#[2],z#[2],i[2] Local avx#,avy#,avz# For a=0 To 2 i[a]=TriangleVertex(surf,index,a) x[a]=VertexX(surf,i[a]) y[a]=VertexY(surf,i[a]) z[a]=VertexZ(surf,i[a]) avx=avx+x[a] avy=avy+y[a] avz=avz+z[a] Next ox#=avx/Float(3) oy#=avy/Float(3) oz#=avz/Float(3) For a=0 To 2 x[a]=x[a]-ox y[a]=y[a]-oy z[a]=z[a]-oz ;rotate on x ty#=y[a]*cosAX+z[a]*sinAX z[a]=z[a]*cosAX-y[a]*sinAX y[a]=ty ;rotate on y tx#=x[a]*cosAY+z[a]*sinAY z[a]=z[a]*cosAY-x[a]*sinAY x[a]=tx ;rotate on z tx#=x[a]*cosAZ+y[a]*sinAZ y[a]=y[a]*cosAZ-x[a]*sinAZ x[a]=tx x[a]=x[a]+ox y[a]=y[a]+oy z[a]=z[a]+oz VertexCoords surf,i[a],x[a],y[a],z[a] Next End Function |
| ||
Oh yes, that's perfect. I was kludging something together from some code that Fredborg posted a while back, but it wasn't working quite right ( my fault, not his ) That's great.. thanks for the help :D You should put that in the codearchives.. I can't be the only one who would benefit from that. |
| ||
...I was kludging something together from some code that Fredborg posted a while back... Hey, I don't remember any code supposed to doing that :) Just out of curiosity, what was it? Good to see people giving a hand :) Fredborg |
| ||
It was a thread Rob started in this forum, where he said he was looking for something to replace turnentity() and rotateentity() for a single surface mesh. It involved creating a pivot, rotating it to the correct angle and then using TFormPoint to calculate the new coordinates for each vertex. |
| ||
I think you are talking about the single surface particle system... but i don't see it in the forum :( |
| ||
Yes that sounds like it. But I don't think it's in this forum, I think it was in advanced 3d. Off to see if I can find it. Edit : Yep, it's there still. http://www.blitzbasic.com/bbs/posts.php?topic=18309 It was rotating a single vertex, but I figured I could kludge it into what I needed, but I didn't get it quite right. I didn't spend long on it though, because Birdie posted his function shortly after I started. |