Welcome, Guest. Please login or register.

Author Topic: My Amos-vector question moved here  (Read 3408 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline GreatLorTopic starter

  • Jr. Member
  • **
  • Join Date: Apr 2004
  • Posts: 72
    • Show all replies
My Amos-vector question moved here
« on: May 21, 2004, 01:25:21 PM »
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 )
 

Offline GreatLorTopic starter

  • Jr. Member
  • **
  • Join Date: Apr 2004
  • Posts: 72
    • Show all replies
Re: My Amos-vector question moved here
« Reply #1 on: May 21, 2004, 02:06:27 PM »
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.
 

Offline GreatLorTopic starter

  • Jr. Member
  • **
  • Join Date: Apr 2004
  • Posts: 72
    • Show all replies
Re: My Amos-vector question moved here
« Reply #2 on: May 21, 2004, 05:03:35 PM »
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.
 

Offline GreatLorTopic starter

  • Jr. Member
  • **
  • Join Date: Apr 2004
  • Posts: 72
    • Show all replies
Re: My Amos-vector question moved here
« Reply #3 on: May 22, 2004, 01:55:49 PM »
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
 

Offline GreatLorTopic starter

  • Jr. Member
  • **
  • Join Date: Apr 2004
  • Posts: 72
    • Show all replies
Re: My Amos-vector question moved here
« Reply #4 on: May 24, 2004, 01:09:31 PM »
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.
 

Offline GreatLorTopic starter

  • Jr. Member
  • **
  • Join Date: Apr 2004
  • Posts: 72
    • Show all replies
Re: My Amos-vector question moved here
« Reply #5 on: May 28, 2004, 02:26:43 PM »
@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 ?