A few easy questions.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Spawn
Posts: 9
Joined: Wed Feb 04, 2009 9:19 pm

A few easy questions.

Post by Spawn »

Hiya guys! I downloaded the Irrlicht engine a while ago but after opening the simple Hello World demo I got scared and ran off. I just picked it up again the other day and have been a drop down addict. I am a former/present Blender 3d developer (and a very popular one ;)) but I found that blender just isn't powerful enough for what I want. I have been working on a project "Fantasy Battlefield" it's a FPS similar to quake.

So anyway I opened up the Movement example and used that as a template for the character. Here are my questions:

Replaced the sphere with the Ninja that is set on idle, I set it so he moves forward when you press W he moves back on S and rotates on A and D. My question for this is when I move and rotate he keeps moving forward. I need the local rotation, maybe it's something simple but I know no C++ (I can only edit scripts) but I'm a fast learner. Here's my movement part of the script:

Code: Select all

		sphere node around respectively. */
		core::vector3df nodePosition = node->getPosition();
		core::vector3df nodeRotation = node->getRotation();

		if(receiver.IsKeyDown(irr::KEY_KEY_W))
			nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime;
			node->setFrameLoop(0,14);
			node->setAnimationSpeed(15);
		if(receiver.IsKeyDown(irr::KEY_KEY_S))
			nodePosition.Z -= MOVEMENT_SPEED * frameDeltaTime;

		if(receiver.IsKeyDown(irr::KEY_KEY_A))
			nodeRotation.Y -= 40 * frameDeltaTime;
		if(receiver.IsKeyDown(irr::KEY_KEY_D))
			nodeRotation.Y += 40 * frameDeltaTime;

		node->setPosition(nodePosition);
		node->setRotation(nodeRotation);
		node->setFrameLoop(206,250);
		node->setAnimationSpeed(15);
Now in that I'm also having trouble with the animation, I want it to play the walking animation when I press WASD.

Next question, how would I make a third person shooter styled camera? As the title of the game is Fantasy Battlefield, it is mostly weapons like axes and swords, with some guns/bows.

If I have more questions which I'm sure I will, I'll post them here.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

I will not help you with all questions but I can tell you that you definitely should learn at last basics of C++ and some math/physic. Especially vector math.

Here is function which will move your node into direction it is facing:

Code: Select all

void move(irr::scene::ISceneNode *node, //node to move
            irr::core::vector3df vel) //velocity vector
            // for example to move node 10 units forward use vector3df(0,0,10)
{
    irr::core::matrix4 m;
    m.setRotationDegrees(node->getRotation());
    m.transformVect(vel);
    node->setPosition(node->getPosition() + vel);
    node->updateAbsolutePosition();
}
Spawn
Posts: 9
Joined: Wed Feb 04, 2009 9:19 pm

Post by Spawn »

So where do I place that script? Why can't you answer all my questions =/ I've been helping others with scripts for a long time: http://blenderartists.org/forum/showthread.php?t=145117

Also is GTK radiant the best solution for map editing? I've been modding Quake with that program so I know it pretty well

Also I know "some" C++ (I rewrote some of blender 3d's code in C++) but I don't know very much.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You have to place the code (script is not the right term here) in your application and compile it. You have to call the function whenever you want to move the scene node.
All of your questions will not always be answered simply because it's fa better to learn C++ by reading books and tutorials, not trying to figure something complex like that from hints in a forum. That's not unfriendly, but the only viable way.
Spawn
Posts: 9
Joined: Wed Feb 04, 2009 9:19 pm

Post by Spawn »

See my way of learning is different than post people :cry: however there are some who learn like me. When I first wanted to learn python I never followed any tutorials, I just took premade scripts and picked them apart, removed lines to see what they were for, and copied lines. I prefer taking a script and picking it apart rather than trying to go from no knowledge to studying :x

Anyway I know how do add the camera and all FPS styled, but I want that camera to follow the person. I suppose the way to do It would be to get the orientation of the object (called rotation in C++) and apply it to the camera with each step? This seems like it would eat up CPU like crazy. Is there a way to dynamically parent objects?

EDIT: I don't understand =/ If I use this:

Code: Select all

		if(receiver.IsKeyDown(irr::KEY_KEY_W))
			void move(irr::scene::ISceneNode *node, //node to move 
					  irr::core::vector3df vel) //velocity vector 
            // for example to move node 10 units forward use vector3df(0,0,10) 
			{
			   irr::core::matrix4 m; 
			   m.setRotationDegrees(node->getRotation()); 
			   m.transformVect(vel); 
			   node->setPosition(node->getPosition() + vel); 
			   node->updateAbsolutePosition(); 
			}
it fails.. This is the log:

Code: Select all

------ Build started: Project: 04.Movement, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\irrlicht-1.5\examples\04.movement\main.cpp(244) : error C2601: 'move' : local function definitions are illegal
        c:\irrlicht-1.5\examples\04.movement\main.cpp(229): this line contains a '{' which has not yet been matched
Build log was saved at "file://c:\irrlicht-1.5\examples\04.Movement\Debug\BuildLog.htm"
04.Movement - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Spkka
Posts: 32
Joined: Fri Jan 02, 2009 8:30 am

Post by Spkka »

If you knew "some" basics you would understand what is wrong imo

http://www.digilife.be/quickreferences/ ... dition.pdf
cobra
Posts: 371
Joined: Fri Jan 23, 2009 2:56 am
Location: United States
Contact:

Post by cobra »

You can't declare a function inside of an "if" statement.

Do something more like this:

Code: Select all

void move(irr::scene::ISceneNode *node, //node to move
                 irr::core::vector3df vel) //velocity vector
// for example to move node 10 units forward use vector3df(0,0,10)
{
      irr::core::matrix4 m;
      m.setRotationDegrees(node->getRotation());
      m.transformVect(vel);
      node->setPosition(node->getPosition() + vel);
      node->updateAbsolutePosition();
} 


if(receiver.IsKeyDown(irr::KEY_KEY_W))
    move(node, vector);
That would execute the function that was defined before the "if" statement. Though make sure you define that function outside of the event handler and into somewhere else like before the "int main()" which is the main code. Do it before that and call it where you need it in the main code. :)
Josiah Hartzell
Image
wEEp
Posts: 70
Joined: Thu Nov 27, 2008 7:55 am

