Thread: 3d
View Single Post
  #29  
Old 08-08-2004, 03:57 PM
amonrabr amonrabr is offline
Scripter
Join Date: Nov 2001
Location: Brazil
Posts: 374
amonrabr is on a distinguished road
Remember these equations?
EQ. 1
x = r * cos(Theta)
EQ. 1-1
y = r * sin(Theta)

Legend:
P = Phi
T = Theta

Phii + Theta = is the total angle.. From the center of the pizza to the tomato. Alitlle bit dificult to undestand.. Just read dont care if you dont understand for now.. One day that will make sence and you back here and read again.. I hope Graal 3D will not come so fast, so Im not writing all this for nothing =PPP

Cosine Identity:
EQ. 3
Cos(P+T)= Cos(P)*Cos(T)-Sin(P)*Sin(T)
Sine Identity:
EQ. 3-1
Sin(P+T)= Sin(P)*Cos(T)+Cos(P)*Sin(T)

Let (P+T) = Theta(Just one angle)...
EQ. 1 becomes:
x = r * cos(P+T)
EQ. 1-1
y = r * sin(P+T)

Then by substitution from EQ 1 and 1-1
EQ. 1 becomes:
x' = r * (Cos(P)*Cos(T)-Sin(P)*Sin(T))
EQ. 1-1 becomes:
y' = r * (Sin(P)*Cos(T)+Cos(P)*Sin(T))

Distributing r:

x' = r*Cos(P)*Cos(T) - r*Sin(P)*Sin(T)
y' = r*Sin(P)*Cos(T) + r*Cos(P)*Sin(T)

And looking back at EQ's 1 and 1-1:
Let P = Theta...
x = r * cos(P)
y = r * sin(P)

Then by substitution:

x' = x * Cos(T) - y * Sin(T)
y' = y * Cos(T) + x * Sin(T)

That's how you prove the 2d rotation formula. =))

Final equations:

Newx=oldx*Cos(Theta) - oldy*Sin(Theta)
Newy=oldy*Cos(Theta) + oldx*Sin(Theta)

Ok.. Why I explained 2D rotation first? Couse for 3D rotation you have 3 equations..

1st) rotate in X
2nd) rotate in Y
3rd) rotate in Z

o.O

If you know the 2D rotaion its pretty easy.. you just let the Cordinate you want to change equal. And rotate the others.. Very logic..

Rotation on the Z
NewY = y*cos(Thetax) - z*sin(Thetax)
NewZ = z*cos(Thetax) + y*sin(Thetax)
y = NewY
z = NewZ

Rotation on the Y
NewZ = z*cos(Thetay) - x*sin(Thetay)
NewX = x*cos(Thetay) + z*sin(Thetay)
x = NewX

Rotation on the Z
NewX = x*cos(Thetaz) - y*sin(Thetaz)
NewY = y*cos(Thetaz) + x*sin(Thetaz)

Rotatedx = NewX
Rotatedy = NewY
Rotatedz = NewZ

:P easy huh? Your near to make any 3D thing in Graal 2D

You also needs to learn Cull mode.. Not used in these stars but used in my poly script =)
Whats Cull mode?
You make a caracter.. graal shouldnt lose time drawing the part of caracter thats not visible..
We can use normals for that.. normals come from the center of each triangle.. Why triangle? Couse when can model anything with triangles..
Sherek 2 caracters where made all by triangles.. any 3D thing is made by triangles..
To find a center of a trinagle is pretty easy.. you have 3 vertex right? x1,y1,x2,y2,x3 and y3? The center is:
Xcenter = (x1+x2+x3)/3;
Ycenter = (y1+y2+y3)/3;
You can use it in all 2d poly.. All Vertexes dived by number of vertexs.


For the light I used in my poly.. is just get the mouse distance for each Triangle (or face).. and how near it is.. more light.. or bigger R,G,B value.. In my poly script I just count the mouse position when its near the poly.. Maybe for this reason someone posted here he didnt like my Light way.. But if I didnt do that.. noone would see the poly when the mouse is too far..

Backing to script..

