"2d" movement based on camera rotation ( Math &

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
TekniX
Posts: 24
Joined: Tue May 01, 2007 12:39 pm

Post by TekniX »

Hey Kazymjir , thanks a buch, did a quick search for it but didnt find anything usable :oops: . I think I have to recompile irrlicht for this, but I have to do this at home, so I wont really be able to tell you if it worked until tonight ( which is in aprox. 3.5 / 4 hours ) . Thanks for your help man :) until now I have this ( which fails because of the vector4d )

Code: Select all


					core::vector4df a = (nodePos.X,nodePos.Y,nodePos.Z,1);
					core::vector3df temp = intersectPlane.Normal;
					core::vector4df pRot = (temp.X,temp.Y,temp.Z,1);
					core::matrix4 mRot;
					mRot.setRotationDegrees(pRot);
					core::matrix4 iRot;
					if(!mRot.getInverse(iRot))
						cout << "\n smthing wrong cldnt get inverse rot matrix";
					core::vector4df t = (1,mOffY,mOffX,1);
					core::vector4df newPos = mRot * t * iRot * a;
					
@Lonesome Ducky : Ok, I didnt quite understand why we do this at a distance from 1, because the node is probably going to be a lot further away, but ill wait and see maybe I understand later :). Thank you !

Regards

TekniX
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

The problem happened to be that I didn't divide by the screen dimensions like I should have:

Code: Select all

vector3df get3DCameraPlanePos(ICameraSceneNode* camera, position2di position, dimension2di screenSize) {
   vector2df offPos(((screenSize.Width-position.X)/(float)screenSize.Width)*2.0f-1.0f,-(((screenSize.Height-position.Y)/(float)screenSize.Height)*2.0f-1.0f));
   vector3df center = camera->getAbsolutePosition()+camera->getAbsoluteTransformation().getRotationDegrees().rotationToDirection();
   vector3df dirX = (camera->getViewFrustum()->getFarRightUp()-camera->getViewFrustum()->getFarLeftUp()).normalize();
   vector3df dirY = (camera->getViewFrustum()->getFarRightDown()-camera->getViewFrustum()->getFarRightUp()).normalize();
   return center+dirX*offPos.X-dirY*offPos.Y;
}
The distance of 1 is used so that the screen's edges are at -1 and 1. You can find the direction between the camera and the position returned, normalize it, and multiply by the distance away you want it to be.
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Not sure if this is what you're looking for (probably not.. but worth a try), but try/look at this:

"RTS/simulation overhead camera function."
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=43470
TekniX
Posts: 24
Joined: Tue May 01, 2007 12:39 pm

Post by TekniX »

@Agamemnus : Not really but I had a look at it ;) .

Actually I solved this problem for now. Later on in development I will come back and solve it the right way ;) . Thank you all for now :)

Greetings TekniX
gerdb
Posts: 194
Joined: Wed Dec 02, 2009 8:21 pm
Location: Dresden, Germany

Post by gerdb »

@author

stefbuet said all you need to know

Initial camera vectors, when there was no rotation and positioning

RIGHT ( 1,0,0 )
UP ( 0,1,0 )
LOOKAT ( 0,0,1 )

as you can see, its the identitymatrix

the basis vectors of your plane are RIGHT and UP

so if the camera is rotated or translated these vectors are the same way
transformed too.

View = Rotation*Translate*World

--> new basis vectors of plane, of course in world system coords
RIGHT' = View * RIGHT
UP' = View * UP

cya
TekniX
Posts: 24
Joined: Tue May 01, 2007 12:39 pm

ok

Post by TekniX »

I think I have it now ;)

thank you a lot guys :) !

Greetings

TekniX
Post Reply