Gargoyle
08-26-2001, 10:02 PM
--original text--
this object is half the way to a complete engine.
still missing rotations and filled areas...
but update is coming soon.
--end original--
here is the new version, rotations implemented and two little bugfixes.
-----
LAST UPDATE 09-28-01
2% speed increase and 3 little bugfixes...
-----
function objectOrigin3D(){} //create an objectOrigin3d object
//initiate the object with x,y,z value of virtual matrix
//the virtual width,height and the xandyoffset which represent the screens center
objectOrigin3D.prototype.init = function(xp, yp, zp, wid, hei, xoff, yoff){
this.wi=parseFloat(wid);
this.he=parseFloat(hei);
this.mco=Math.cos;
this.msi=Math.sin;
this.xo=xoff;
this.yo=yoff;
this.vi=parseFloat(this.xo/2.5);
this.d=yoff+20;
this.pX = parseFloat(xp);
this.pY = parseFloat(yp);
this.pZ = parseFloat(zp);
this.vX = parseFloat(0.0);
this.vY = parseFloat(0.0);
this.vZ = parseFloat(0.0);
this.ia = 0;
this.ua=false;
this.dd=(Math.PI/180)
}
//calculates the real values at the screen form the given virtuals and places the assigned movieclip there
objectOrigin3D.prototype.toScreen = function (Hx, Hy, Hz){
if (this.mymc == ""){
return false;
} else {
this.pX = parseFloat(Hx);
this.pY = parseFloat(Hy);
this.pZ = parseFloat(Hz);
this.sX = (((this.vi * this.pX) / (this.d + this.pZ)) + this.xo);
this.sY = (((-(this.vi) * this.pY) / (this.d + this.pZ)) + this.yo);
this.sh = (this.vi * this.wi) / (this.d + this.pZ);
this.st = (this.vi * this.he) / (this.d + this.pZ);
this.sa = (this.vi * this.ia) / (this.yo + 1 + this.pZ);
this.mc._x = this.sX;
this.mc._y = this.sY;
this.mc._width = this.sh;
this.mc._height = this.st;
if(this.ua){
this.mc._alpha = this.sa;
}
return true;
}
}
//calculates the real values at the screen form the given virtuals
objectOrigin3D.prototype.toValues = function (Hx, Hy, Hz){
this.pX = parseFloat(Hx);
this.pY = parseFloat(Hy);
this.pZ = parseFloat(Hz);
this.sX = (((this.vi * this.pX) / (this.d + this.pZ)) + this.xo);
this.sY = (((-(this.vi) * this.pY) / (this.d + this.pZ)) + this.yo);
this.sh = (this.vi * this.wi) / (this.d + this.pZ);
this.st = (this.vi * this.he) / (this.d + this.pZ);
this.sa = (this.vi * this.ia) / (this.yo + 1 + this.pZ);
}
//calculates the real values at the screen from the own virtuals
objectOrigin3D.prototype.updateValues = function (){
this.sX = (((this.vi * this.pX) / (this.d + this.pZ)) + this.xo);
this.sY = (((-(this.vi) * this.pY) / (this.d + this.pZ)) + this.yo);
this.sh = (this.vi * this.wi) / (this.d + this.pZ);
this.st = (this.vi * this.he) / (this.d + this.pZ);
this.sa = (this.vi * this.ia) / (this.yo + 1 + this.pZ);
}
//calculates the real values at the screen form the own virtuals and places the assigned movieclip there
objectOrigin3D.prototype.updateScreen = function (){
if (this.mc == ""){
return false;
} else {
this.sX = (((this.vi * this.pX) / (this.d + this.pZ)) + this.xo);
this.sY = (((-(this.vi) * this.pY) / (this.d + this.pZ)) + this.yo);
this.sh = (this.vi * this.wi) / (this.d + this.pZ);
this.st = (this.vi * this.he) / (this.d + this.pZ);
this.sa = (this.vi * this.ia) / (this.yo + 1 + this.pZ);
this.mc._x = this.sX;
this.mc._y = this.sY;
this.mc._width = this.sh;
this.mc._height = this.st;
if(this.ua){
this.mc._alpha = this.sa;
}
return true;
}
}
//introduces a movieclip to the object, to b placed according to the objects calculations (a victim in such sense :) )
objectOrigin3D.prototype.assignMC = function (mc){
this.mc = eval(mc);
}
//either use the objects alpha calculations of define yar own ones
objectOrigin3D.prototype.enableAlpha = function (){
if (this.mc == ""){
return false;
} else {
this.ia=this.mc._alpha;
this.ua = true;
return true;
}
}
//set an new alpha for the assinged movieclip
objectOrigin3D.prototype.setAlpha = function (s){
if (s == "" || isNaN(s) || s > 100){
return false;
} else {
this.ia = s;
this.ua = true;
return true;
}
}
//move in virtual space
objectOrigin3D.prototype.move = function (){
this.pX += this.vX;
this.pY += this.vY;
this.pZ += this.vZ;
}
//replace the origin of yar object in virtual space
objectOrigin3D.prototype.placeAt = function(Hx, Hy, Hz){
this.pX = parseFloat(Hx);
this.pY = parseFloat(Hy);
this.pZ = parseFloat(Hz);
}
//sets the movments speed and direction to the given values
objectOrigin3D.prototype.setVector = function (Hx, Hy, Hz){
this.vX = parseFloat(Hx);
this.vY = parseFloat(Hy);
this.vZ = parseFloat(Hz);
}
//accelerate the objects speed > 1 get faster <1 get slower
objectOrigin3D.prototype.accelerate = function (s){
this.vX = this.vX * parseFloat(s);
this.vY = this.vY * parseFloat(s);
this.vZ = this.vZ * parseFloat(s);
}
//set the speed value
objectOrigin3D.prototype.setSpeed = function (s){
if(this.vX != 0 || this.vY != 0 || this.vZ !=0){
var len= Math.sqrt((this.vX+this.vX)+(this.vY*this.vY)+(thi s.vZ*this.vZ));
var fak=parseFloat(s)/len;
this.vX = this.vX * fak;
this.vY = this.vY * fak;
this.vZ = this.vZ * fak;
}
}
//want to know how fast yar object is?
objectOrigin3D.prototype.Speed = function (){
len= Math.sqrt((this.vX+this.vX)+(this.vY*this.vY)+(thi s.vZ*this.vZ));
return len;
}
//with these commands u ask the object for values or set them.
//the coordinates width/height and alpha on the real screen
objectOrigin3D.prototype.ScreenX = function (){
return this.sX;
}
objectOrigin3D.prototype.ScreenY = function (){
return this.sY;
}
objectOrigin3D.prototype.ScreenWidth = function (){
return this.sh;
}
objectOrigin3D.prototype.ScreenHeight = function (){
return this.st;
}
objectOrigin3D.prototype.ScreenAlpha = function (){
return this.sa;
}
//positions r the positions in the virtual space
objectOrigin3D.prototype.PosZ = function (){
return this.pZ;
}
objectOrigin3D.prototype.setPosZ = function (s){
this.pZ = parseFloat(s);
}
objectOrigin3D.prototype.PosY = function (){
return this.pY;
}
objectOrigin3D.prototype.setPosY = function (s){
this.pY = parseFloat(s);
}
objectOrigin3D.prototype.PosX = function (){
return this.pX;
}
objectOrigin3D.prototype.setPosX = function (s){
this.pX = parseFloat(s);
}
//the Vec's describe the movement speed and direction of yar object in virtual space
objectOrigin3D.prototype.VecZ = function (){
return this.vZ;
}
objectOrigin3D.prototype.setVecZ = function (s){
this.vZ = parseFloat(s);
}
objectOrigin3D.prototype.VecX = function (){
return this.vX;
}
objectOrigin3D.prototype.setVecX = function (s){
this.vX = parseFloat(s);
}
objectOrigin3D.prototype.VecY = function (){
return this.vY;
}
objectOrigin3D.prototype.setVecY = function (s){
this.vY = parseFloat(s);
}
//inverses the direction of the movment according to the selected axis
objectOrigin3D.prototype.bounceX = function (){
this.vX = -(this.vX);
}
objectOrigin3D.prototype.bounceY = function (){
this.vY = -(this.vY);
}
objectOrigin3D.prototype.bounceZ = function (){
this.vZ = -(this.vZ);
}
//yar object already has speed and direction the direction and speed may b influenced here by adding values to the vector
objectOrigin3D.prototype.addToVec = function (Hx, Hy, Hz){
this.vX += parseFloat(Hx);
this.vY += parseFloat(Hy);
this.vZ += parseFloat(Hz);
}
//rotation around an axis. remember the objects r going to rotate around the origin.
//so if u want something to rotate around another point, first create an new origin for it also using this class.
objectOrigin3d.prototype.rotateX = function (s){
this.pY = ((this.pY * mco(this.dd * s)) - (this.pZ * msi(this.dd * s)));
this.pZ = ((this.pY * msi(this.dd * s)) - (this.pZ * mco(this.dd * s)));
this.vY = ((this.vY * mco(this.dd * s)) - (this.vZ * msi(this.dd * s)));
this.vZ = ((this.vY * msi(this.dd * s)) - (this.vZ * mco(this.dd * s)));
}
objectOrigin3d.prototype.rotateY = function (s){
this.pZ = ((this.pZ * mco(this.dd * s)) - (this.pX * msi(this.dd * s)));
this.pX = ((this.pZ * msi(this.dd * s)) - (this.pX * mco(this.dd * s)));
this.vZ = ((this.vZ * mco(this.dd * s)) - (this.vX * msi(this.dd * s)));
this.vX = ((this.vZ * msi(this.dd * s)) - (this.vX * mco(this.dd * s)));
}
objectOrigin3d.prototype.rotateZ = function (s){
this.pX = ((this.pX * mco(this.dd * s)) - (this.pY * msi(this.dd * s)));
this.pY = ((this.pX * msi(this.dd * s)) - (this.pY * mco(this.dd * s)));
this.vX = ((this.vX * mco(this.dd * s)) - (this.vY * msi(this.dd * s)));
this.vY = ((this.vX * msi(this.dd * s)) - (this.vY * mco(this.dd * s)));
}
and here is a little example what u r able to do with it
this object is half the way to a complete engine.
still missing rotations and filled areas...
but update is coming soon.
--end original--
here is the new version, rotations implemented and two little bugfixes.
-----
LAST UPDATE 09-28-01
2% speed increase and 3 little bugfixes...
-----
function objectOrigin3D(){} //create an objectOrigin3d object
//initiate the object with x,y,z value of virtual matrix
//the virtual width,height and the xandyoffset which represent the screens center
objectOrigin3D.prototype.init = function(xp, yp, zp, wid, hei, xoff, yoff){
this.wi=parseFloat(wid);
this.he=parseFloat(hei);
this.mco=Math.cos;
this.msi=Math.sin;
this.xo=xoff;
this.yo=yoff;
this.vi=parseFloat(this.xo/2.5);
this.d=yoff+20;
this.pX = parseFloat(xp);
this.pY = parseFloat(yp);
this.pZ = parseFloat(zp);
this.vX = parseFloat(0.0);
this.vY = parseFloat(0.0);
this.vZ = parseFloat(0.0);
this.ia = 0;
this.ua=false;
this.dd=(Math.PI/180)
}
//calculates the real values at the screen form the given virtuals and places the assigned movieclip there
objectOrigin3D.prototype.toScreen = function (Hx, Hy, Hz){
if (this.mymc == ""){
return false;
} else {
this.pX = parseFloat(Hx);
this.pY = parseFloat(Hy);
this.pZ = parseFloat(Hz);
this.sX = (((this.vi * this.pX) / (this.d + this.pZ)) + this.xo);
this.sY = (((-(this.vi) * this.pY) / (this.d + this.pZ)) + this.yo);
this.sh = (this.vi * this.wi) / (this.d + this.pZ);
this.st = (this.vi * this.he) / (this.d + this.pZ);
this.sa = (this.vi * this.ia) / (this.yo + 1 + this.pZ);
this.mc._x = this.sX;
this.mc._y = this.sY;
this.mc._width = this.sh;
this.mc._height = this.st;
if(this.ua){
this.mc._alpha = this.sa;
}
return true;
}
}
//calculates the real values at the screen form the given virtuals
objectOrigin3D.prototype.toValues = function (Hx, Hy, Hz){
this.pX = parseFloat(Hx);
this.pY = parseFloat(Hy);
this.pZ = parseFloat(Hz);
this.sX = (((this.vi * this.pX) / (this.d + this.pZ)) + this.xo);
this.sY = (((-(this.vi) * this.pY) / (this.d + this.pZ)) + this.yo);
this.sh = (this.vi * this.wi) / (this.d + this.pZ);
this.st = (this.vi * this.he) / (this.d + this.pZ);
this.sa = (this.vi * this.ia) / (this.yo + 1 + this.pZ);
}
//calculates the real values at the screen from the own virtuals
objectOrigin3D.prototype.updateValues = function (){
this.sX = (((this.vi * this.pX) / (this.d + this.pZ)) + this.xo);
this.sY = (((-(this.vi) * this.pY) / (this.d + this.pZ)) + this.yo);
this.sh = (this.vi * this.wi) / (this.d + this.pZ);
this.st = (this.vi * this.he) / (this.d + this.pZ);
this.sa = (this.vi * this.ia) / (this.yo + 1 + this.pZ);
}
//calculates the real values at the screen form the own virtuals and places the assigned movieclip there
objectOrigin3D.prototype.updateScreen = function (){
if (this.mc == ""){
return false;
} else {
this.sX = (((this.vi * this.pX) / (this.d + this.pZ)) + this.xo);
this.sY = (((-(this.vi) * this.pY) / (this.d + this.pZ)) + this.yo);
this.sh = (this.vi * this.wi) / (this.d + this.pZ);
this.st = (this.vi * this.he) / (this.d + this.pZ);
this.sa = (this.vi * this.ia) / (this.yo + 1 + this.pZ);
this.mc._x = this.sX;
this.mc._y = this.sY;
this.mc._width = this.sh;
this.mc._height = this.st;
if(this.ua){
this.mc._alpha = this.sa;
}
return true;
}
}
//introduces a movieclip to the object, to b placed according to the objects calculations (a victim in such sense :) )
objectOrigin3D.prototype.assignMC = function (mc){
this.mc = eval(mc);
}
//either use the objects alpha calculations of define yar own ones
objectOrigin3D.prototype.enableAlpha = function (){
if (this.mc == ""){
return false;
} else {
this.ia=this.mc._alpha;
this.ua = true;
return true;
}
}
//set an new alpha for the assinged movieclip
objectOrigin3D.prototype.setAlpha = function (s){
if (s == "" || isNaN(s) || s > 100){
return false;
} else {
this.ia = s;
this.ua = true;
return true;
}
}
//move in virtual space
objectOrigin3D.prototype.move = function (){
this.pX += this.vX;
this.pY += this.vY;
this.pZ += this.vZ;
}
//replace the origin of yar object in virtual space
objectOrigin3D.prototype.placeAt = function(Hx, Hy, Hz){
this.pX = parseFloat(Hx);
this.pY = parseFloat(Hy);
this.pZ = parseFloat(Hz);
}
//sets the movments speed and direction to the given values
objectOrigin3D.prototype.setVector = function (Hx, Hy, Hz){
this.vX = parseFloat(Hx);
this.vY = parseFloat(Hy);
this.vZ = parseFloat(Hz);
}
//accelerate the objects speed > 1 get faster <1 get slower
objectOrigin3D.prototype.accelerate = function (s){
this.vX = this.vX * parseFloat(s);
this.vY = this.vY * parseFloat(s);
this.vZ = this.vZ * parseFloat(s);
}
//set the speed value
objectOrigin3D.prototype.setSpeed = function (s){
if(this.vX != 0 || this.vY != 0 || this.vZ !=0){
var len= Math.sqrt((this.vX+this.vX)+(this.vY*this.vY)+(thi s.vZ*this.vZ));
var fak=parseFloat(s)/len;
this.vX = this.vX * fak;
this.vY = this.vY * fak;
this.vZ = this.vZ * fak;
}
}
//want to know how fast yar object is?
objectOrigin3D.prototype.Speed = function (){
len= Math.sqrt((this.vX+this.vX)+(this.vY*this.vY)+(thi s.vZ*this.vZ));
return len;
}
//with these commands u ask the object for values or set them.
//the coordinates width/height and alpha on the real screen
objectOrigin3D.prototype.ScreenX = function (){
return this.sX;
}
objectOrigin3D.prototype.ScreenY = function (){
return this.sY;
}
objectOrigin3D.prototype.ScreenWidth = function (){
return this.sh;
}
objectOrigin3D.prototype.ScreenHeight = function (){
return this.st;
}
objectOrigin3D.prototype.ScreenAlpha = function (){
return this.sa;
}
//positions r the positions in the virtual space
objectOrigin3D.prototype.PosZ = function (){
return this.pZ;
}
objectOrigin3D.prototype.setPosZ = function (s){
this.pZ = parseFloat(s);
}
objectOrigin3D.prototype.PosY = function (){
return this.pY;
}
objectOrigin3D.prototype.setPosY = function (s){
this.pY = parseFloat(s);
}
objectOrigin3D.prototype.PosX = function (){
return this.pX;
}
objectOrigin3D.prototype.setPosX = function (s){
this.pX = parseFloat(s);
}
//the Vec's describe the movement speed and direction of yar object in virtual space
objectOrigin3D.prototype.VecZ = function (){
return this.vZ;
}
objectOrigin3D.prototype.setVecZ = function (s){
this.vZ = parseFloat(s);
}
objectOrigin3D.prototype.VecX = function (){
return this.vX;
}
objectOrigin3D.prototype.setVecX = function (s){
this.vX = parseFloat(s);
}
objectOrigin3D.prototype.VecY = function (){
return this.vY;
}
objectOrigin3D.prototype.setVecY = function (s){
this.vY = parseFloat(s);
}
//inverses the direction of the movment according to the selected axis
objectOrigin3D.prototype.bounceX = function (){
this.vX = -(this.vX);
}
objectOrigin3D.prototype.bounceY = function (){
this.vY = -(this.vY);
}
objectOrigin3D.prototype.bounceZ = function (){
this.vZ = -(this.vZ);
}
//yar object already has speed and direction the direction and speed may b influenced here by adding values to the vector
objectOrigin3D.prototype.addToVec = function (Hx, Hy, Hz){
this.vX += parseFloat(Hx);
this.vY += parseFloat(Hy);
this.vZ += parseFloat(Hz);
}
//rotation around an axis. remember the objects r going to rotate around the origin.
//so if u want something to rotate around another point, first create an new origin for it also using this class.
objectOrigin3d.prototype.rotateX = function (s){
this.pY = ((this.pY * mco(this.dd * s)) - (this.pZ * msi(this.dd * s)));
this.pZ = ((this.pY * msi(this.dd * s)) - (this.pZ * mco(this.dd * s)));
this.vY = ((this.vY * mco(this.dd * s)) - (this.vZ * msi(this.dd * s)));
this.vZ = ((this.vY * msi(this.dd * s)) - (this.vZ * mco(this.dd * s)));
}
objectOrigin3d.prototype.rotateY = function (s){
this.pZ = ((this.pZ * mco(this.dd * s)) - (this.pX * msi(this.dd * s)));
this.pX = ((this.pZ * msi(this.dd * s)) - (this.pX * mco(this.dd * s)));
this.vZ = ((this.vZ * mco(this.dd * s)) - (this.vX * msi(this.dd * s)));
this.vX = ((this.vZ * msi(this.dd * s)) - (this.vX * mco(this.dd * s)));
}
objectOrigin3d.prototype.rotateZ = function (s){
this.pX = ((this.pX * mco(this.dd * s)) - (this.pY * msi(this.dd * s)));
this.pY = ((this.pX * msi(this.dd * s)) - (this.pY * mco(this.dd * s)));
this.vX = ((this.vX * mco(this.dd * s)) - (this.vY * msi(this.dd * s)));
this.vY = ((this.vX * msi(this.dd * s)) - (this.vY * mco(this.dd * s)));
}
and here is a little example what u r able to do with it