Everything I showed up.. I use in this part..

From that we can make a fast 3*3 Rotation matrix

There the letters “c” in front each thing means “cos()”
Letter s in front each thing means “sin()”

X axis
xx = cy*cz
xy = sx*sy*cz - cx*sz
xz = cx*sy*cz + sx*sz

Y axis
yx = cy*sz
yy = cx*cz + sx*sy*sz
yz = -sx*cz + cx*sy*sz

Z axis
zx = -sy
zy = sx*cy
zz = cx*cy

Difficult when you see the first time.. But it becomes pretty easy when you use it alot.. I promise.. I fell free to make other kinds of rotation when I learned this..

PHP Code:
  //pré calculo
  
xx cos(ay)*cos(az);
  
xy sin(ax)*sin(ay)*cos(az) - cos(ax)*sin(az);
  
xz cos(ax)*sin(ay)*cos(az) + sin(ax)*sin(az);
  
yx cos(ay)*sin(az);
  
yy cos(ax)*cos(az) + sin(ax)*sin(ay)*sin(az);
  
yz = -sin(ax)*cos(az) + cos(ax)*sin(ay)*sin(az);
  
zx = -sin(ay);
  
zy sin(ax)*cos(ay);
  
zz cos(ax)*cos(ay);

  
//calculo
  
sx sx*xx sy*xy sz*xz;
  
sy sx*yx sy*yy sz*yz;
  
sz sx*zx sy*zy sz*zz 
Uf.. the difficult part is done..

Distancia is out “distance”.. My scripts always in portuguese

Distance from star is our LENS less its Z distance.. When using Right Hand or Left hand its different..

If Distance is bigger then 0.. or its in out LENs we draw..

Meux means “myx” =P

Learning portuguese huh? Lol...

Center of the screen plus LENS multiplicate for position..

I said alot on top.. But to change 3D to 2D you just have to divide X and Y for Z
=P

new_x = x/z
new_y = y/z

where Z is the distance.. I used my LENS in this distance..

PHP Code:
  distancia lente sz;
  if(
distancia>0){
    
meux= (screenwidth/2) + (lente sx distancia);
    
meuy= (screenheight/2) - (lente sy distancia); 
Draw my stars.. I made a zoom way.. so Stars are bigger or smaller when Z is near or far..
PHP Code:
    showimg 300+i,light4.png,meux,meuy;
    if((
sz/300)>0.05){
      
changeimgzoom 300+i,sz/300;
    }else{
      
changeimgzoom 300+i,0.05;

    }
    
changeimgcolors 300+i,1,0,1,.99;
    
changeimgvis 300+i,5;

  } 
Come is my flag to tell if it has to come for out eyes.. or ours LENS
Is the position is bigger the LENS we lost it.. lest put again in other screen position..
If its not.. We add Z.. so it comes for our eyes..
PHP Code:
  if(come>0){
    if(
zz[i]>lente){
      
xx[i]=random(-500,500);
      
yy[i]=random(-500,500);
      
zz[i]=random(-500,500);

    }
    
zz[i]+=10;
  }

Hide player so it doesnt bore us..
And the timeout to repeat what is not in “created” part..
PHP Code:
hideplayer 0.05;
timeout 0.05
Pressing.. the keys 1..2...3.. or 4..
It turns on/off.. each flag.. that take care of one kind of moviment..
PHP Code:
if(keypressed){

  if(
strcontains(#p(1),1)){
    
come=1-come;
  }
  if(
strcontains(#p(1),2)){
    
rotatex=1-rotatex;
  }
  if(
strcontains(#p(1),3)){
    
rotatey=1-rotatey;
  }
  if(
strcontains(#p(1),4)){
    
rotatez=1-rotatez;
  }



Done ^_^

We made a 3D script.. now lets post alot of 3D scripts on Forums to help other people too
=))

I think Kai will agree to help people too if needed.. You can pm me if you want to.. not sure If I will answer it.. lol

Hugs see ya..

Omg.. all my Saturday morning writing this, I hope someone reads it

X.x


I had to use more posts.. couse I used more then 10,000 letters.. lol