| |||||||
Du magst keine Werbung? Wir auch nicht!
Einfach registrieren und die Werbung ist weg. Diese Nachricht sehen nur nicht registrierte Nutzer.
![]() |
| | LinkBack | Themen-Optionen | Ansicht |
| | #1 (permalink) |
| Neuer User Registriert seit: Jan 2004 Ort: bei Düsseldorf
Beiträge: 76
|
Hallo zusammen, ich hab angefangen eine kleine Wireframe 3D - Engine zu basteln. Ich werd zwar alles neu proggen,da mir die transformationen nicht 100% gefallen,aber vielleicht kann jemand damit was anfangen. Das ist meine erste 3d-Engine überhaupt, auch wenn ich mich vorher schon oft mit 3d beschäftigt habe, also seit nachsichtig mit der Kritik Code: <?
ming_setScale(20.00000000);
ming_useswfversion(6);
$movie = new SWFMovie();
$movie->setDimension(400,400);
$movie->setBackground(0x00, 0x00, 0x00 );
$movie->setRate(31);// mx actionscript
$strAction ="
Math.RAD = Math.PI/180;
//Klassendefinition für einen Punkt
Point= function(x,y,z){
this.x=x;
this.y=y;
this.z=z;
this.x_2d=100;
this.y_2d=100;
};
Point.prototype.move=function(dx,dy,dz){
this.x+=dx;
this.y+=dy;
this.z+=dz;
};
Point.prototype.scale=function(dx,dy,dz){
this.x*=dx;
this.y*=dy;
this.z*=dz;
};
Point.prototype.rotX = function(degrees) {
var cosine = Math.cos(degrees*Math.RAD);
var sine = Math.sin(degrees*Math.RAD);
var tempY = this.y*cosine-this.z*sine;
var tempZ = this.y*sine+this.z*cosine;
this.y = tempY;
this.z = tempZ;
};
Point.prototype.rotY = function(degrees) {
var cosine = Math.cos(degrees*Math.RAD);
var sine = Math.sin(degrees*Math.RAD);
var tempX = this.z*sine+this.x*cosine;
var tempZ = this.z*cosine-this.x*sine;
this.x = tempX;
this.z = tempZ;
};
Point.prototype.rotZ = function(degrees) {
var cosine = Math.cos(degrees*Math.RAD);
var sine = Math.sin(degrees*Math.RAD);
var tempX = this.x*cosine - this.y*sine;
var tempY = this.x*sine + this.y*cosine;
this.x = tempX;
this.y = tempY;
};
Point.prototype.to2d=function(sx,sy){
dis=-300; //sollte änderbar sein
div=this.z+dis;
if(div==0){div=0.0000000001;}
pers = dis/div;
this.x_2d=sx+(this.x*pers);
this.y_2d=sy+(this.y*-pers);
};
//klassendefinition für ein dreieck
Tri=function(p1,p2,p3){
this.p1=p1;
this.p2=p2;
this.p3=p3;
};
Tri.prototype.draw=function(context){
w=200;
h=200;
this.p1.to2d(w,h);
this.p2.to2d(w,h);
this.p3.to2d(w,h);
context.moveTo(this.p1.x_2d,this.p1.y_2d);
context.lineTo(this.p2.x_2d,this.p2.y_2d);
context.lineTo(this.p3.x_2d,this.p3.y_2d);
context.lineTo(this.p1.x_2d,this.p1.y_2d);
};
Tri.prototype.rotate=function(rx,ry,rz){
this.p1.rotX(rx);
this.p2.rotX(rx);
this.p3.rotX(rx);
this.p1.rotY(ry);
this.p2.rotY(ry);
this.p3.rotY(ry);
this.p1.rotZ(rz);
this.p2.rotZ(rz);
this.p3.rotZ(rz);
};
Tri.prototype.move=function(dx,dy,dz){
this.p1.move(dx,dy,dz);
this.p2.move(dx,dy,dz);
this.p3.move(dx,dy,dz);
};
Tri.prototype.scale=function(dx,dy,dz){
this.p1.scale(dx,dy,dz);
this.p2.scale(dx,dy,dz);
this.p3.scale(dx,dy,dz);
};
Quad=function(p1,p2,p3,p4){
this.p1=p1;
this.p2=p2;
this.p3=p3;
this.p4=p4;
};
Quad.prototype.draw=function(context){
w=200;
h=200;
this.p1.to2d(w,h);
this.p2.to2d(w,h);
this.p3.to2d(w,h);
this.p4.to2d(w,h);
context.moveTo(this.p1.x_2d,this.p1.y_2d);
context.lineTo(this.p2.x_2d,this.p2.y_2d);
context.lineTo(this.p3.x_2d,this.p3.y_2d);
context.lineTo(this.p4.x_2d,this.p4.y_2d);
context.lineTo(this.p1.x_2d,this.p1.y_2d);
};
Quad.prototype.move=function(dx,dy,dz){
this.p1.move(dx,dy,dz);
this.p2.move(dx,dy,dz);
this.p3.move(dx,dy,dz);
this.p4.move(dx,dy,dz);
};
Quad.prototype.scale=function(dx,dy,dz){
this.p1.scale(dx,dy,dz);
this.p2.scale(dx,dy,dz);
this.p3.scale(dx,dy,dz);
this.p4.scale(dx,dy,dz);
};
Quad.prototype.rotate=function(rx,ry,rz){
this.p1.rotX(rx);
this.p2.rotX(rx);
this.p3.rotX(rx);
this.p4.rotX(rx);
this.p1.rotY(ry);
this.p2.rotY(ry);
this.p3.rotY(ry);
this.p4.rotY(ry);
this.p1.rotZ(rz);
this.p2.rotZ(rz);
this.p3.rotZ(rz);
this.p4.rotZ(rz);
};
Quad.prototype.to2d=function(viewDistanz){
this.p1.to2d(viewDistanz);
this.p2.to2d(viewDistanz);
this.p3.to2d(viewDistanz);
this.p4.to2d(viewDistanz);
};
Object3D = function(){
this.faces=new Array(); //array der seitenflächen
};
Object3D.prototype.draw=function(context){
i=0;
while(this.faces[i] != null)
{
this.faces[i].draw(context); // jede fläche zeichnet sich selbst :)
i++;
}
};
Object3D.prototype.rotate=function(rx,ry,rz){
i=0;
while(this.faces[i] != null)
{
this.faces[i].rotate(rx,ry,rz);
i++;
}
};
Object3D.prototype.move=function(dx,dy,dz){
i=0;
while(this.faces[i]!=undefined)
{
this.faces[i].move(dx,dy,dz);
i++;
}
};
Object3D.prototype.scale=function(dx,dy,dz){
i=0;
while(this.faces[i]!=undefined)
{
this.faces[i].scale(dx,dy,dz);
i++;
}
};
Object3D.prototype.addFace=function(face){
this.faces.push(face);
};
_root.obj=new Object3D();
_root.obj.addFace(new Quad(new Point(0,0,0),new Point(50,0,0),new Point(50,50,0),new Point(0,50,0))); //ein Quadart wird hinzugefügt
_root.obj.addFace(new Quad(new Point(0,0,50),new Point(50,0,50),new Point(50,50,50),new Point(0,50,50)));
_root.obj.addFace(new Quad(new Point(0,0,0),new Point(0,0,50),new Point(50,0,50),new Point(50,0,0)));
_root.obj.addFace(new Quad(new Point(0,50,0),new Point(0,50,50),new Point(50,50,50),new Point(50,50,0)));
_root.obj.addFace(new Tri(new Point(0,50,0),new Point(50,50,0),new Point(25,90,25))); //ein dreieck wird hinzugefügt
_root.obj.addFace(new Tri(new Point(0,50,50),new Point(50,50,50),new Point(25,90,25)));
_root.obj.move(-25,-25,-25); //Objekt zentrieren (nicht wirklich notwendig)
_root.obj.scale(2,2,1);
";
$movie->add(new SWFAction(str_replace("\r", "", $strAction)));
$movie->nextFrame();
$movie->nextFrame();
$strAction="
_root.clear();
_root.lineStyle(1,0x888888);
_root.obj.rotate(((_root._ymouse/100)-2)*3,((_root._xmouse/100)-2)*3,0); //objekt drehen
//_root.obj.move(_root._xmouse/100,_root._ymouse/100,0);
_root.obj.draw(_root); // Jede Fläche zeichnet sich selbst (Tri oder Quad)
gotoAndPlay(2);
";
$movie->add(new SWFAction(str_replace("\r", "", $strAction)));
$movie->nextFrame();
header("Content-type:application/x-shockwave-flash");
$movie->output(9);
?> SIGINT P.S.: Ich hoffe irgendwann mal Flat-Shading einbauen zu können,aber dafür muss ich noch ein paar Mathe - Tuts durchlesen ![]() P.P.S.: Hab's ganz vergessen: Die SWF wird per MING erzeugt Geändert von sigint (25-07-2004 um 10:36 Uhr) |
| | |
| | #3 (permalink) |
| Neuer User Registriert seit: Jan 2004 Ort: bei Düsseldorf
Beiträge: 76
|
So, jetzt sieht es etwas besser aus und das Timing wird per setInterval gesteuert ActionScript:
|
| | |
![]() |
| Lesezeichen |
| Themen-Optionen | |
| Ansicht | |
| |