|
Register or have you forgotten your password?
|
|
|
| Amiga OS -- Development This particular forum deals with issues regarding development for all versions of AmigaOS. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||||||||
|
Too much caffeine
![]()
Join Date: Apr 2004
Posts: 72
|
First I must say that yesterday I came up with a quicker way to do the rotation (no use of square-roots - boy was that STUPID ?! :-) )
If anyone has any experience with vector-programming please give your opinions, here fallows; first the intit for the base-vectors: ax#=50 ay#=0 az#=0 bx#=0 by#=-50 bz#=0 cx#=0 cy#=0 cz#=50 here is the main loop: do gosub rotate_ab gosub rotate_bc gosub rotate_ca wait vbl cls 0 ; Double-buffering is not important right now loop Here's the 'rotate_ab' subroutine: ; I use array 'siin#()' to store some sinus values (it's faster) rotate_ab: ;two coordinate vectors for base vector a's new pos. (rotation) a1x#=siin#(91)*ax# a1y#=siin#(91)*ay# a1z#=siin#(91)*az# b1x#=siin#(1)*bx# b1y#=siin#(1)*by# b1z#=siin#(1)*bz# ;two coodinate vectors for base vector b's new pos. b2x#=siin#(91)*bx# b2y#=siin#(91)*by# b2z#=siin#(91)*bz# a2x#=siin#(1)*-ax# a2y#=siin#(1)*-ay# a2z#=siin#(1)*-az# ; now adding the two vectors of each base vector to them ; vector a ax#=a1x#+b1x# ay#=a1y#+b1y# az#=a1z#+b1z# ; vector b bx#=b2x#+a2x# by#=b2y#+a2y# bz#=b2z#+a2z# return ; and two similar subroutines for the rotations around the two other axis (which I will not include here). So is THIS the way others do vector rotations or are there faster (and more complicated) ways ? Thanx in advance ! (hope somebody answers this :-D ) |
||||||||
|
|
|
|
|
#2 | ||||||||
|
Master Sock Abuser
|
If I were you I'd probably make a generalised function to do the Matrix math, and use it on your data.
I can't remember if AMOS handles functions properly or not though :-(
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
||||||||
|
|
|
|
|
#3 | ||||||||
|
Too much caffeine
![]()
Join Date: Apr 2004
Posts: 72
|
by 'generalised function' do you mean a a subroutine that takes input parameters (function) ? in that case, sure I know how to the most elegant and fast functions, but my question was if the actual vector rotations I do are THE way everyone did/do or not.
|
||||||||
|
|
|
|
|
#4 | |||||||||
|
Master Sock Abuser
|
Quote:
A function is a unit of code, that takes variables and returns a result. "Sin(x)" is an example of a fuinction. - I can't follow what you have done, there are far to many variables all over the place, if you turned it into a function then it would be easier to see... If you used C (or even Blitz Basic) you could make a verctor data type that would add clarity to your code.
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
|||||||||
|
|
|
|
|
#5 | ||||||||
|
Too much caffeine
![]()
Join Date: Apr 2004
Posts: 72
|
Please give an example of what you mean.
You mean like: (in c) //********************************************* // vectors a,b and c float a[3]={50,0,0} float b[3]={0,-50,0} float c[3]={0,0,50} int main() { rot(a,b,1) // rotate a and b (around c) +1 postion rot(b,c,2) // rotate b and c (around a) +2 postions rot(c,a,3) // rotate c and a (around b) +3 postions } void rot(float *vec1,float *vec2,int degr) { .... .... } //********************************************** Is that what you ment ? however I dont remember the functions for mathematic operations in C, so I cant go further in that language, but if that is what you ment I then will get back to you with appropriate function(s) in AMOS. *EDIT* I'll read your post tomorrow. |
||||||||
|
|
|
|
|
#6 | ||||||||
|
Master Sock Abuser
|
I was thinking that you could make a vector data type:
struct vector { float x; float y; float z; }; struct vector a; struct vector b; struct vector c; int main() { c=rot(a,b,1); a=rot(b,c,2); b=rot(c,a,3); return 0; }; vector rot(struct vector fist_vec , struct vector second_vec , int position) { /* Do something to the two vectors*/ struct vector return_vec; return_vec.x = first_vec.x * second_vec.x / position; return return_vec; }; I can't really see what you are trying to do though :-/ (as demonstrated by my random example). Whatever, data structures and function will make you code far easier to read and optimise than procedures and arrays. Blitz Basic supports data types and functions, use that instead of AMOS.
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
||||||||
|
|
|
|
|
#7 | ||||||||
|
Too much caffeine
![]()
Join Date: Apr 2004
Posts: 72
|
Well, I dont have any problems whatsoever with not using structures, simply because the languages I'm playing with right now doesnt support them, anyway, I didnt get what "return_vec.x = first_vec.x * second_vec.x / position;" is supposed to do, will "return_vec.x = first_vec.x * second_vec.x / position;" give the ROTATED x position ??? :-?
Its a shame that others do not contribute in this thread, I find vector-programming quite intresting, anyone who knows of any forum(s) (doesnt matter what platform - although Amiga is preferable) about this subject ? If yes then link, if no then dont bother :-D |
||||||||
|
|
|
|
|
#8 | ||||||||
|
Cult Member
![]()
Join Date: Jun 2002
Posts: 565
|
Firstly, was there a previous thread - you seemed to refer to earlier things, I wasn't sure if there was another thread I should be looking at. If not, what is it you are actually trying to achieve?
Secondly, there appear to be two issues here: what algorithms should be used to do vector maths, and how to actually code it (in that you don't know C that well, but the rest of us get totally confused by AMOS - I mean yes, I know what it means, but it's very unreadable code ![]() Your way of doing things is quite reasonable - you have an orthonormal axis (ie, the 3 vectors) which completely define the rotation, and then you're doing rotations with respect to this local axis. This is certainly a lot better in general than say using Euler angles (which suffer from "Grimbol lock"). For some simple speed ups, it depends on what you're trying to do. Maybe the three rotations in each loop can be combined into a single rotation? It's easiest to work this out by expressing the three rotations as matrices, and multiplying them together. If you're doing the same rotation each time, then the 9 elements of the matrix can then be precomputed. Each of the 9 elements in the set of 3 vectors then requires 3 multiplys and 2 additions, so multiplying the 3 vectors by the rotation matrix costs 27 multiplys and 18 additions. Where as in your method, each individual rotation costs 12 multiplys and 6 additions, which gives a total of 36 multiplys and 18 additions. I think that's right.. One thing to be careful is numerical instability - due to inaccuracies in floating point calculations, your 3 vectors will drift from being orthogonal and normalised vectors, so this may have to be corrected every so often. Now, if you want a faster way of doing things, I suggest you look up about "Quaternions". Basically, they represent a rotation by only 4 numbers (they are actually 4-dimensional equivalents of complex numbers, but don't let that put you off instead of 9, so this means less calculations are required. A knowledge of vector operations such as cross product and dot product is highly recommended before you start learning about Quaternions.Some good information on these is available at http://www.j3d.org/matrix_faq/matrfaq_latest.html (A warning - a lot of tutorials and FAQs on Quaternions have mistakes in some of the calculations! This FAQ as far as I can tell seems to be correct). |
||||||||
|
|
|
|
|
#9 | ||||||||||
|
Cult Member
![]()
Join Date: Jun 2002
Posts: 565
|
Quote:
Quote:
will understand, and hopefully be able to help![]() Some good forums for 3D programming are: http://www.gamedev.net/ http://www.gamasutra.com/ http://www.flipcode.com/ |
||||||||||
|
|
|
|
|
#10 | ||||||||
|
Sockologist
![]()
|
I can't tell you anything AMOS specific, but I do know vector mathematics ;-)
Your best bet is to create a Vector type that has x,y,z,1. You can use a 4x4 matrix to perform any transformation on such a vector - rotation, scaling, translation, projection, you name it. You can multiply these matrices together to create a matrix that can do transformation (scale, rotate, translate, etc.) of your data in a single vector*matrix step. This is basically what OpenGL does to process polygons.
__________________
OCA This isn't SCSI... This is SATA!!! I have CDO. It's like OCD except all the letters are in ascending order. The way they should be. Core2 Quad Q9450 2.66GHz / X48T / 4GB DDR3 / nVidia GTX275 / Linux x64, AROS, Win64 A1XE 800MHz / 512MB / Radeon 9200 / OS4.1 A1200T BPPC 240MHz / 256MB / Permedia 2 / OS 3.1 - OS3.9, OS4 A1200T Apollo 1240 28MHz / 32MB / Mediator1200 / Voodoo 3000 / OS3.9 A1200D Apollo 1240 25MHz (ejector seat ROM edition) / 32MB |
||||||||
|
|
|
|
|
#11 | ||||||||
|
Too much caffeine
![]()
Join Date: Apr 2004
Posts: 72
|
Thanx mdwh2, well I just had some 3-4 weeks of experience with C, but I know plenty enough about it to know that bloodline should send to the function a pointer to the structure rather then sending the whole thing, (enough GreatLor, go to your room, you are grounded - :-D )
Anyway thanx for your infromation, and I will look up those sites, thank you all. |
||||||||
|
|
|
|
|
#12 | ||||||||
|
Too much caffeine
![]()
Join Date: Apr 2004
Posts: 72
|
@mdwh2, hmm, interesting, this cross-product, actually some years back when I was doing my primitive vector rotations (actually before it, when I experimented with 2d-vectors), I noticed that in 2d, for two vectors a and b, orthagonal to eachother, this is the formula to determine vector b's orthagonal position to a (so I only needed to rotate ONE vector):
b.x = a.y b.y = -a.x So this envoked me to try to accomplish this in 3d, but after one days failure (and exhausted brain), I totally gave that up and rotated ALL THREE axis instead, what do you think, am I a genious ( :-D ) for being on my path to (re)discover this "cross-product", or a real IDIOT for not understanding it in 3d ? |
||||||||
|
|
|
|
|
#13 | |||||||||
|
Defender of the Faith
![]()
Join Date: Nov 2002
Posts: 1,031
|
Quote:
|
|||||||||
|
|
|
|
|
#14 | ||||||||||
|
Cult Member
![]()
Join Date: Jun 2002
Posts: 565
|
Quote:
It typically looks something like: ( R11 R12 R13 Tx ) ( R21 R22 R23 Ty ) ( R31 R32 R33 Tz ) ( 0 0 0 1 ) When you multiply this by the vector with elements {x, y, z, 1}, you get the same as if you'd multiplied by vector {x, y, z} by the 3x3 matrix {Rij}, and then translated by the vector T. The bottom row of the 4x4 matrix is such that the 4th element in the vector remains as 1. You can also consider values other than 1 to be treated as a scaling factor, which makes it easier to implement more types of transformations. However, I don't think that all this is any help as far as rotations are concerned - but it's a useful way of doing things if you want to represent translations in your matrix operations. |
||||||||||
|
|
|
![]() |
| Bookmarks |
| Tags |
| amosvector , moved , question |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Running AMOS 3D and AMOS Creator on AGA | SamOS39 | Amiga Software Issues and Discussion | 8 | 02-18-2009 07:44 AM |
| #amiga.org has moved (again) | Blomberg | Amiga.org site announcements | 18 | 02-03-2008 01:55 PM |
| Amix Wiki moved across the Atlantic | Failure | General chat about Amiga topics | 1 | 01-09-2008 06:06 PM |
| ExoticA website has moved. | buzz | Amiga Gaming | 0 | 03-17-2006 02:31 PM |
| Amos, Easy Amos or Amos Pro or maybe Blitz Basic? | CyberStorm | Amiga Software Issues and Discussion | 7 | 12-11-2004 11:06 PM |