2D sprite in a 3D world
I''ve been looking into this alot but I can seem to find much information on exactly how to do it. I want to create a game in which a 2D plane/billboard is used as the main object the camera focuses on, like in Paper Mario, Star Ocean, Final Fantasy Tactics and the like. The thing is, how would I do collision dection with a flat object like that, and when moving the camera around won''t the billboarding process throw off my x, y, and z values? I''d be nice if someone could show me a tutorial of this type of thing. I just can''t grasp the concept of using billboarding to achieve it...
"Life is a double edged sword, we always hope to strike though adversity with the shining side..."
jkettles16 of Venosoft
"Life is a double edged sword, we always hope to strike though adversity with the shining side..."jkettles16 of Venosoft
billboarding rotates the sprite to face the camera, it doesnt move the spite at all.
June 28, 2003 03:27 AM
Look at NeHe''s tutorial #9, the one with the stars. It shows this perfectly.
Sumarized: You mvoe the object (quad) to the right place as any object, by rotating and translating it. When in the right position, so ''undo'' the rotations in the oposite order, so that it once again faces the camera.
Sumarized: You mvoe the object (quad) to the right place as any object, by rotating and translating it. When in the right position, so ''undo'' the rotations in the oposite order, so that it once again faces the camera.
Ya I believe I understand, besides it''s not like my object''s x, y, and z stored in program are going to change anyway when OpenGl does it''s translations because thier not passed to the rountines by reference, but even still...since the object is a flat quad with no depth, if it rotates to face the camera during a really close collision detection won''t it intersect the wall?
"Life is a double edged sword, we always hope to strike though adversity with the shining side..."
jkettles16 of Venosoft
"Life is a double edged sword, we always hope to strike though adversity with the shining side..."
jkettles16 of Venosoft
"Life is a double edged sword, we always hope to strike though adversity with the shining side..."jkettles16 of Venosoft
{ For rendering }
just store the position of your images, then take the Up vector and Right vector of your camera and use them as y and x axis.
{ For collision detection }
Well since the billboard ROTATES around a POINT then that can only mean one thing... a SPHERE
do your collisions with a sphere, where the radius is half the size of your image.
to get the distances between two points, translate both points so that one of the points "lands" on origo, then check the magnitude (lenght) of the vector to the second point. Meaning:
ehm... you better skip the effeciency part until you fully understand and have a working version of the first stuff
! NOTE ! Vector3f is not a built in type or something, you'll have to write it yourself. But here a struct{ float x,y,z; } would work
"No lies of sugar can sweeten the sournes of reality"
}+TITANIUM+{ A.K.A. DXnewbie[onMIRC]
[edited by - Seriema on June 28, 2003 9:33:37 PM]
just store the position of your images, then take the Up vector and Right vector of your camera and use them as y and x axis.
// pseudo codeVector3f xAxis = GetCameraFromSomewhere()->GetRight(), yAxis = GetCameraFromSomewhere()->GetUp(); // They must be normalized vectors!Vector3f x = xAxis * halfObjSize, y = yAxis * halfObjSize;Vector3f bottomLeft = objPosition - y - x, topleft = objPosition + y - x, topright = objPosition + y + x, bottomright= objPosition - y + x;// now isn't that fun?
{ For collision detection }
Well since the billboard ROTATES around a POINT then that can only mean one thing... a SPHERE
do your collisions with a sphere, where the radius is half the size of your image.
to get the distances between two points, translate both points so that one of the points "lands" on origo, then check the magnitude (lenght) of the vector to the second point. Meaning:
Vector3f checkPoint = myObj2 - myObj1;float lenght = sqrt( checkPoint.x^2 + checkPoint.y^2 + checkPoint.z^2 );if ( lenght < radius ) PANG(myObj1, myObj2);/*{ For effeciency }don't sqrt() since that's not nice to the cpu, use it squared and compare to radius^2. (and don't use pow() to square, just write radius*radius):float lengthSquare = checkPoint.x^2 + checkPoint.y^2 + checkPoint.z^2if ( lengthSquare > radius*radius ) PANG(myObj1, myObj2);*/
ehm... you better skip the effeciency part until you fully understand and have a working version of the first stuff

! NOTE ! Vector3f is not a built in type or something, you'll have to write it yourself. But here a struct{ float x,y,z; } would work

"No lies of sugar can sweeten the sournes of reality"
}+TITANIUM+{ A.K.A. DXnewbie[onMIRC]
[edited by - Seriema on June 28, 2003 9:33:37 PM]
[ ThumbView: Adds thumbnail support for DDS, PCX, TGA and 16 other imagetypes for Windows XP Explorer. ] [ Chocolate peanuts: Brazilian recipe for home made chocolate covered peanuts. Pure coding pleasure. ]
So I'm basically using a plane, but collision detection and the camera would treat it more like a sphere or cylinder. That should work well, thank you.
"Life is a double edged sword, we always hope to strike though adversity with the shining side..."
jkettles16 of Venosoft
[edited by - jkettles16 on June 28, 2003 9:28:53 PM]
"Life is a double edged sword, we always hope to strike though adversity with the shining side..."
jkettles16 of Venosoft
[edited by - jkettles16 on June 28, 2003 9:28:53 PM]
"Life is a double edged sword, we always hope to strike though adversity with the shining side..."jkettles16 of Venosoft
hmm... well the object itself should be treated like a sphere (or cylinder if you wish, but that''s harder to collisiondetect). but the graphical representation is a flat texture.
"No lies of sugar can sweeten the sournes of reality"
}+TITANIUM+{ A.K.A. DXnewbie[onMIRC]
"No lies of sugar can sweeten the sournes of reality"
}+TITANIUM+{ A.K.A. DXnewbie[onMIRC]
[ ThumbView: Adds thumbnail support for DDS, PCX, TGA and 16 other imagetypes for Windows XP Explorer. ] [ Chocolate peanuts: Brazilian recipe for home made chocolate covered peanuts. Pure coding pleasure. ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement