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

  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.

  2. #2
    Senior Member
    Join Date
    Sep 2008
    Posts
    100
    If my post is lacking the information that is needed by other users, in other words, if I need to put in more of the code I'm using to help you peeps understand enough to help me. PLEASE LET ME KNOW.

    Edit: Man oh man, I hope I'm not the only person here who understands this stuff. I mean, how else could of people made stuff like papervision and away3d. I'm just wanna see if someone might know how to fix my world positioning code, maybe a fix for that size changing part in the quarternion rotation. Also, I wanna let you know, that the only way the quarternion rotation will actually do anything is to change the number in the function that is used to perform the rotation to be higher than 0, even 0.1 is good.
    Last edited by cody112; 06-25-2010 at 09:25 AM.

  3. #3
    Senior Member
    Join Date
    Sep 2008
    Posts
    100
    Little update, I kinda fixed the world positioning problem, but it still isn't quite right, so any help on that would be nice. The problem with the quarternion part is still the same, but I haven't really worked on that. So is anyone gonna say anything, or would I be better off having this deleted.

  4. #4
    Junior Member
    Join Date
    Dec 2009
    Posts
    15
    For the world positioning issue, I'm not sure exactly what the problem is other than that there is some problem and it deals with "world positioning", whatever that means. Luckily, you seem to be on your way to solving it.

    I didn't read the links posted, but I will say that the rendering pipeline is done using Linear Algebra techniques, not direct application of trignometry the way you have done. I would suggest switching to the traditional methods as they're more common (and easier to find help on), much easier to understand and manage, and they are less prone to programmer error (typos, etc).

    As for the quaternion issue, it's important to realize that rotation matrices and quaternions are interchangable in most cases. If you cannot understand quaternions, then using the matrices instead is probably fine. Of course, most people don't understand quaternions and use them just fine as well. At any rate, if your objects are changing size because of a quaternion-related piece of code, it is usually because you're not renormalizing your quaternions. Without renormalization, error will accumulate and cause incorrect rotations and transformations. The same is true, as you may have guessed, with rotation matrices (but the normalization costs are different).

    Last, the flash crew isn't typically familiar with this stuff, but neither is the typical non-flash programmer. If you're looking for people who are, you need to look in the right places--game, rendering, physics, and math sites, for example.

  5. #5
    Senior Member
    Join Date
    Sep 2008
    Posts
    100
    Quote Originally Posted by Freshmaker View Post
    For the world positioning issue, I'm not sure exactly what the problem is other than that there is some problem and it deals with "world positioning", whatever that means. Luckily, you seem to be on your way to solving it.

    I didn't read the links posted, but I will say that the rendering pipeline is done using Linear Algebra techniques, not direct application of trignometry the way you have done. I would suggest switching to the traditional methods as they're more common (and easier to find help on), much easier to understand and manage, and they are less prone to programmer error (typos, etc).

    As for the quaternion issue, it's important to realize that rotation matrices and quaternions are interchangable in most cases. If you cannot understand quaternions, then using the matrices instead is probably fine. Of course, most people don't understand quaternions and use them just fine as well. At any rate, if your objects are changing size because of a quaternion-related piece of code, it is usually because you're not renormalizing your quaternions. Without renormalization, error will accumulate and cause incorrect rotations and transformations. The same is true, as you may have guessed, with rotation matrices (but the normalization costs are different).


    Last, the flash crew isn't typically familiar with this stuff, but neither is the typical non-flash programmer. If you're looking for people who are, you need to look in the right places--game, rendering, physics, and math sites, for example.
    When I said "world positioning" I was meaning, well basically. There is the positioning of vertices in the objects. Thats the world within the objects. "World positioning" is referring to the positioning of the objects in the world in which the camera moves in. Best way to describe it is putting a boxes inside a box, or spaces inside a space. Well I think you know what I mean.

    But anyways, I seem to be handing the vertices positioning fine, problem is, my objects positioning seems a little odd.

    Oh and, Well I don't really know what the traditional methods were, so I just went a long with my own flow using the tutorials I found.

    And I decided to ditch quarternions for now, I don't think I will be able understand them for a long while lol.

    Oh and in case your wondering why I'm talking about it like as if I haven't solved any of it yet, its because I haven't, it was driving me nuts so I took a little break, gonna get back to it soon.

    I'm still not sure how I'm gonna go about occlusion culling, I do have a method that should work in mind, but its rather complex.
    Last edited by cody112; 07-12-2010 at 04:31 PM.

  6. #6
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    Perhaps look at achieving this stuff using matrix multiplications in a more generalized 3d pipeline kind of approach.

    I sent you a PM with my details if you want my help!

  7. #7
    Member
    Join Date
    Aug 2007
    Posts
    47
    I've been experimenting with 3D in AS3. The flashandmath site has been most helpful, as well as the Adobe AS3 Language reference pages - on Vector3D and Matrix3D in particular.
    As for culling, have you tried using the graphics method 'drawTriangles'? If not, I'd recommend the page on the 'graphics' class (From the link below, click index >> G >> Graphics, then scroll down to drawTriangles)...
    http://help.adobe.com/en_US/AS3LCR/F...0.0/index.html
    ...One point about this method - that took some time to stumble upon - is that each triplet of indices should be described in clockwise direction. If not, you will get unpredicted and unfortunate culling results.
    Last edited by moosefetcher; 10-22-2010 at 06:15 AM.

  8. #8
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    Note that the draw triangles functionality includes winding based back faced culling only, this is not the only method of culling to consider, others are;

    FRUSTUM CULLING:
    A geometry object is usually contained within some kind of bounding area (typically an axis aligned bound box aka aabb or a bounding spere). A frustum is a box defined as the visible area in front of the camera. The aabb or bounding sphere is checked against 6 planes of the frustum to check which side they are on... if they are on the outside, the geometry (and children if you use a scenegraph controlled aka BVH), becomes culled.

    OCCLUSION CULLING:
    By using hidden planes to define transition ports between game areas, we can occlude areas of the world that are not visible from your current position. There are many ways to do this, portals for example or calculations using spacial subdivisions and what not..

    iab

    RipX

  9. #9
    Senior Member
    Join Date
    Sep 2008
    Posts
    100
    Quote Originally Posted by RipX View Post
    Note that the draw triangles functionality includes winding based back faced culling only, this is not the only method of culling to consider, others are;

    FRUSTUM CULLING:
    A geometry object is usually contained within some kind of bounding area (typically an axis aligned bound box aka aabb or a bounding spere). A frustum is a box defined as the visible area in front of the camera. The aabb or bounding sphere is checked against 6 planes of the frustum to check which side they are on... if they are on the outside, the geometry (and children if you use a scenegraph controlled aka BVH), becomes culled.

    OCCLUSION CULLING:
    By using hidden planes to define transition ports between game areas, we can occlude areas of the world that are not visible from your current position. There are many ways to do this, portals for example or calculations using spacial subdivisions and what not..

    iab

    RipX
    Its funny... I thought occlusion culling was the removal of polygons hidden by other geometry. Am I wrong? And, even if I haven't implemented frustum culling completely already, the concept is simple and is easy to finish up the process.

  10. #10
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    @cody112 That's correct! I was using an invisible plane as the geometry you speak of, but essentially a tri fully behind another could be removed and this is also occulusion culling. by using the plane example you can create a 2 way relationship between the area you are inside and the area behind the invisible plane and you've now got the 'portal' principle.

    Anyway, responded to your PM. Enjoy

    RipX

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