Accueil > > > CLASS MATRIX3D.AS - BASIC, POUR AIDER A COMPRENDRE
CLASS MATRIX3D.AS - BASIC, POUR AIDER A COMPRENDRE
Information sur la source
Description
j'ai trouvé un tutorial sur les matrices sur flash-france: http://www.flash-france.com/sections .php?op=viewarticle&secid=1&artid=73 comme le code est plutot moche (non, c vrai, c cool mais mal codé), j'ai decidé de convertir en as2. Voici donc la class.Je ne vais pas expliquer comment ça fonctionne, j'ai compris a peine ce qu'il faut pour pouvoir coder cette class. Amusez vous, cette class est basic, mais ej compte en developer une plus complete pour des besoins personnels
Source
- dans matrix3d.as:
- ----------------------------------
- class matrix3d {
- var polygons:Array;
- var points:Array;
- //
- // Constructor
- function matrix3d() {
- polygons = new Array();
- points = new Array();
- }
- //
- // register a new point
- function registerPoint(x:Number, y:Number, z:Number) {
- var temp:Array = new Array();
- var i:Number;
- for (i=1; i<4; i++) {
- temp[i] = new Array();
- }
- temp[1][1] = x;
- temp[2][1] = y;
- temp[3][1] = z;
- return temp;
- }
- //
- // register a new polygon -> 3 points
- function registerPolygon(pt1:Array, pt2:Array, pt3:Array) {
- polygons.push({pt1:pt1, pt2:pt2, pt3:pt3});
- }
- //
- //
- function mtxMutiply(matriceA, matriceB) {
- var i, j, k:Number;
- var temp:Array = new Array();
- for (i=1; i<4; i++) {
- temp[i] = new Array();
- }
- for (i=1; i<=3; i++) {
- temp[i][1] = 0;
- for (j=1; j<=3; j++) {
- for (k=1; k<=3; k++) {
- temp[i][j] += matriceA[i][k]*matriceB[k][j];
- }
- }
- }
- return temp;
- }
- //
- //
- function getRotationMatrix_x(radian:Number) {
- var rx:Array = new Array();
- var i:Number;
- for (i=1; i<4; i++) {
- rx[i] = new Array();
- }
- rx[1][1] = 1;
- rx[1][2] = 0;
- rx[1][3] = 0;
- rx[2][1] = 0;
- rx[2][2] = Math.cos(radian);
- rx[2][3] = -Math.sin(radian);
- rx[3][1] = 0;
- rx[3][2] = Math.sin(radian);
- rx[3][3] = Math.cos(radian);
- return rx;
- }
- //
- //
- function rotate_x(radian:Number) {
- var i:Number;
- for (i=0; i<=polygons.length-1; i++) {
- polygons[i].pt1 = mtxMutiply(getRotationMatrix_x(radian), polygons[i].pt1);
- polygons[i].pt2 = mtxMutiply(getRotationMatrix_x(radian), polygons[i].pt2);
- polygons[i].pt3 = mtxMutiply(getRotationMatrix_x(radian), polygons[i].pt3);
- }
- return true;
- }
- //
- //
- function drawMatrix(cible:MovieClip, cOption:Object) {
- var i:Number;
- cible.lineStyle(cOption.lineStyle.thickness, cOption.lineStyle.color, cOption.lineStyle.alpha);
- for (i=0; i<=polygons.length-1; i++) {
- cible.beginFill(cOption.fillStyle.color, cOption.fillStyle.alpha);
- cible.moveTo(polygons[i].pt1[1][1], polygons[i].pt1[2][1]);
- cible.lineTo(polygons[i].pt2[1][1], polygons[i].pt2[2][1]);
- cible.lineTo(polygons[i].pt3[1][1], polygons[i].pt3[2][1]);
- cible.lineTo(polygons[i].pt1[1][1], polygons[i].pt1[2][1]);
- cible.endFill();
- }
- }
- }
-
-
dans matrix3d.as:
----------------------------------
class matrix3d {
var polygons:Array;
var points:Array;
//
// Constructor
function matrix3d() {
polygons = new Array();
points = new Array();
}
//
// register a new point
function registerPoint(x:Number, y:Number, z:Number) {
var temp:Array = new Array();
var i:Number;
for (i=1; i<4; i++) {
temp[i] = new Array();
}
temp[1][1] = x;
temp[2][1] = y;
temp[3][1] = z;
return temp;
}
//
// register a new polygon -> 3 points
function registerPolygon(pt1:Array, pt2:Array, pt3:Array) {
polygons.push({pt1:pt1, pt2:pt2, pt3:pt3});
}
//
//
function mtxMutiply(matriceA, matriceB) {
var i, j, k:Number;
var temp:Array = new Array();
for (i=1; i<4; i++) {
temp[i] = new Array();
}
for (i=1; i<=3; i++) {
temp[i][1] = 0;
for (j=1; j<=3; j++) {
for (k=1; k<=3; k++) {
temp[i][j] += matriceA[i][k]*matriceB[k][j];
}
}
}
return temp;
}
//
//
function getRotationMatrix_x(radian:Number) {
var rx:Array = new Array();
var i:Number;
for (i=1; i<4; i++) {
rx[i] = new Array();
}
rx[1][1] = 1;
rx[1][2] = 0;
rx[1][3] = 0;
rx[2][1] = 0;
rx[2][2] = Math.cos(radian);
rx[2][3] = -Math.sin(radian);
rx[3][1] = 0;
rx[3][2] = Math.sin(radian);
rx[3][3] = Math.cos(radian);
return rx;
}
//
//
function rotate_x(radian:Number) {
var i:Number;
for (i=0; i<=polygons.length-1; i++) {
polygons[i].pt1 = mtxMutiply(getRotationMatrix_x(radian), polygons[i].pt1);
polygons[i].pt2 = mtxMutiply(getRotationMatrix_x(radian), polygons[i].pt2);
polygons[i].pt3 = mtxMutiply(getRotationMatrix_x(radian), polygons[i].pt3);
}
return true;
}
//
//
function drawMatrix(cible:MovieClip, cOption:Object) {
var i:Number;
cible.lineStyle(cOption.lineStyle.thickness, cOption.lineStyle.color, cOption.lineStyle.alpha);
for (i=0; i<=polygons.length-1; i++) {
cible.beginFill(cOption.fillStyle.color, cOption.fillStyle.alpha);
cible.moveTo(polygons[i].pt1[1][1], polygons[i].pt1[2][1]);
cible.lineTo(polygons[i].pt2[1][1], polygons[i].pt2[2][1]);
cible.lineTo(polygons[i].pt3[1][1], polygons[i].pt3[2][1]);
cible.lineTo(polygons[i].pt1[1][1], polygons[i].pt1[2][1]);
cible.endFill();
}
}
}
Conclusion
utilisation: ---------------------------------- va r cOption:Object = new Object({lineStyle:new Object(), fillStyle:new Object()}); cOption.lineStyle.thickness = -1; cOption.lineStyle.color = 0x0; cOption.lineStyle.alpha = 100; cOption.fillStyle.color = 0x336699; cOption.fillStyle.alpha = 20;
var m3d:matrix3d = new matrix3d(); m3d.registerPolygon(m3d.registerPoint( 60, -40, -20), m3d.registerPoint(140, 80, -20), m3d.registerPoint(110, 20, 70)); m3d.registerPolygon(m3d.registerPoint(140, 80, -20), m3d.registerPoint(110, 20, 70), m3d.registerPoint(180, -20, -20)); m3d.registerPolygon(m3d.registerPoint(110, 20, 70), m3d.registerPoint(180, -20, -20), m3d.registerPoint(60, -40, -20)); var itv = setInterval(function () { _root.clear(); m3d.rotate_x(0.1); m3d.drawMat rix(_root,cOption); }, 50);
------------------------------------------- ----------------- comme d'hab, je fournis le code, mais pas le service apres vente.
Historique
- 13 juillet 2004 22:35:01 :
- cette source bouge vers MX2004:CLASS
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|