Irrlicht Wrapper for 3D games and applications

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
super_castle
Posts: 289
Joined: Oct 10, 2006 7:19

Postby super_castle » Apr 07, 2010 16:03

have the found.
every body must be pivatnode the helicopter.
now it works.

Texture : rot.png blau.png and has yet to be created.

gruss

Code: Select all



#include "IrrlichtWrapper.bi"

Dim Mesh As irr_mesh
Dim MeshTexture As irr_texture
Dim OurCamera As irr_camera

Dim CentreNode As irr_node
Dim EdgeNode1 As irr_node
Dim EdgeNode2 As irr_node
Dim PivotNode As irr_node
Dim PivotNode1 As irr_node
Dim PivotNode2 As irr_node

Dim CentreNode0 As irr_node
Dim EdgeNode10 As irr_node
Dim EdgeNode20 As irr_node
Dim PivotNode0 As irr_node
Dim PivotNode10 As irr_node
Dim PivotNode20 As irr_node

Dim CentreNode1 As irr_node
Dim PivotNode30 As irr_node

Dim CubeRotation As Double

IrrStart( IRR_EDT_OPENGL, 512, 512, IRR_BITS_PER_PIXEL_32, _
        IRR_WINDOWED, IRR_NO_SHADOWS, IRR_IGNORE_EVENTS )
IrrSetWindowCaption( "quadro" )

'--------------------------------------------------------
PivotNode = IrrAddEmptySceneNode
IrrSetNodePosition( PivotNode, 0.0, 0.0, 0.0 )
CentreNode = IrrAddTestSceneNode
MeshTexture = IrrGetTexture("./media/rot.png")
IrrSetNodeMaterialTexture( CentreNode, MeshTexture, 0)
IrrSetNodeScale( CentreNode, 1.8,0.03,0.03 )
IrrAddChildToParent(CentreNode, PivotNode)

PivotNode1 = IrrAddEmptySceneNode
IrrSetNodePosition( PivotNode1, 0.0, 0.0, 0.0 )
EdgeNode1 = IrrAddTestSceneNode
MeshTexture = IrrGetTexture("./media/blau.png")
IrrSetNodeMaterialTexture( EdgeNode1, MeshTexture, 0 )
IrrSetNodeScale( EdgeNode1, 0.5,0.01, 0.04)
IrrAddChildToParent(EdgeNode1, PivotNode1)

PivotNode2 = IrrAddEmptySceneNode
IrrSetNodePosition( PivotNode2, 0.0, 0.0, 0.0 )
EdgeNode2 = IrrAddTestSceneNode
MeshTexture = IrrGetTexture("./media/blau.png")
IrrSetNodeMaterialTexture( EdgeNode2, MeshTexture, 0 )
IrrSetNodeScale( EdgeNode2, 0.5,0.01, 0.04)
IrrAddChildToParent(EdgeNode2, PivotNode2)

IrrAddChildToParent(PivotNode1,PivotNode )
IrrSetNodePosition( PivotNode1, 8.8, 0.4, 0.0)

IrrAddChildToParent(PivotNode2,PivotNode )
IrrSetNodePosition( PivotNode2, -8.8, 0.4, 0.0)
'-------------------------------------------------------

PivotNode0 = IrrAddEmptySceneNode
IrrSetNodePosition( PivotNode0, 0.0, 0.0, 0.0 )
CentreNode0 = IrrAddTestSceneNode
MeshTexture = IrrGetTexture("./media/rot.png")
IrrSetNodeMaterialTexture( CentreNode0, MeshTexture, 0 )
IrrSetNodeScale( CentreNode0, 1.8,0.03,0.03 )
IrrAddChildToParent(CentreNode0, PivotNode0)

PivotNode10 = IrrAddEmptySceneNode
IrrSetNodePosition( PivotNode10, 0.0, 0.0, 0.0 )
EdgeNode10 = IrrAddTestSceneNode
MeshTexture = IrrGetTexture("./media/blau.png")
IrrSetNodeMaterialTexture( EdgeNode10, MeshTexture, 0 )
IrrSetNodeScale( EdgeNode10, 0.5,0.01, 0.04)
IrrAddChildToParent(EdgeNode10, PivotNode10)

PivotNode20 = IrrAddEmptySceneNode
IrrSetNodePosition( PivotNode20, 0.0, 0.0, 0.0 )
EdgeNode20 = IrrAddTestSceneNode
MeshTexture = IrrGetTexture("./media/blau.png")
IrrSetNodeMaterialTexture( EdgeNode20, MeshTexture, 0 )
IrrSetNodeScale( EdgeNode20, 0.5,0.01, 0.04)
IrrAddChildToParent(EdgeNode20, PivotNode20)

IrrAddChildToParent(PivotNode10,PivotNode0 )
IrrSetNodePosition( PivotNode10, 8.8, 0.4, 0.0)

