Getting all points between two vectors

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.
Post Reply
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Getting all points between two vectors

Post by monkeycracks »

Ok, in example :

Vector3df A is at (0,0,0)
Vector3df B is at (100,0,100)

There is a hill between the two.

I tried creating a flystraight animator but it goes through the hill. What I want to do is make it go over the hill and not through it.

Collision Detection and Triangle Selectors wont' fix it.

Also I tried doing this and making a followspline

Code: Select all

     array<vector3df> points;

for(int x = eManager->selectedNode->getPosition().X; x <= newPos.X; x++)
{
 for(int y = eManager->selectedNode->getPosition().Y; y <= newPos.Y; y++)
  {
   for(int z = eManager->selectedNode->getPosition().Z; z <= newPos.Z; z++)
   {
   points.push_back(vector3df(x,y,z));
   }
  }
}
I didnt get the desired result, in fact it took a second to process and then didnt give the results I wanted.


Soo, any suggestions?
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Post by kburkhart84 »

The collision detection should work for this, but not using the flystraight animator. I'd recommend you either use a physics library and apply force to it towards where you want to go, or change the position manually by adding the vector that is the direction you want to go times the time passed this frame to the position vector. Then if you are using the collision system, it should work.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

FlyStraightAnimator ignores collision system. That's why I asked for it to be ignored. I don't think I should need a physics library just for this one function anyways... =\

Any other solutions?

I'm thinking the FollowSplineAnimator was the way to go, but my method of finding the points was messy or incorrect.
atomhamster
Posts: 13
Joined: Wed Feb 14, 2007 3:32 pm
Location: HH | Germany
Contact:

Post by atomhamster »

i think building a spline is pretty much work for this stuff and has to be done in a single step, before your object can start flying.

i would possibly try to add a collision response animator and move the object step by step each frame.

if i understand right, the collision animator cannot pass through your ground.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

FlyStraightAnimator ignores collision system.
Collision Detection and Triangle Selectors wont' fix it.
:|
Anyone else?
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

I'd make a function that works something like this:

Code: Select all

vectorlist list;

vector start;
vector end;
vector p;
triangle triangle;

list.add(start);

p,triangle=trace(start, end);
if(p!=end)
{
do
{
list.add(p);
p=followtriangleplaneuntilnotontriangle(triangle,p,normalize(end-p));
list.add(p);
p,triangle=trace(p,end);
}while(p!=end);
}
list.add(p);
return list;
Then i'd make my camera follow those vectors. kindof. it's just a rough idea. :P
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Post by kburkhart84 »

monkeycracks wrote:
FlyStraightAnimator ignores collision system.
Collision Detection and Triangle Selectors wont' fix it.
:|
Anyone else?
We understood that the first time, but why do you HAVE to use the flystraight animator to do it. What do you want, working code or use the animator. I prefer code that works, whether it uses that animator or not. I DO agree that it isn't necesary to use a physics engine, but if you were to use one on part of your project, it is easier to use it on the whole thing. I saw you posting on the IPhysics topic, that's why I mentioned the physics engine. Right now, the last time I had a camera move over terrain, I just used the method I explained, not the FlyStraightAnimator.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

What do you want, working code or use the animator. I prefer code that works, whether it uses that animator or not.
I'd take either if it worked. I've yet to see working code though.
change the position manually by adding the vector that is the direction you want to go times the time passed this frame to the position vector. Then if you are using the collision system, it should work.
What would the function be to find the direction vector?

vector3df direction = (newPos-oldPos).normalize(); ?

Then how would you set the node to move along that line, stopping it from going through the terrain, and stopping in a certain speed?
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Post by kburkhart84 »

If we are talking about the camera itself, then the Target or LookAt member is what you what. It seems that you want to move nodes instead though. You can look at the code in the FPS camera class that makes the movement. In their, it calculates a directional vector just like you are looking for. Then you add the vector times the delta time value( if using time-based movement), to the position of the node you are moving. Unless you get a low framerate, adding the triangle selector and collision animator like in the tutorial will result in what you are looking for. You may not think I know what I'm talking about because I don't post a code example, but I don't like to post code. Also, are you sure you are not going to want to implement a physics engine into your code. It in the end could meke things more simple and realistic at the same time.
Post Reply