dcsimg
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Making a custom 3d rendering engine. Having a few problems with world positioning

Threaded View

  1. #1
    Senior Member
    Join Date
    Sep 2008
    Posts
    100

    Question Making a custom 3d rendering engine. Having a few problems with world positioning

    Ok, first of all I'm making this engine while keeping in mind two tutorials along with an extra link. This one is pretty much exactly how I handle the world positioning in relation to a camera. http://www.kirupa.com/developer/acti...ch_balloon.htm

    And this one is how I handle the three dimensional object rendering http://www.flashandmath.com/advanced...cube_code.html
    The only changes made in the rendering process were pretty minor. First change being that the rotational function used in the code is completely different, yea the one where the new vertices are calculated. And the second is that I switched things up in the 3d to 2d conversion a bit and I made it so the z axis is the center of attention.

    in the tut it was x = fLen/fLen-Vertex.x*Vertex.y, y = -fLen/fLen-Vertex.x*Vertex.z

    mine is x = fLen/(fLen-Vertex.z)*Vertex.x, y = -fLen/(fLen-Vertex.z)*Vertex.y

    And as a just so you know, I did put the ( & ) in on purpose, it didn't work right otherwise...

    And the third link, the one that isn't a tut, just a wiki is something I found on quarternions, unfortunately I didn't understand quite a lot of it. But they had some Puesedo code for the rotational functionality of it, and it was quite easy to turn into something usable in flash. Keeping in mind that the code found on the page is contained in one class and my actual quarternions in another. The quarternion class only has 4 public variables that get set by the constructor. But anyway, here is the link for the quarternion code that I barely understand.

    http://en.wikipedia.org/wiki/Quatern...atial_rotation

    As a lil note on something else I want help in, the quarternion rotation is a lil odd, it makes the object size change as well as the rotation so thats something I wanna fix.

    Much thanks to any help that might come, though I'm not expecting too much, I get into some rather complicated code that many won't have much clue on, no offense.

    EDIT: Cause I know code helps with the understanding.

    code for updating current global perspective.

    I'll also have note that the only real problem is that the objects rotational origin in the actual world doesn't stay where the camera is. Basically the farther away, the more the camera rotation is off.

    Code:
    public function updatePerspective(camera:Camera3D) {
    			var x=Origin.x-camera.Origin.x;
    			var y=Origin.y-camera.Origin.y;
    			var z=Origin.z-camera.Origin.z;
    			var tx,ty,tz;
    			// rotation around y axis
    			var angle=camera.Rotation.y;
    			RenderedRotation.y=Rotation.y+angle;
    			tx=Math.cos(angle)*x-Math.sin(angle)*z;
    			tz=Math.sin(angle)*x+Math.cos(angle)*z;
    			x=tx;
    			z=tz;
    			angle=camera.Rotation.x;
    			RenderedRotation.x=Rotation.x+angle;
    			ty=Math.cos(angle)*y-Math.sin(angle)*z;
    			tz=Math.sin(angle)*y+Math.cos(angle)*z;
    			y=ty;
    			z=tz;
    			angle=camera.Rotation.z;
    			RenderedRotation.z=angle+Rotation.z;
    			tx=Math.cos(angle)*x-Math.sin(angle)*y;
    			ty=Math.sin(angle)*x+Math.cos(angle)*y;
    			x=tx;
    			y=ty;
    			if (z>0) {
    				var scaleRatio = Lens/(Lens + z);
    				RenderedOrigin.x=x*scaleRatio;
    				RenderedScale.x=Scale.x*scaleRatio;
    				RenderedOrigin.y=y*scaleRatio;
    				RenderedScale.y=Scale.y*scaleRatio;
    				RenderedOrigin.z=z*scaleRatio;
    				RenderedScale.z=Scale.z*scaleRatio;
    				render();
    			}
    		}
    code for updating vertices

    Code:
    private function pointNewVerts(vert:Vertex):Vertex {
    			var newVert:Vertex=quartMath.quat_rot(vert,RenderedRotation,0);
    			newVert.x = (newVert.x*RenderedScale.x)+RenderedOrigin.x;
    			newVert.y = (newVert.y*RenderedScale.y)+RenderedOrigin.y;
    			newVert.z = (newVert.z*RenderedScale.z)+RenderedOrigin.z;
    			return newVert;
    		}
    EDIT::

    Because it would be nice to show people what I'm talking about Imma give you a link to a slightly less updated use of my engine thus far.

    http://www.escapetruth.com/michael/object3DTester2.swf

    Be aware that there is no occlusion culling, depth sorting, and there isn't any proper rotational updates happening.

    You will also notice that it is extremely laggy. Its not from the lack of occlusion culling, though that does make it slightly worse. But its also because even though there might not be any form or rendering or drawing being done to quite a lot of them, which helps a lot, the problem still remains that there is like 11120 instances in the scene at once. My best guess is to actually make a real-time database that contains the actual 3d object information. Such as its location, rotation, vertex data, and polygon data. And that information is only supplied to the scene when needed, rather than having all 11120 instances in the scene to be processed on every update. Its like the difference of having all that information placed in the client to be processed all the time, or having it some place else and it only counts when it needs to count.

    When the object exits certain bounds it saves the current information to the database, from then on all camera updates need be sent once, per frame of camera update, and handled in the database, all updates to the objects themselves get sent by a lil something else I'll have set up, once again not being handled in scene, but in the database.The only part of the process that will be handled in scene will be the sending and an even smaller amount of receiving.

    When the object enters the bounds it just adds it back to the scene with the current information the database has. Using this method the only time the object has to be reloaded or cleared is when it enters and exits certain bounds, which I'll probably define distance wise, zone wise, etc...
    Last edited by cody112; 07-12-2010 at 10:12 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center