IrrAddChildToParent(PivotNode20,PivotNode0 )
IrrSetNodePosition( PivotNode20, -8.8, 0.4, 0.0)
'-------------------------------------------------------

PivotNode30 = IrrAddEmptySceneNode
IrrSetNodePosition( PivotNode30, 0.0, 0.0, 0.0 )
CentreNode1 =  IrrAddSphereSceneNode( 1.0, 16 )
MeshTexture = IrrGetTexture("./media/gruen.png")
IrrSetNodeMaterialTexture( CentreNode1, MeshTexture, 0)
IrrAddChildToParent(CentreNode1, PivotNode30)
'-------------------------------------------------------

IrrAddChildToParent(PivotNode0,PivotNode )
IrrSetNodePosition( PivotNode0, 0.0,0.0, 0.0)
IrrSetNodeRotation( PivotNode0, 0.0,  90.0, 0.0)

IrrAddChildToParent(PivotNode30,PivotNode )
IrrSetNodePosition( PivotNode30, 0.0,0.0, 0.0)

IrrSetAmbientLight( 1,1,1 )

OurCamera = IrrAddCamera( 10,20,20, 0,0,0 )

While IrrRunning
    IrrBeginScene( 200,200,200 )

    CubeRotation = Timer * 100
    irrSetNodeRotation( PivotNode,  0.0,0.0,CubeRotation/4 )
    IrrSetNodeRotation( PivotNode1, 0.0,  CubeRotation, 0.0)
    IrrSetNodeRotation( PivotNode2, 0.0,  CubeRotation, 0.0)
    IrrSetNodeRotation( PivotNode10, 0.0,  CubeRotation, 0.0)
    IrrSetNodeRotation( PivotNode20, 0.0,  CubeRotation, 0.0)
   
    IrrDrawScene
 
    IrrEndScene
Wend

IrrStop

Last edited by super_castle on Apr 07, 2010 17:28, edited 3 times in total.
super_castle
Posts: 289
Joined: Oct 10, 2006 7:19

Postby super_castle » Apr 07, 2010 16:12

how to create a sphere with irrlicht ?

gruss
The Car
Posts: 102
Joined: Jul 08, 2005 19:02
Location: MN, USA
Contact:

Postby The Car » Apr 07, 2010 16:18

super_castle wrote:how to create a sphere with irrlicht ?

gruss


Search for "sphere" in IrrlichtWrapper.bi . You will see:

IrrAddSphereSceneNode
IrrAddSphereSceneMesh

Code: Select all

SceneNode = IrrAddSphereSceneNode (20,50)
IrrSetNodeMaterialTexture( SceneNode, MeshTexture, 0 )

agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Postby agamemnus » Apr 07, 2010 17:35

The Car wrote:Aga,

Then that's your problem. IrrLicht is a 3d engine, so the collision helpers they provide is for a 3d world. If you are only using 3D for display of actors in a 2d world then it is a waste of resources to use any type of 3d mesh/collision detection.


For the second scenario, is not a case of 2d collision, but 3d collision. The method Irrlicht has is not efficient for anything but a few meshes.

I think for the 2d collision scenario, the solution I want is I suppose do-able. However, for the 3d ray collision, it's a whole other ballgame... geometry. :(
The Car
Posts: 102
Joined: Jul 08, 2005 19:02
Location: MN, USA
Contact:

Postby The Car » Apr 07, 2010 18:16

agamemnus wrote:For the second scenario, is not a case of 2d collision, but 3d collision. The method Irrlicht has is not efficient for anything but a few meshes.


Oh, so for case 2, even though all characters are on the same plane, you can move and tilt the camera in 3d space.

Why can't you use getRayFromScreenCoordinates?

Like these guy did:

http://gamedevfan.blogspot.com/2009/10/irrlicht-how-to-get-mouse-pointer.html

http://z8.invisionfree.com/Game_Maker_forum/index.php?showtopic=1117&st=15

The functions already seem to be wrapped in the .bi ..

Once you have your ray, because everything is on the same plane, you can cheat and convert the ray to a 2d x,y position on your gamefield plane. Then you can use the simplified 2d triangle collision detection. This is assuming that your actors aren't really high, and you can get away with "click on ground" type detection instead of "click on tall smoke-stack" selection :)


Or did you try that already with bad results?
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Postby agamemnus » Apr 07, 2010 19:20

The Car wrote:Oh, so for case 2, even though all characters are on the same plane, you can move and tilt the camera in 3d space.

Why can't you use getRayFromScreenCoordinates?


I would have to use getSceneNodeAndCollisionPointFromRay. Again, as I said, it's inefficient because I have to test each mesh individually instead of testing for collision with an array or list of meshes.

