Posted by: kyuzo Mar 9 2007, 07:55 PM
hi all.
i'm still trying to get to know sandy; i have a simple scene:
CODE
import sandy.view.*;
import sandy.core.World3D;
import sandy.core.group.*;
import sandy.primitive.*;
import sandy.core.transform.*;
import sandy.core.data.Vector;
class Main{
static function Main(){
var camera:Camera3D=new Camera3D(100);
camera.setPosition(0,0,-20);
World3D.getInstance().setCamera(camera);
var root:Group=new Group();
var sphere:Sphere=new Sphere(5,3,"quad");
root.addChild(sphere);
World3D.getInstance().setRootGroup(root);
World3D.getInstance().render();
}
static function main(){
var m=new Main();
}
}
i would expect the sphere to be drawn in the middle of the scene, but it gets drawn in the left upper corner.
any idea why?
http://tcornel.googlepages.com/s6.swf
Posted by: zeusprod Mar 9 2007, 08:44 PM
QUOTE(kyuzo @ Mar 9 2007, 02:55 PM)

i would expect the sphere to be drawn in the middle of the scene, but it gets drawn in the left upper corner.
any idea why?
http://tcornel.googlepages.com/s6.swf
I
recommend adding axes to your world for reference as described in
petit's tutorial. That way, you can see where it "really" is.
And you can wrap it in a transform and set the location using the translation method.
I always wrap it, so I never tested what happens "by default"
Regards,
Bruce
Posted by: Petit Mar 10 2007, 01:21 AM
QUOTE(kyuzo @ Mar 9 2007, 08:55 PM)

i would expect the sphere to be drawn in the middle of the scene, but it gets drawn in the left upper corner.
any idea why?
Well,
if you look at any example written for Sandy 1.1, you'll see that
there's two arguments to pass to the Camera3D constructor. The first is
the focal or nodal distance, which in effect determines the viewing
angle of the camera, the second is a ClipScreen with a width and a
height. This is the area your world is drawn on.
If it has the same dimensions as your stage, the world origin ( and your sphere ) will be in the middle of the stage.
Good advice from Bruce there - http://www.flashsandy.org/tutorials/ and http://www.petitpub.com/labs/media/flash/sandy/.
Good luck!
Posted by: kyuzo Mar 10 2007, 02:28 PM
QUOTE(Petit @ Mar 10 2007, 02:21 AM)

if you look at any example written for Sandy 1.1
thank you and zeusprod for the reply, but i think i'm lost; i was thinking that i'm using the 1.2 beta...
is the ClipScreen necesary in sandy 1.2?
could someone please post a few lines of code, in sandy 1.2, that would draw that sphere in the center of the window?
thank you.
Posted by: zeusprod Mar 10 2007, 05:09 PM
QUOTE(kyuzo @ Mar 10 2007, 09:28 AM)

thank you and zeusprod for the reply, but i think i'm lost; i was thinking that i'm using the 1.2 beta...
is the ClipScreen necesary in sandy 1.2?
could someone please post a few lines of code, in sandy 1.2, that would draw that sphere in the center of the window?
thank you.
I
haven't worked with the Sandy 1.2 beta or ActionScript 3. I've only
worked with 1.1. I don't know if ClipScreen is necessary in 1.2, but it
is necessary, I believe in 1.1. The screen is passed as the second
argument to the Camera3D constructor. I suggest you try working with
Sandy 1.1. If that works, then you can try to port the code to 1.2.
Your
code didn't compile with AS2 and Sandy 1.1. I don't know if it works
with AS 3 and Sandy 1.2, but your code looks wrong to me.
Here is some working code for AS2 and Sandy 1.1.
Note
that I've removed the lowercase "main()" function, and made the
uppercase "Main()" function public and not static. I've also added a
clipscreen and created a 400 x 400 viewing window. I've passed the
clipScreen to the Camera3D constructor. Also, I've changed
"setCamera()" to "addCamera()". In Sandy 1.1, setCamera isn't supported
in the way you used it. I don't know if your code works in 1.2. Again,
if you compile the code in the Flash authoring tool, it will warn you
about attempts to invoke incorrect methods.
The following code belongs in a file named "Main.as". Compile it in the Flash authoring tool, so you know it is error free.
CODE
import sandy.view.*;
import sandy.core.World3D;
import sandy.core.group.*;
import sandy.primitive.*;
import sandy.core.transform.*;
import sandy.core.data.Vector;
class Main{
//static function Main(){
public function Main(){
var
screen:ClipScreen = new ClipScreen(_root.createEmptyMovieClip('screen',
1), 400, 400, 0xffffff);
// Create a camera, so we can see our world.
// Give it a focal distance and a reference to the viewing screen.
var camera:Camera3D=new Camera3D(100, screen)
camera.setPosition(0,0,-20);
// World3D.getInstance().setCamera(camera);
World3D.getInstance().addCamera(camera);
var root:Group=new Group();
var sphere:Sphere=new Sphere(5,3,"quad");
root.addChild(sphere);
World3D.getInstance().setRootGroup(root);
World3D.getInstance().render();
}
}
This
code goes in the first frame of your test .fla file. I made that fla
400 x 400 (in its document settings) to match the 400 x 400 clipscreen
above.
CODE
function main(){
var m=new Main();
}
main();
This works for me. It draws the circle in the center of the screen.
Cheers
Bruce (zeusprod)
Posted by: Petit Mar 10 2007, 05:36 PM
QUOTE(kyuzo @ Mar 10 2007, 03:28 PM)

i was thinking that i'm using the 1.2 beta...is the ClipScreen necesary in sandy 1.2?
No, if you are using Sandy 1.2 beta, there is no ClipScreen argument.
Here's some code for the 1.2 version.
The values passed to the Camera3D constructor is the width of the stage in this case.
The init method
CODE
var world:World3D = World3D.getInstance(); // Our 3D world
function init( Void ):Void {
// Pass the size of the rendering surface to the camera
var cam:Camera3D = new Camera3D( 200, 200 );
// Position the camera at a negative distance along the z axis
cam.setPosition(0,0,-300);
// Attach the camera to the world
world.setCamera( cam );
// Create the root group, the branch node for all objects in our world
var bg:Group = new Group();
// and attach it to the world.
world.setRootGroup( bg );
// Create the scene and attach it to the rootGroup
createScene( bg );
// Finally we start rendering the world
world.render();
}
The createScene() method creates the actual content of the world's root group
CODE
function createScene( bg:Group ):Void {
// I'm creating a coordinate system to see where in the world I am
createCoordinateSystem(bg, true, 1);
// Create the Sphere
var sphere = new Sphere( 40, 5, 'tri');
sphere.setSkin( skin=new SimpleColorSkin(0xFEFE4E, 80));
skin.setLightingEnable(true);
bg.addChild( sphere );
}
In this case I am creating a coordinate system for reference ( from my tutorials on Sandy 1.1 )
Run it here
SphereTest4.swf ( 32.28k )
Number of downloads: 16