Re: A few easy questions.

Post by wEEp »

Spawn wrote: Next question, how would I make a third person shooter styled camera?

Code: Select all

scene::ISceneNode * nodeCamera = smgr->addCameraSceneNodeFPS(0, 100.0f, .1f); 
Just compare the cameras position with the position of the model you have and place the behind it ;)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Spawn wrote:Anyway I know how do add the camera and all FPS styled, but I want that camera to follow the person. I suppose the way to do It would be to get the orientation of the object (called rotation in C++) and apply it to the camera with each step? This seems like it would eat up CPU like crazy. Is there a way to dynamically parent objects?
It's not called rotation in C++, but in Irrlicht. What makes you think it will eat up CPU [time]? That makes absolutely no sense, because the camera will be rendered anyway, and changing a few floats each frame is definitely no problem.

If you prefer this very different learning style you should be aware that not many people will share it. So you have to accept that you'll get only links to tutorials instead of answers to really dumb C++ problems. You must not complain about this fact, as you freely chose to ignore this way.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Why can't you answer all my questions =/ I've been helping others with scripts for a long time:...
Because answering some of your questions equals writing C++/Irilicht tutorial or small book. There is no point doing so since tutorials and books like that were already written by more educated people than me. And I recommend you to get and read them.

You will not get far without understanding basics, believe me. And from your question I can see, you don't know even basic structure of C++ program.

That book Spkka was posting above is good point to start. I also did start by reading it.
Spawn
Posts: 9
Joined: Wed Feb 04, 2009 9:19 pm

Post by Spawn »

OK I figured some stuff out, I learn very quickly ;) I looked into the documentation included in irrlicht for some cool goodies like getParent and setParent (what I was looking for, for the camera)

Now, in IrrEdit, if I make special effects like a particle emmiter or something like that, when I import the irr into irrlicht will it have the emitter? Or will it need more code?

Also I'm a very accomplished game maker (http://youtube.com/mediachicken) those are just for my contest entry, I have greater examples like real time portal guns with mirrors and such. Just give me time and I'll learn =)


EDIT:: Ok, I have another problem, the worse part about this is that the compiler doesn't print up errors =X here's what I'm doing:

This code is placed before the main() function

Code: Select all

void move(irr::scene::ISceneNode *node, //node to move 
                 irr::core::vector3df vel) //velocity vector 
// for example to move node 10 units forward use vector3df(0,0,10) 
{ 
      irr::core::matrix4 m; 
      m.setRotationDegrees(node->getRotation()); 
      m.transformVect(vel); 
      node->setPosition(node->getPosition() + vel); 
      node->updateAbsolutePosition(); 
} 

and this is the movement one:

Code: Select all

		if(receiver.IsKeyDown(irr::KEY_KEY_W))
			move(node,core::vector3df(0,0,100));
it compiles fine, but when I play it I press W and I don't move =/
Spawn
Posts: 9
Joined: Wed Feb 04, 2009 9:19 pm

Post by Spawn »

Anyone know the answer?
wEEp
Posts: 70
Joined: Thu Nov 27, 2008 7:55 am

Post by wEEp »

Spawn wrote:Anyone know the answer?
I guess that we need more code for that ( for example how u draw this )

You can try that code to move summit

Code: Select all

u32 then = device->getTimer()->getTime(); 

   // This is the movemen speed in units per second. 
   const f32 MOVEMENT_SPEED = 5.f; 
....
....
....
 while(device->run()) 
   { 
     
      // Work out a frame delta time. 
      const u32 now = device->getTimer()->getTime(); 
      const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds 


if(receiver.IsKeyDown(irr::KEY_KEY_S)) 
         nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime; 

nodeCamera->setPosition(nodePosition); 
      then = now; 

Cheers
Spawn
Posts: 9
Joined: Wed Feb 04, 2009 9:19 pm

Post by Spawn »

Ok, I'm not on my windows machine so can't test it out now, but just looking over that code... that doesn't look like it will move the character on his local orientation, it looks to me like that may be a 3p camera? I understand most, except why you imported the time?
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

To get a framerate independet movement.

If you add 1 unit to a position every frame, the player with the high end monster machine will run twice as fast as the one with the gameboy.

If you add 1 unit * time since last frame every frame, both players will run with the same speed.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Post Reply