This is G o o g l e's cache of http://www.flashsandy.org/forum/lofiversion/index.php/t50.html as retrieved on 20 Jul 2007 19:32:03 GMT.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
This cached page may reference images which are no longer available. Click here for the cached text only.
To link to or bookmark this page, use the following url: http://www.google.com/search?q=cache:B6KpjZdsyOQJ:www.flashsandy.org/forum/lofiversion/index.php/t50.html+site:www.flashsandy.org/forum&hl=en&ct=clnk&cd=24


Google is neither affiliated with the authors of this page nor responsible for its content.

Full Version: hitTest in 3d?
Pages: 1, 2
Zaba
Hey, im creating a flash 3d game. i wanna this:
camera follows mouse,
ASDW control,
Space as jumping,
world.
1 and 3 are MAIN problems.
HEEELPP!
In other words, i want basic phisics:
if not touching ground
vspeed++
else
vspeed=0
if jumping
vspeed = 20


Help me please asap!
kiroukou
Hi,
Did you tried something?
I can help you to correct your code, or to give you the best solution to a specific problem, but I can't do the job for you.

What you needs seems feasible to me. Camera follows mouse is quite easy, and the basic physics engine can be done if you implement some physics tests of the objects vertex!

++
Zaba
i done it all in 2d already. a month ago. is there a way to port 2d code to pseudo3d, huh. im first day at sandy, im gonna experiment with other (p00r) 3d engines before. no idea about hitTest in 3d yet... btw im kinda new to Math3d things. ;-)

EDIT: yay i done something (movement for/back)
Zaba
Look at this
its flash8
the problem is i want to hop on and stay at box
Zaba
Jumping is done for 1/3
:-S
point me to my mistake... hope ull notice it... try to jump (Space)
kiroukou
Not nice but working code :
CODE

import sandy.core.light.*;
import sandy.core.data.*;
import sandy.core.group.*;
import sandy.primitive.*;
import sandy.view.*;
import sandy.core.*;
import sandy.skin.*;
import sandy.util.*;
import sandy.core.transform.*;
import sandy.events.*;
var vspeed = 0;
// screen creation, the object where objects will be displayed.
var ecran:ClipScreen = new ClipScreen(this.createEmptyMovieClip('ecran', 1), 600, 600);
// we create our camera
var cam:Camera3D = new Camera3D(700, ecran);
// we add the camera to the world
World3D.getInstance().addCamera(cam);
//We create the Light coming from the left with a low intensity (20)
var l:Light3D = new Light3D(new Vector(1, 0, 0), 20);
// set the world light
World3D.getInstance().setLight(l);
// we create the root node.
var bg:Group = new Group();
// and set it as the root node of the world.
World3D.getInstance().setRootGroup(bg);
// and we launch the scene creation
createScene(bg);
// and now that everything is created, we can launch the world rendering.
World3D.getInstance().render();
function createScene(bg:Group):Void {
    // We create our object. It is a cube of 50 pixels, and with the quad mode, so here four points per face.
    var o:Object3D = new Box(50, 50, 50, 'quad');
    // we create a skin to "dress up " the object a bit, and make it visually better.
    //  SimpleColor skin is used here, it needs the fill color, alpha, and thickness
    var skin:Skin = new MixedSkin(0x00FF00, 100, 0, 1);
    // NEW PART, we enable the light
    skin.setLightingEnable(true);
    // We apply the skin to the object
    o.setSkin(skin);
    // We create two TransformGroup instances. Each one corresponds to a node of the tree we are going to create.
    var tg1:TransformGroup = new TransformGroup();
    var tg2:TransformGroup = new TransformGroup();
    // We also create two instances of Translation objects.
    // Give them an appropriate name, this becomes important very rapidly.
    var translation:Transform3D = new Transform3D();
    // We create an interpolator to make it rotate linearly for a while
    var ease:Ease = new Ease();
    ease.linear();
    var rotint:RotationInterpolator = new RotationInterpolator(tg2, ease.create(), 300);
    // we translate the object by 500 pixels on the Z axis.
    translation.translate(0, 0, 500);
    // We apply those transformations to the nodes.
    tg1.setTransform(translation);
    tg2.addChild(rotint);
    // We add the rotation tansformation to the node which represents the rotation,by setting it as a child.
    // The rotation will be applied first, translation later (higher in the tree)
    tg2.addChild(o);
    // Now we link the two nodes
    // The order here is very important.
    tg1.addChild(tg2);
    // Now we simply link the translation node to the root node, thus completing the tree creation
    bg.addChild(tg1);
}
var ljmp = false;
onEnterFrame = function(){
    if(Key.isDown(Key.UP)){
        cam.moveForward(10);
    }
    if(Key.isDown(Key.DOWN)){
        cam.moveForward(-10);
    }
    if(Key.isDown(Key.RIGHT)){
        cam.rotateAxis(0, 1, 0, 3);
    }
    if(Key.isDown(Key.LEFT)){
        cam.rotateAxis(0, 1, 0, -3);
    }

    if(ljmp && cam.getPosition().y > 0 ){
        vspeed --;
    } else if (ljmp && cam.getPosition().y <= 0 )
    {
        vspeed = 0;
        ljmp = false;
    }    
    if(Key.isDown(Key.SPACE) && !ljmp){
        vspeed = 20;
        ljmp = true;
    }
    cam.moveVertically(vspeed);
    trace(cam.getPosition().y);
    trace(vspeed);
}
onMouseMove = function(){
    var nx = _root._xmouse;
    var ny = _root._ymouse;
}

