Visualizzazione dei risultati da 1 a 10 su 10

Discussione: Tutorial - 3d rotation

  1. #1

    Tutorial - 3d rotation

    Ciao ragazzi,
    ho trovato sul sito www.bit-101.com come fare la rotazione in 3d con flash.
    Ho messo tre oggetti sullo stage, tutto funziona bene.
    Il problema sta che ruotano sempre, era possibile fare in modo che quando vado sopra all'oggetto esso si fermi?
    Questo è il codice.
    onClipEvent (load) {
    y = 100;
    speed = 2;
    radius = 100;
    xcenter = 80;
    ycenter = 80;
    zcenter = 100;
    angle = 360;
    fl = 150;
    }
    onClipEvent (enterFrame) {
    z = Math.sin(angle*Math.PI/180)*radius+zcenter;
    scale = fl/(fl+z);
    x = Math.cos(angle*Math.PI/180)*radius;
    _x = x*scale+xcenter;
    _y = y*scale+ycenter;
    _xscale = _yscale=scale*100;
    angle += speed;
    if (angle>359) {
    angle -= 360;
    }
    }


  2. #2
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    codice:
    onClipEvent (load) {
    	y = 100;
    	speed = 2;
    	radius = 100;
    	xcenter = 80;
    	ycenter = 80;
    	zcenter = 100;
    	angle = 360;
    	fl = 150;
    }
    onClipEvent (enterFrame) {
    	if(!sopra){
    		z = Math.sin(angle * Math.PI / 180) * radius + zcenter;
    		scale = fl / (fl + z);
    		x = Math.cos(angle * Math.PI / 180) * radius;
    		_x = x * scale + xcenter;
    		_y = y * scale + ycenter;
    		_xscale = _yscale = scale * 100;
    		angle += speed;
    		if (angle > 359) {
    			angle -= 360;
    		}
    	}
    }
    onClipEvent(mouseMove){
    	if(this.hitTest(_root._xmouse, _root._ymouse, true)){
    		if(!this.sopra)this.sopra = true;
    	} else {
    		if(this.sopra)this.sopra = false;
    	}
    }

  3. #3
    Grazie Nega sei sempre disponibile.
    E' possibile creare una funzione, ho tre oggetti sullo stage ai quali cambio il valore della variabile angle?
    Cosa calcola la variabile fl?


  4. #4
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    >E' possibile creare una funzione, ho tre oggetti sullo stage ai
    >quali cambio il valore della variabile angle?

    Nel primo frame della timeline principale scrivi:


    codice:
    MovieClip.prototype.init3D = function(angle)
    {	
    	this.y = 100;
    	this.speed = 2;
    	this.radius = 100;
    	this.xcenter = 80;
    	this.ycenter = 80;
    	this.zcenter = 100;
    	this.fl = 150;
    	this.angle = angle;
    };
    MovieClip.prototype.rotate = function()
    {
    	if(!this.sopra){
    		this.z = Math.sin(this.angle * Math.PI / 180) * this.radius + this.zcenter;
    		this.scale = this.fl / (this.fl + this.z);
    		this.x = Math.cos(this.angle * Math.PI / 180) * this.radius;
    		this._x = this.x * this.scale + this.xcenter;
    		this._y = this.y * this.scale + this.ycenter;
    		this._xscale = this._yscale = this.scale * 100;
    		this.angle += this.speed;
    		if (this.angle > 359) {
    			this.angle -= 360;
    		}
    	}
    };
    MovieClip.prototype.hitControl = function()
    {
    	if(this.hitTest(_root._xmouse, _root._ymouse, true)){
    		if(!this.sopra)this.sopra = true;
    	} else {
    		if(this.sopra)this.sopra = false;
    	}	
    };
    Poi, ai movieclip associ il seguente script, cambiando solo la parte in grassetto:

    codice:
    onClipEvent (load) {
    	this.init3D(360);
    }
    onClipEvent (enterFrame) {
    	this.rotate();
    }
    onClipEvent(mouseMove){
    	this.hitControl();
    }
    >Cosa calcola la variabile fl?

    fl = focal length

    la distanza dell'osservatore dallo schermo

  5. #5
    Funziona tutto alla grande, una piccola precisazione qual è la differenza tra costruire una funzione:
    functio reset(theClip)
    invece quella che hai fatto tu?


  6. #6
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    La funzione che dici tu è una funzione "procedurale", cioè una funzione che serve ad eseguire sistematicamente una serie di istruzioni, da qualunque oggetto venga richiamata.
    Così come le ho scritte io, invece, diventano veri e propri metodi della classe movieclip, come il gotoAndPlay, e in questo modo, tramite l'oggetto prototype, ereditati da tutti i movieclip presenti nel filmato, che li usano come se fossero definiti al loro interno:

    codice:
    onClipEvent (enterFrame) {
    	this.rotate();
    }

  7. #7
    E' uscito un problema nel momento in cui vado sopra all'oggetto esso si ferma, nel momento in cui l'oggetto ricomincia a ruotare non ha più le stesse coordinate dell'inizio, perciò si accavalla con l'altro.
    Qual è la soluzione migliore?

  8. #8
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    Fermarli tutti:

    codice:
    select = null;
    flag = false;
    MovieClip.prototype.path = this;
    MovieClip.prototype.init3D = function(angle)
    {
    	this.sopra = false;
    	this.y = 100;
    	this.speed = 2;
    	this.radius = 100;
    	this.xcenter = 80;
    	this.ycenter = 80;
    	this.zcenter = 100;
    	this.fl = 150;
    	this.angle = angle;
    };
    MovieClip.prototype.rotate = function()
    {
    	if(!this.path.flag){
    		this.z = Math.sin(this.angle * Math.PI / 180) * this.radius + this.zcenter;
    		this.scale = this.fl / (this.fl + this.z);
    		this.x = Math.cos(this.angle * Math.PI / 180) * this.radius;
    		this._x = this.x * this.scale + this.xcenter;
    		this._y = this.y * this.scale + this.ycenter;
    		this._xscale = this._yscale = this.scale * 100;
    		this.angle += this.speed;
    		if (this.angle > 359)this.angle -= 360;
    	}
    };
    MovieClip.prototype.hitControl = function()
    {
    	if(this.hitTest(_root._xmouse, _root._ymouse, true)){
    		this.path.select = this;
    		this.path.flag = true;
    	} else {
    		if(this.path.select == this){
    			this.path.select = null;
    			this.path.flag = false;
    		}
    	}
    };

  9. #9
    Funziona benissimo
    ciaoooooooooooooooooo.

  10. #10

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.