Fastest vertex rotation method?
Blitz3D Forums/Blitz3D Programming/Fastest vertex rotation method?
| ||
You may have noticed from some of my previous questions that 3d maths isn't really my thing, and I do usually try to write games that don't require a ton of it ( honest ) but it's unavoidable sometimes. I'm about to start work on it now, and I figure I'm going to create a pivot, rotate it and use TFormPoint and TFormNormal to rotate the vertices and their normals. At least that's what I hope I'm going to do. But before I strain my brain getting the coordinates the right way around and trying to remember which is pitch and which is yaw.. is this the fastest way? If it isn't, what's the fastest way of rotating vertices? |
| ||
I don't quite understand how you can rotate a point.. |
| ||
i think he meant to rotate vertices along a rotation center. |
| ||
RotateEntity entity,pitch#,yaw#,roll#,[,global] Parameters: entity - name of the entity to be rotated pitch# - angle in degrees of pitch rotation yaw# - angle in degrees of yaw rotation roll# - angle in degrees of roll rotation global (optional) - true if the angle rotated should be relative to 0,0,0 rather than a parent entity's orientation. False by default. |
| ||
.. thats not quite it i think, that would be for an entity, hes talking about an individual vertex |
| ||
Maybi this it will workfor i=1 to nrpoint ;or what ever :) x#=x_ponit(i) y#=y_ponit(i) z#=z_ponit(i) ; rotate x-axis x1#=x# y1#=(cos(ang)*y#)+(sin(ang)*z#) z1#=(sin(ang)*z#)-(cos(ang)*y#) ;roate y-axis x2#=(cos(ang)*x1#)+(sin(ang)*z1#) y2#=y1# z2#=(sin(ang)*z1#)-(cos(ang)*x1#) ;rotate z-axis x1#=(cos(ang)*x2#)+(sin(ang)*y2#) y1#=(cos(ang)*y2#)+(sin(ang)*x2#) z1#=z2# x_ponit(i)=x1# y_ponit(i)=y1# z_ponit(i)=z1# next Note the most optimized code...but I think you get the general idea :) Sveinung |
| ||
Well...my spelling sux!!! Hehe damn I sux Sorry Sveinung |
| ||
for fast calculate, precalculate table Sin Cos 4096 elements and optimize the code this: ;precalculate Sin - Cos cx# = cos(angx) : sx# = sin(angx) cy# = cos(angy) : sy# = sin(angy) cz# = cos(angz) : sz# = sin(angz) for i=1 to nrpoint ;or what ever :) x# = x_ponit(i) y# = y_ponit(i) z# = z_ponit(i) ; rotate x-axis x1#=x# y1#=(cx#*y#)+(sx#*z#) z1#=(sx#*z#)-(cx#*y#) ;rotate y-axis x2#=(cy#*x1#)+(sy#*z1#) y2#=y1# z2#=(sy#*z1#)-(cy#*x1#) ;rotate z-axis x1#=(cz#*x2#)+(sz#*y2#) y1#=(cz#*y2#)+(sz#*x2#) z1#=z2# x_ponit(i)=x1# y_ponit(i)=y1# z_ponit(i)=z1# next for very speed use value interger, moltiplicate all value point and sin cos for 10000 and after moltiplicate 0.0001 Bye |
| ||
Someone recently posted (I can't remember who) saying they'd been using a "dummy" quad; rotating that using the native entity commands, and then copying out the vertex co-ords to the target vertices. Something like that, anyway. The intersting thing was that he reckoned it was actually quite a bit faster than using the vertex rotation commands in the code archives. I can't confirm any of this though, it's just what I read. I expect my own rotation commands could do with some optimising too... |