I cannot just use collision with the polygon that the object is sitting on. Yes, that would have bad results.
The Car
Posts: 102
Joined: Jul 08, 2005 19:02
Location: MN, USA
Contact:

Postby The Car » Apr 07, 2010 19:52

aga wrote:I would have to use getSceneNodeAndCollisionPointFromRay. Again, as I said, it's inefficient because I have to test each mesh individually instead of testing for collision with an array or list of meshes.


I assume that all of your meshes are nodes that are part of a scene.

IrrLicht provides a function that does fast bounding box checking, then an accurate triangle checking here:

Code: Select all


      //! Perform a ray/box and ray/triangle collision check on a heirarchy of scene nodes.
      /** This checks all scene nodes under the specified one, first by ray/bounding
      box, and then by accurate ray/triangle collision, finding the nearest collision,
      and the scene node containg it.  It returns the node hit, and (via output
      parameters) the position of the collision, and the triangle that was hit.

      All scene nodes in the hierarchy tree under the specified node are checked. Only
      notes that are visible, with an ID that matches at least one bit in the supplied
      bitmask, and which have a triangle selector are considered as candidates for being hit.
      You do not have to build a meta triangle selector; the individual triangle selectors
      of each candidate scene node are used automatically.

      \param ray: Line with which collisions are tested.
      \param outCollisionPoint: If a collision is detected, this will contain the
      position of the nearest collision.
      \param outTriangle: If a collision is detected, this will contain the triangle
      with which the ray collided.
      \param idBitMask: Only scene nodes with an id which matches at least one of the
      bits contained in this mask will be tested. However, if this parameter is 0, then
      all nodes are checked.
      \param collisionRootNode: the scene node at which to begin checking. Only this
      node and its children will be checked. If you want to check the entire scene,
      pass 0, and the root scene node will be used (this is the default).
      \param noDebugObjects: when true, debug objects are not considered viable targets.
      Debug objects are scene nodes with IsDebugObject() = true.
      \return Returns the scene node containing the hit triangle nearest to ray.start.
      If no collision is detected, then 0 is returned. */
      virtual ISceneNode* getSceneNodeAndCollisionPointFromRay(
                        core::line3df ray,
                        core::vector3df & outCollisionPoint,
                        core::triangle3df & outTriangle,
                        s32 idBitMask = 0,
                        ISceneNode * collisionRootNode = 0,
                        bool noDebugObjects = false) = 0;
   };



The wrapper for this function seems to do what you want:

/* ----------------------------------------------------------------------------
the rootNode and its children are recursively tested and the nearest node whose
bounding box is hit by the ray then has its triangles tested in detail to find
an exact point of collision on a specific triangle. If such a collision is
found the node, the point of collision and the normal of that collision is
returned. For the collision to work the node must have had a triangle selector
created for it.
*/
' a ray is cast through the specified co-ordinates and the nearest node that has
' a collision selector object that is hit by the ray is returned along with the
' coordinate of the collision and the normal of the triangle that is hit. if no
' node is hit zero is returned for the object

declare sub IrrGetNodeAndCollisionPointFromRay CDECL alias "IrrGetNodeAndCollisionPointFromRay" ( _
byref vectorStart as IRR_VECTOR, _
byref vectorEnd as IRR_VECTOR, _
byref node as irr_node, _
byref posX as single, _
byref posY as single, _
byref posZ as single, _
byref normalX as single, _
byref normalY as single, _
byref normalZ as single, _
byval id as integer = 0, _
byval rootNode as irr_node = IRR_NO_OBJECT )
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Postby agamemnus » Apr 07, 2010 21:34

Well, yeah...

A bounding box check and then an accurate check after the bounding box would be a solution, I suppose, but not really the best..
Last edited by agamemnus on Apr 08, 2010 1:29, edited 1 time in total.
Frank Dodd
Posts: 444
Joined: Mar 10, 2006 19:22

Postby Frank Dodd » Apr 07, 2010 21:36

Hi guys work has been busy after the holidays so my replies will be a bit slow again.

Hello Siskenedge
Thanks for the update to the gravity that seams to do the job very well and is a big improvment to the scene realism, if I increased it too much I started to see some surface penetration though so I think this may very well be solved by a matter of scale too. Looks cool though.

Hello Super_castle
I'm glad you got your program working and it looks like a good representation of the quad robot in the picture. The only things I would suggest are a few more comments and renaming the PivotNode variables so that they describe the joints they represent better.

Hello Eric and Agamemnus
Thanks for picking up the baton on making some excellent suggestions for agamemnus's problems Eric. I think the comments in your earlier post were spot on and contained very good suggestions, especially in that a customised function for finding a specific triangle hit by a ray or even simply detecting a point in polygon which is very fast indeed.

The trouble for agamemnus's method of node picking based on triangles is that none of the calls return a triangle index at this point. Obviously digging down a little the triangle index is actually known. A function could be constructed to replicate the calls Irrlicht makes and in addition to the point of collision return a triangle additionally return the triangle in collision. I will have a think about this I'm just not sure it would be the best solution.

