Forum Topic: Rendering 3D: Rotation

(449 views • 7 replies)

This topic is 1 page long.

<< < > >>
None

Tool-Of-The-System

Reply To Post Reply & Quote

Posted at: 4/30/05 01:40 AM

Tool-Of-The-System EVIL LEVEL 23

Sign-Up: 06/25/01

Posts: 2,538

Hey. I've been trying for a while to make a good 3D Flash engine and have been successful on the way. What I'm trying to do is make an engine that will draw a matrix of points that looks like this:

_|X|Y|Z|
0|#|#|#|
1|#|#|#|
2|#|#|#|
3|#|#|#|
4|#|#|#|
5|#|#|#|

And then the movie would use the drawing methods to make this shape.

What I'm trying to figure out is how I can get the X and Y rotations to affect the drawTo() X and Y coordinates without many bugs.

Here is a copy of my current script which will give you the front side of a star on your movie... you don't need to draw anything:

points = [[0, 0, 50], [0, -50, 0], [14.8, -20.2, 0], [47.5, -15.4, 0], [23.8, 7.7, 0], [29.4, 40.5, 0], [0, 25, 0], [-29.4, 40.5, 0], [-23.8, 7.7, 0], [-47.5, -15.4, 0], [-14.8, -20.2, 0], [0, 0, -50]];
shapes = [[0, 1, 2], [0, 2, 3], [0, 3, 4],[0, 4, 5], [0, 5, 6], [0, 6, 7], [0, 7, 8], [0, 8, 9], [0, 9, 10], [0, 10, 1]];
_root.createEmptyMovieClip("drawthis", -20);
drawthis._x = Stage.width/2;
drawthis._y = Stage.height/2;
this.onEnterFrame = function() {
drawthis.clear();
drawthis.lineStyle(1, 0x000000, 100);
drawthis.beginFill(0xFF0000, 100);
for (s=0; s<shapes.length; s++) {
drawthis.moveTo(points[shapes[s][0]][0], points[shapes[s][0]][1]);
for (p=1; p<shapes[s].length; p++) {
drawthis.lineTo(points[shapes[s][p]][0], points[shapes[s][p]][1]);
}
}
drawthis.endFill();
};

I was thinking that if a certain key was down I would have all the points in the POINTS array changed so that one number would have a chunk given to it from another number but that doesn't seem to be working very well.


None

Tombulgius

Reply To Post Reply & Quote

Posted at: 4/30/05 01:51 AM

Tombulgius LIGHT LEVEL 12

Sign-Up: 01/24/05

Posts: 650

It looks very, very brilliant, considering I have no idea of what any of it means.


None

Vengeance

Reply To Post Reply & Quote

Posted at: 4/30/05 07:20 AM

Vengeance EVIL LEVEL 28

Sign-Up: 03/18/05

Posts: 5,033

wow thats a long script and im not sure if anyone can help you with it. except maybe one of the pro's if they work on it for a while

========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

None

BLUEleaf

Reply To Post Reply & Quote

Posted at: 4/30/05 07:26 AM

BLUEleaf LIGHT LEVEL 21

Sign-Up: 09/24/03

Posts: 4,714

Matrixes drive me crazy, I still can't really figure them out either =/

There is an example out there somewhere on manipulating matrixes... Just wish I could remember where it was.


Thinking

Apocalypse-2087

Reply To Post Reply & Quote

Posted at: 4/30/05 11:10 AM

Apocalypse-2087 EVIL LEVEL 03

Sign-Up: 03/14/05

Posts: 11

try asking that question on the programming area. I hade no idea u could do that with flash though.I do understand the idea very well but not the code (that was the only way to draw in another programming language i learned a while back (its a begginers to teach the concepts) but nice job!


None

Begoner

Reply To Post Reply & Quote

Posted at: 4/30/05 11:33 AM

Begoner NEUTRAL LEVEL 10

Sign-Up: 10/10/04

Posts: 3,038

Well, instead of changing every element in the array to fit the rotation (which is bound to give you a lot of glitches), maybe you could have two arrays -- one that represents the orientation of the the shape in space, and another that represents how the object would look relative to a camera somewhere in space. You could use trig to figure out the second array, given an (x, y) position of the camera.


None

dELtaluca

Reply To Post Reply & Quote

Posted at: 4/30/05 11:59 AM

dELtaluca LIGHT LEVEL 20

Sign-Up: 04/16/04

Posts: 5,559

3d engine

my 3d engine so far,
arrows to move, drag mouse to rotate,

......
......
......

to rotate an object you have to multiply each of its coordinates by a rotation matrice
where A is the angle in radians

[1 0 0 ]
Rx = [0 cosA -sinA],
[0 sinA cosA ]

[cosA 0 sinA]
Ry = [ 0 1 0 ],
[-sinA 0 cosA]

[cosA -sinA 0]
Rz = [sinA cosA 0],
[ 0 0 1]

for example lets say you have coordinate (100,50,10) and you wanted to rotate it 45 degrees about (50,50,50) around the y axis

coord = [100,50,10];
centre = [50,50,50];
//get the cos and sin of the angle
cos = Math.cos((45*Math.PI/180));
sin = Math.sin((45*Math.PI/180));
//take away the centres coordinate and rotate
x = cos*(coord[0]-centre[0])+sin*(coord[2]-centre[2]);
z = (-sin)*(coord[0]-centre[0])+cos*(coord[2]-centre[2]);
//add the centres coordinate back
coord[0] = x+centre[0];
coord[2] = z+centre[2];

My social worker says im special!

BBS Signature

None

dELtaluca

Reply To Post Reply & Quote

Posted at: 4/30/05 12:01 PM

dELtaluca LIGHT LEVEL 20

Sign-Up: 04/16/04

Posts: 5,559

hmmm, all the spaces have dissapeard but you should be able to see the different items still

My social worker says im special!

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 11:27 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!