# Three Dimensional Problem

**URL:** <https://forum.kirupa.com/t/three-dimensional-problem/147698>\
**Category:** Uncategorized\
**Created:** [May 12, 2005, 10:11pm UTC](https://forum.kirupa.com/t/three-dimensional-problem/147698 "2005-05-12T22:11:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dangerskew](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@dangerskew](https://forum.kirupa.com/u/dangerskew)\
**Post date:** [May 12, 2005, 10:11pm UTC](https://forum.kirupa.com/t/three-dimensional-problem/147698/1 "2005-05-12T22:11:58Z")

</div>

I’ve made many 3D things ([Newest One](http://www.sheezyart.com/view/416895)) based on Sen’s tutorials, and I’ve always run into the same problem. Whenever an object gets too close to the camera, it gets all messed up. Here’s the codes I use for 3D:

```php

/*This function converts a 3 dimensional point into a 2 dimensional point on the stage
*/
function TwoToThree(Point){
 var cx = camera.x + (Math.sin(camera.rotation) * 150);
 var cy = camera.y;
 var cz = camera.z + (Math.cos(camera.rotation) * 150);
 var x = Point.x - cx;
 var y = Point.y - cy;
 var z = Point.z - cz;
 var tx, ty, tz;
 var angle = camera.rotation;
 tx = Math.cos(angle)*x - Math.sin(angle)*z;
 tz = Math.sin(angle)*x + Math.cos(angle)*z;
 x = tx;
 z = tz;
 var scaleRatio = FL/(FL + z);
 x = x * scaleRatio;
 y = y * scaleRatio;
 Point2 = new Object();
 Point2.x = x;
 Point2.y = y;
 Point2.z = z;
 Point2.tr = FL + z;
 return Point2;
}
/*This is the function that the walls in the racing game run threw for updating
*/
function WallOnEnter(){
 if(_root._currentframe != GameFrame){
  Destroy(this);
 }
 var p = new Array();
 for(i=0;i<this.points.length;i++){
  p* = TwoToThree(this.points*);
 }
 var a = 0;
 for(i=0;i<this.points.length;i++){
  if(p*.tr < 300){
   a ++;
   break;
  }
 }
 this.clear();
 if(a == 0){
  this.beginFill(this.col, 100);
  this.lineStyle(0, 0xDE0101, 25);
  this.moveTo(p[0].x, p[0].y);
  for(i=1;i<p.length;i++){
   this.lineTo(p*.x, p*.y);
  }
  this.lineTo(p[0].x, p[0].y);
  this.endFill();
 }
 var tz = 0;
 i=0;
 while(i<this.points.length){
  tz += p*.z;
  i++;
 }
 tz = tz/i;
 this.swapDepths(-tz);
}

```

The focal length (FL) is 300.  
I image that I’d have to change something in one of these two, which is why I picked them. If anyone has ideas, I’ll be glad to try them.
