dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: PAPERVISION: Set 3D markers on a sphere based on a sub-MC in its material

  1. #1
    Junior Member
    Join Date
    Jul 2009
    Posts
    2

    Angry PAPERVISION: Set 3D markers on a sphere based on a sub-MC in its material

    I'm really struggling with this - hope that someone can help out with the 3D math. I've tried everything and nothing seems to work.

    There are plenty of examples out there doing something similar but with lat/lang coordinates directly (for example*http://blog.zupko.info/?p=221) but I'm not working with lat/lang but pixels directly.*

    I have a 3D sphere with movieclipmaterial surface. That movieclipmaterial has inside it a series of other movieclips - dots basically. What I'd like to do is position 3D objects (arrows basically) directly above those points of the sphere.

    How would I convert 2D x,y points from the movieclipmaterial surface to the 3D coordinate system of the sphere x,y,z? Any ideas?

    I've tried to adapt the code from the blog above - but its simply not working and I've been at it for days now.

    Take a look here -*http://files.getdropbox.com/u/355341/mtest02.swf - once you click on the globe an rotate it, the 3D marker should reposition itself above the "dot" MC in the globe material.*

    And then take a quick look ( http://files.getdropbox.com/u/355341/mtest02.fla ) at the code and maybe tell me what I'm doing wrong? I've simplified the code to include only this particular problem - there are only a few lines of code so anybody with experience should be able to locate the problem quickly.

    Please help - its a college project and I'm supposed to turn it in soon.

    Thank you!

  2. #2
    Palindrome emordnilaP Diniden's Avatar
    Join Date
    Feb 2008
    Posts
    230
    I don't know about papervision, but have you tried using spherical coordinates? Use spherical coordinates then convert to rectangular coordinates to find where in 3D space things are supposed to be positioned.

    When I look at the swf, it looks like you're just 90 off on some axis. When I went through the code, I was hoping there was some actual math system involved in placing your cube :P but it seems you're just trying to use the shtuff of papervision...

    Well, hope my suggestion sparks some thoughts : )

  3. #3
    Junior Member
    Join Date
    Jul 2009
    Posts
    2
    Hi Diniden - thanks for your thoughts.

    Papervision is more or less just used for automated display and rendering. My problem actually is with math - I still have to calculate the positions of objects in 3D space manually.

    What I want to do is take a movieclip object that is embedded within the sphere texture (and of which I can get 2D x,y flash coordinates) and calculate its 3D x,y,z position in relations to the sphere so that I can position another 3d object there.

    I've had radians and higher math at some point in past - but unfortunately I just don't remember enough of it. So if you can - please do help out

    The problem is just in the following code:
    Code:
    var w2:Number = MovieMaterial(sphere.material).rect.width;
    var h2:Number = MovieMaterial(sphere.material).rect.height;		
    		
    var l = MovieClip(MovieMaterial(sphere.material).movie).dot.x * (Math.PI/180);
    var lo = MovieClip(MovieMaterial(sphere.material).movie).dot.y * (Math.PI/180);
    		
    var x = 500 * (Math.sin(l) * Math.cos(lo));
    var y = 500 * (Math.sin(l) * Math.sin(lo));
    var z = 500 * Math.cos(l);
    The first two lines are just to get the width/height of the sphere texture. The second two should get the spherical coordinates and then the final 3 convert those into cartesian coordinates.

    Od something along those lines

  4. #4
    Palindrome emordnilaP Diniden's Avatar
    Join Date
    Feb 2008
    Posts
    230
    I can't think off of my head how you are working the conversion from the flat surface of the texture to spherical coordinates...But I can see that you are definitely missing the point by somewhere around 90

    So, though it may not be a true fix, try throwing in + or -Math.PI/2 within different locations of the cosines and sines.

    I'm trying to devise a way to convert from the flat plane to the sphere. I'm assuming papervision evenly distributes the entirety of the plane over the sphere. (I'm not too familiar with jumping from texture space to 3D space yet ;~;, just started that part on my pipeline : )

  5. #5
    Junior Member
    Join Date
    Jul 2009
    Posts
    1
    Is the shere radius equal to 500? Try this one.

    Code:
    var w2:Number = MovieMaterial(sphere.material).rect.width;
    var h2:Number = MovieMaterial(sphere.material).rect.height;		
    		
    var l = Math.PI*MovieClip(MovieMaterial(sphere.material).movie).dot.x / (w2);
    var lo = 2*Math.PI*MovieClip(MovieMaterial(sphere.material).movie).dot.y / (h2);
    		
    var x = 500 * (Math.sin(lo) * Math.cos(l));
    var y = 500 * (Math.sin(lo) * Math.sin(l));
    var z = 500 * Math.cos(lo);
    And yep, play for a while with the axis directions (and switch l and lo) and angles.

  6. #6
    Palindrome emordnilaP Diniden's Avatar
    Join Date
    Feb 2008
    Posts
    230
    Aye according to spherical coordinates, he's setting the radius to 500.

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