++
Zaba
THANq

now problem is hittesting, no idea yet :-(
a huge for-in around all Object3Ds? no i think.
other ideas ? no, too...
Zaba
read things on guide layer

I wanna hittest in 3d
help me with it
please.
kiroukou
Hey Zaba,
you can't ask some help and have somebody giving you the answer immediatly! Please take time for think about the problem yourself, ask for some precise problems!

We have all a personnal life, we are not living on that board smile.gif
Zaba
Im living with computer.
Ive thinked about it and i have NO idea...
thats why im here!
kiroukou
Well,

For example, you did't say which king of collision test do you want.
Is it floor against object? object/object? object / camera?

You see? How can we help you if the problem isn't described correctly wink.gif

But this is a complicated part! You should do some research and some tests ! And also be patient because this will take some time for sure if you want to do it correcly.

++
Zaba
I need to make camera stay on floor, be able to hop on and stay to any surface. floor is an object too, btw. and not to walk into surfaces, like walls.

simply, camera must collide to all objects.
Zaba
huh, it does jump better now...
Zaba
Im dumb in Math, btw.
thats why im asking you.
kiroukou
Well I'm sorry but I have a lot of work curently and some others projects (developing Sandy take a lot of time).

So I'm sorry, I'm not able to code anything for you. I just can give you the good orientation to do that.
Retrieve the surfaces, compute their equation (easy to do with the normal vector), and then make a collision test with a 3D point, or a 3D segment.
Otherwise you should learn some math basics! This is not very funny to do, but so usefull smile.gif
Zaba
Well, i have other 2D projects too.
But asap please -v it. :-( im too silly and non-english to understand it from 1 sentence... sorry if im very annoying here. but if i have 3 boxes with different Y and X ill need to check all of them? ill learn math i think, i *hope* i will... but for now i cant so im here asking you and others (i think).


Camera here, Camera steps here, so ill need to check only point under camera? how to get it (point) then?
>>>>| >>>> |
+--------+
|---------|+------+
|---------|--------|
+--------+-------+

Thanq for help.
Read/reply asap.
PS: the best is to make a Game Tutorial.
PPS: what a good forum you have
Zaba
I suck (this totally slows down it):
CODE
var nx = mt._xmouse/250;
    var ny = mt._ymouse/250;
    for(var i in bg.getChildList()){
        if(bg.getChildList()[i].isParent()){
            rlist.push(bg.getChildList()[i]);
        } else {
            //collision detection
            //bg.getChildList()[i]. ...
        }
    }
    for(var i in rlist){
        //collision detection:
        //this[rlist[i]]. ...
    }
kiroukou
Good start!
But you should before try to retrieve the Leaf objects, and more precisely the Object3D instances!

You can do a loop like this but test current_node instanceof Object3D, and if true, push it into your array list.

++
Zaba
well as i said this code will slow it down really, so it will be good to know whats under the camera and chect only that point. My code cant parse big worlds, but as i planned them too i think i should try other methods... looparound all objects is bad, isnt it?
ill try what ure suggesting anyway.
thanks

by the way... im already using isParent(), so only groups can be a parents or not? isnt it = instanceof Group? ant can Groups contain something another than Object3Ds? or im wrong?
Zaba
you meant this, right?

CODE

var nx = mt._xmouse/250;
    var ny = mt._ymouse/250;
    for(var i in bg.getChildList()){
        if(bg.getChildList()[i].isParent()){
            if(bg.getChildList()[i] instanceof Object3D) rlist.push(bg.getChildList()[i]);
        } else {
            //collision detection
            //bg.getChildList()[i]. ...
        }
    }
    for(var i in rlist){
        //collision detection:
        //this[rlist[i]]. ...
    }


PS: who needs PHP here?
Zaba
Hey,
how to get X of Object3D 8-S
i gonna be dumb...
kiroukou
An object3D does not have an x in Sandy!

As an object is in fact composed by faces, and not as an object, you do have an position property!

But I'm thinking on a workaround to allows you to get this position!
I'll try it, and include it in the update I'll do this week I hope.

Thnaks for this question.
++
Zaba
huh, i used getZBounds, ill need getXBounds too!
Zaba
hm. i think all i need for basic collision detection is to get a face, get its points, get camera pos and test for collision? cant i write a hitTest3d(Object3D, Camera) method and use it?
kiroukou
Yes or to use the bounds of the object indeed.

It is not very accurate, but enought I guess for a simple game.
I'll implement it!
Zaba
oh thank you! biggrin.gif
bounds isnt accurate as tiles could be only cubes then wink.gif
no tiles at all = the best...
I sure ill be able to improve it when ill need something more advanced.

why dont you like Face checking?

im not plannng to create a simple game, but a story-based FPS (gpled of course)
kiroukou
Face checking needs a lot of computations, imagine that you'll have to compute the distance between the cam pos, to all the vertex of the object.

With the bounds object, Bounding Box, you just have to compute the distance from 8 vertex!
So very useful with complex object
Zaba
but if the object isnt a cube, what to do then?
kiroukou
What do you mean, a Sprite?
Zaba
i meant Sphere or a Pyramid
kiroukou
Yes so instead of testing the important number of vertices og those objects, you'll jsut have to check the 8 vertices of the Bounding Box object!

So 8 tests instead of 50 per frame, this can be useful smile.gif
Zaba
ehm... i didnt get the point. if i have a pyramid theres no difference between walking over it and its bonding box???
kiroukou
The Bounding box is the volume that encapsulate (don't know the right word) your object.
If you are testing a cube or a pyramid, this is not useful (because of the number of vertices), and with a cone or a sphere it starts to become necessary!

For sure testing the Bounding Box is less accurate, but allows you to save some computations. The result should enough for your game.
Zaba
QUOTE(kiroukou @ Jun 30 2006, 11:19 PM) *

The Bounding box is the volume that encapsulate (don't know the right word) your object.
If you are testing a cube or a pyramid, this is not useful (because of the number of vertices), and with a cone or a sphere it starts to become necessary!

For sure testing the Bounding Box is less accurate, but allows you to save some computations. The result should enough for your game.

im not sure.
ill need complex maps i think.
if ill use bounding box for huge pyramid ill not be able to walk on it as on real pyramid?
kiroukou
You want to walk on a pyramid face?
You're optimitic smile.gif

So indeed in this case you can use it. You should use Bounding Box just to avoid collision.
But I think your project is too complex for this version of Flash... maybe in AS3..?
Zaba
AS3? noo ill wait for 2007 to use nonalpha nonbeta version.
lets experiment with faces now.
Zaba
how to get camera's rotation?
kiroukou
You can't.

Is it useful for you to be able to obtain the camera rotation?
Zaba
yeah. to make it NOT to rotate on Z
kiroukou
Just do the correct rotatios to make it NOT rotate around Z axis no?
Zaba
im rotating X and Y according to mouse but it starts rotation Z in a while (why)?
any solutions?
kiroukou
It is possible. Depends on your code.

But I had also this problem, si maybe it is a bug, but in this case, I have some problems to be able to solve this one.
Zaba
here is it ull see comment before it

ahem.
cant it be sloved in nonsandy level?
Zaba
i have an idea.
why not to first check bounding boxes then check object(s) that are colliding on BB level by faces?
Zaba
hitTest3d(group:Group, x, y, z);

that shud be enuf.
as i said in prevous post, it will be great.
kiroukou
Please do it smile.gif

I will not do it myself !
This is an open source project, that means that people should make some contributions!
Zaba
ahem.
if i would be able to do that i wouldnt come to here.
and yeah. i dont even kno:
what getBounds returns?
am i able to get camera/Object3d pos?
ill get some faces from obj3d, what i can do with em? i cant get points!
then maybe ill do something.
Zaba
im not asking u to do it but to help me.
Zaba
QUOTE(Zaba @ Jul 1 2006, 09:54 PM) *

im rotating X and Y according to mouse but it starts rotation Z in a while (why)?
any solutions?

I got the problem, it occurs in any 3d engine (Shockwave3D for example)
i think ill think around it so thats not the problem now.
Zaba
will not really work, the question is in comment.

Sketch:

function hitTest3d(g:Group, x, y, z){
for(var i in g.getChildList()){
if(g.getChildList()[i].getBounds()[0] >= x && g.getChildList()[i].getBounds()[1] <= x && g.getChildList()[i].getBounds()[2] >= y && g.getChildList()[i].getBounds()[3] <= y/*Z here too?*/){
for(var j in bg.getChildList()[i].getFaces()){
//What to do with face?
trace(bg.getChildList()[i].getFaces()[j]);
}
}
}
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2007 Invision Power Services, Inc.