Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13

Discussione: oggetti 3d

  1. #1

    oggetti 3d

    come faccio a creare un oggetto 3d che ruota sul asse?
    La teoria è quando si sa tutto ma non funziona niente.
    La pratica è quando funziona tutto ma nn si sa il perchè.
    In ogni caso si finisce sempre a coniugare la teoria con la pratica: Non funziona niente e non si sa il perchè.
    Albert Einstein
    Slackware 10.2 Fluxbox 9.0.12

  2. #2
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    Dipende dall'oggetto Che cos'è?

  3. #3
    Utente di HTML.it L'avatar di nestore
    Registrato dal
    Feb 2002
    Messaggi
    458
    puoi usare Swift3d che è un programmino che ti permette di creare oggetti 3d importabili in flash e ha gia dei movimenti e rotazioni predefiniti da dare all'oggetto

  4. #4
    Dipende da com'è l'oggetto, come dice negatyve.

    Se sei in mx puoi pensare all'utilizzo dei drawing methods.

    Ciao,
    .:| bandafox |:.

  5. #5
    pensavo a una doppia piramide (ovvero una sopra e una sotto)
    La teoria è quando si sa tutto ma non funziona niente.
    La pratica è quando funziona tutto ma nn si sa il perchè.
    In ogni caso si finisce sempre a coniugare la teoria con la pratica: Non funziona niente e non si sa il perchè.
    Albert Einstein
    Slackware 10.2 Fluxbox 9.0.12

  6. #6
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    ok. in flash 5 o mx?

  7. #7
    MX
    La teoria è quando si sa tutto ma non funziona niente.
    La pratica è quando funziona tutto ma nn si sa il perchè.
    In ogni caso si finisce sempre a coniugare la teoria con la pratica: Non funziona niente e non si sa il perchè.
    Albert Einstein
    Slackware 10.2 Fluxbox 9.0.12

  8. #8
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    Crea un filmato vuoto, e scrivi nel primo frame il seguente script. Quindi esporta.

    codice:
    LightSource = function (x, y, z, brightness) {
    	this.x = x;
    	this.y = y;
    	this.z = z;
    	this.brightness = brightness;
    	this.magnitude = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
    };
    
    this.createEmptyMovieClip("center", 0);
    
    center._x = Stage.width / 2;
    center._y = Stage.height / 2;
    inc = .5;
    focalLength = 400;
    rad = Math.PI/180;
    
    light = new LightSource(-20000, -20000, 20000, 100);
    
    pyr = {};
    
    pyr.vertexList = [];
    pyr.side = [];
    
    pyr.side.push({vertices:[0, 4, 3], sideColor:0x6600CC});
    pyr.side.push({vertices:[0, 3, 2], sideColor:0x6600CC});
    pyr.side.push({vertices:[0, 2, 1], sideColor:0x6600CC});
    pyr.side.push({vertices:[0, 1, 4], sideColor:0x6600CC});
    pyr.side.push({vertices:[5, 2, 3], sideColor:0x6600CC});
    pyr.side.push({vertices:[5, 3, 4], sideColor:0x6600CC});
    pyr.side.push({vertices:[5, 4, 1], sideColor:0x6600CC});
    pyr.side.push({vertices:[5, 1, 2], sideColor:0x6600CC});
    
    pyr.vertexList.push({x:0, y:100, z:0});
    pyr.vertexList.push({x:-50, y:0, z:50});
    pyr.vertexList.push({x:50, y:0, z:50});
    pyr.vertexList.push({x:50, y:0, z:-50});
    pyr.vertexList.push({x:-50, y:0, z:-50});
    pyr.vertexList.push({x:0, y:-100, z:0});
    
    vertices = [];
    
    backface = function (x, y) {
    	var cax = x[2] - x[0];
    	var cay = y[2] - y[0];
    	var bcx = x[1] - x[2];
    	var bcy = y[1] - y[2];
    	return (cax * bcy < cay * bcx);
    };
    
    render = function (model) {
    	center.clear();
    	center.lineStyle(2, 0, 100);
    	verts2D = [];
    	depthArray = [];
    	for (var i = 0; i < model.side.length; i++) {
    		var zDepth = 0;
    		for (var j = 0; j < model.side[i].vertices.length; j++) {
    			var whichVert = model.side[i].vertices[j];
    			if (verts2D[whichVert] == undefined) {
    				verts2D[whichVert] = {};
    				var scale = focalLength / (focalLength - model.vertexList[whichVert].z);
    				verts2D[whichVert].x = model.vertexList[whichVert].x * scale;
    				verts2D[whichVert].y = model.vertexList[whichVert].y * scale;
    			}
    			zDepth += model.vertexList[whichVert].z;
    		}
    		depthArray.push([model.side[i], zDepth]);
    	}
    	depthArray.sort(function (a, b) { return a[1] > b[1];});
    	for (var i = 0; i < depthArray.length; i++) {
    		var sideVerts = depthArray[i][0].vertices;
    		if (!backface([verts2D[sideVerts[0]].x, verts2D[sideVerts[1]].x, verts2D[sideVerts[2]].x], [verts2D[sideVerts[0]].y, verts2D[sideVerts[1]].y, verts2D[sideVerts[2]].y])) {
    			center.moveTo(verts2D[sideVerts[0]].x, verts2D[sideVerts[0]].y);
    			center.beginFill(getSideColor(model, depthArray[i][0]), 100);
    			for (var j = 1; j < sideVerts.length; j++) {
    				center.lineTo(verts2D[sideVerts[j]].x, verts2D[sideVerts[j]].y);
    			}
    			center.lineTo(verts2D[sideVerts[0]].x, verts2D[sideVerts[0]].y);
    			center.endFill();
    		}
    	}
    };
    
    getSideColor = function (model, side) {
    	var col = side.sideColor.toString(16);
    	while (col.length < 6) {
    		col = "0" + col;
    	}
    	var verts = [model.vertexList[side.vertices[0]], model.vertexList[side.vertices[1]], model.vertexList[side.vertices[2]]];
    	var lightFactor = factorLightAngle(verts);
    	var r = parseInt(col.substr(0, 2), 16) * lightFactor;
    	var g = parseInt(col.substr(2, 2), 16) * lightFactor;
    	var b = parseInt(col.substr(4, 2), 16) * lightFactor;
    	return r << 16 | g << 8 | b;
    };
    
    factorLightAngle = function (vertices) {
    	var U = [(vertices[0].x - vertices[1].x), (vertices[0].y - vertices[1].y), (vertices[0].z - vertices[1].z)];
    	var V = [(vertices[1].x - vertices[2].x), (vertices[1].y - vertices[2].y), (vertices[1].z - vertices[2].z)];
    	var p = [((U[1] * V[2]) - (U[2] * V[1])), -((U[0] * V[2]) - (U[2] * V[0])), ((U[0] * V[1]) - (U[1] * V[0]))];
    	var magP = Math.sqrt((p[0] * p[0]) + (p[1] * p[1]) + (p[2] * p[2]));
    	var dP = ((p[0] * light.x) + (p[1] * light.y) + (p[2] * light.z));
    	return ((Math.acos(dP / (magP * light.magnitude)) / Math.PI) * light.brightness / 100);
    };
    // ----------- ROTAZIONE ATTORNO AGLI ASSI ----------- //
    rotate = function (model, angX, angY, angZ) {
    	var sinX = Math.sin(angX * rad);var cosX = Math.cos(angX * rad);
    	var sinY = Math.sin(angY * rad);var cosY = Math.cos(angY * rad);
    	var sinZ = Math.sin(angZ * rad);var cosZ = Math.cos(angZ * rad);
    	for(var i = 0; i < model.vertexList.length; i++){
    		var vert = model.vertexList[i];
    		// rotazione attorno all'asse x
    		var rx1 = vert.x;
    		var ry1 = vert.y * cosX - vert.z * sinX;
    		var rz1 = vert.z * cosX + vert.y * sinX;
    		// rotazione attorno all'asse y
    		var rx2 = rx1 * cosY - rz1 * sinY;
    		var ry2 = ry1;
    		var rz2 = rz1 * cosY + rx1 * sinY;
    		// rotazione attorno all'asse z
    		var rx3 = rx2 * cosZ - ry2 * sinZ;
    		var ry3 = ry2 * cosZ + rx2 * sinZ;
    		var rz3 = rz2;
    		// aggiornamento dei punti
    		vert.x = rx3;vert.y = ry3;vert.z = rz3;
    	};
    }
    center.onEnterFrame = function() {
    	rotX += Key.isDown(Key.DOWN) * inc - Key.isDown(Key.UP) * inc;
    	rotY += Key.isDown(Key.LEFT) * inc - Key.isDown(Key.RIGHT) * inc;
    	rotate(pyr, rotX, rotY, rotZ);
    	render(pyr);
    };

  9. #9
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    1,610
    negative una domandina ma come fai a concepire queste cose
    è una domanda seria cmq

  10. #10
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    Beh, purtroppo non l'ho concepito io... :)
    So solo come funziona e come modificarlo..

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.