Agamemnus on your point about attaching a selector to multiple nodes I would accept the argument on its usefulness and will implement an additional command to allow this to be done.

A point of warning is that I would perform some stress tests immediately if you are thinking of having a thousand Scene Nodes this can seriously effect performance as all of the code for object set up is run a thousand times, often what is done instead is that the geometry for many identically shaded objects is batched together under a single object instead so that its set up as a single node.
Last edited by Frank Dodd on Jun 23, 2011 5:55, edited 1 time in total.
The Car
Posts: 102
Joined: Jul 08, 2005 19:02
Location: MN, USA
Contact:

Postby The Car » Apr 07, 2010 22:07

agamemnus wrote:Well, yeah...

A bounding box check and then an accurate check after the bounding box would be a solution, I suppose, but really the best..


Do you know a faster solution? Bounding box is incredibly fast, which leaves only a few nodes to perform a triangle test, unless you have an extreme camera angle (close to the ground, looking perpendicular to the ground).

It really depends on the limits you will impose on your camera, aga.

Can you tell us:

1. Average and Max number of actors/nodes in a scene.
2. Will the camera ever be positioned close to the ground with a low angle (i.e. not looking down, but looking straight ahead across the land).

What are the min/max camera angles in relation to the game plane?

I was envisioning a warcraft 3/ C&C camera type overhead view. Let me know if that is incorrect.

There are ways to optimize or use tricks that depend on the camera limits you impose, but you haven't really given us much info to work with.
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Postby agamemnus » Apr 08, 2010 1:37

The Car wrote:Do you know a faster solution? Bounding box is incredibly fast, which leaves only a few nodes to perform a triangle test, unless you have an extreme camera angle (close to the ground, looking perpendicular to the ground).


Well, yes, the extreme camera angle you mentioned will be possible but not likely. The bounding box method is not particularly fast when you are potentially selecting more than one item at the same time (ie, select and drag), though I suppose it will work and possibly not much slower than triangle-in-an-oct-tree picking, just not what I originally envisioned.

Can you tell us:
1. Average and Max number of actors/nodes in a scene.
2. Will the camera ever be positioned close to the ground with a low angle (i.e. not looking down, but looking straight ahead across the land).

What are the min/max camera angles in relation to the game plane?

In terms of the selectable objects, probably less than 1000.
Yes, it will be possible to position it looking straight ahead.
The min/max is 0 and 180 for both perpendicular rotational planes that are perpendicular to the game plane.

I was envisioning a warcraft 3/ C&C camera type overhead view. Let me know if that is incorrect.


That'll be the general view, but I give the player the freedom to move around at any angle, unless he tries to look under the map. (gotta hide those monsters somewhere)
super_castle
Posts: 289
Joined: Oct 10, 2006 7:19

Postby super_castle » Apr 09, 2010 6:36

how do you make a cylinder 80% transparent?

gruss
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Postby agamemnus » Apr 09, 2010 7:27

For colors (not sure about materials/textures), set the vertex color rgba value appropriately:

thecolor = rgba(r, g, b, 255*.8)
Use IrrSetMeshVertexSingleColor for this.

Code: Select all

' Copy only the color vertex data into the mesh -- a single color.
declare sub IrrSetMeshVertexSingleColor CDECL alias "IrrSetMeshVertexSingleColor" ( _
    byval mesh as irr_mesh, _
    byval frame as uinteger, _
    byval vertexColor as uinteger, _
    byval groupAmount as uinteger = 0, _
    byval startPos as uinteger ptr = 0, _
    byval endPos as uinteger ptr = 0, _
    byval meshbuffer as uinteger = 0 )




Frank Dodd:

2 points:

* I made a mistake, I think. For IrrSetMeshVertexColors et all, you need "startPos[i]; j <= endPos[i]" instead of "startPos[i]; j < endPos[i]"
* what is the difference between iFrame & iMeshbuffer? I know there is one, just not sure what exactly it is. Could you spell it out for me?
chung
Posts: 636
Joined: Jan 16, 2010 20:52
Location: France
Contact:

irrclose

Postby chung » Apr 09, 2010 9:34

could you add a irrclose command to your irrlichtwrapper

as

extern "C" __declspec(dllexport) void Irrclose(void)
{
device->closeDevice();
return ;
}

cause i use it in my game irr_chung , so it closes the current window , which is not done by irrstop , then i can restart irrlicht after it without ending the program ?

it tested it with a custom my_irr_wrapper.dll version but it works only on windows
super_castle
Posts: 289
Joined: Oct 10, 2006 7:19

Postby super_castle » Apr 09, 2010 14:09

hello, I do not get 80% transparent.

gruss

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 6 guests