Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!   (85,056 visits to this link)

    2. News

    1. GTA Online

      1. Find Lobbies & Players
      2. Guides & Strategies
      3. Vehicles
      4. Content Creator
      5. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption 2

    2. Red Dead Redemption

    3. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Forum Support

    2. Site Suggestions

nixolas1

Help with Portal Vector Math

Recommended Posts

nixolas1

Hey guys, I'm making a portal mod for GTA IV/EFLC, and its quite done and working somewhat nicely. But I'm having some problems with the math behind the rotation of the vehicle speed vectors and vehicle rotations/quaternions.

 

Are there anyone in here with some good math skills?

What i am doing is rotating the speed vector according to the angle between the two portals, both in the 2D axis and the 3D axis.

Here is the code in question, and ill comment along the way. Ask any questions if you dont understand something.

 

 

Vector3 v;     	f32 he, rot, rotz,hx,hy,sr,cr,srz,crz,x2,y2,z2;     	GetCarSpeedVector(veh, &v, false);     	     	//teleport car to other portal     	SetCarCoordinates(veh,p[u],p[u+1],p[u+2]);     	//speed vect rot, p[5] is portal1 x rot, p[11] is portal2 xrot, p3=port1 z rot, p9=p2 zrot. PIX=pi/180.//rot = the difference + 180 degrees between the two portals     	rot=(abs(p[5]-p[11])+180)*PIX;     	rotz=(abs(p[3]-p[9])+180)*PIX;     	sr=sin(rot);     	cr=cos(rot);     	srz=sin(rotz);     	crz=cos(rotz);     	//z axis rot 2d, works at times, sometimes gives 90 deg wrong, sometimes 180.     	x2=(v.X*cr-v.Y*sr);     	y2=(v.X*sr+v.Y*cr);     	z2=v.Z;     	//x axis rot, veh is supposed to fly up if the car drives horizontally into a portal on a wall, and the other portal is on the floor(facing upwards). //it is also supposed to fly horizontally if car falls into portal on floor to portal on wall, in the direction the portal on wall is heading.//right now, some of that works, ish. if it falls on a portal on floor to another on floor, it correctly flies up again, and if the portal is on a wall it(mostly) flies up (correctly).// but vertical to horizontal does not work. it goes horizontally, but not in the direction the portal is headed.     	x3=(x2*abs(crz)-z2*srz);	     	y3=(y2*abs(crz)-z2*srz);     	z3=(sqrt(v.X*v.X+v.Y*v.Y)*-abs(srz)+z2*crz);     	//car rotation, which has to be partially rewritten, using quaternion to set the proper rotation of the car after it has been through the portal. (Quaternions are hard!)     	GetCarHeading(veh, &he);     	hx=cos(he*PIX);     	hy=sin(he*PIX);     	GetHeadingFromVector2D(hx*cr-hy*sr,hx*sr+hy*cr, &hed);     	hed+=90;     	SetCarHeading(veh, hed);     	Wait(1);     	ApplyForceToCar(veh, 3, x3, y3, z3, 0, 0, 0, 0, 0, 0, 1);

 

 

What am I doing wrong? Do you have any tips on what I can do?

 

If you are interested and show that you can contribute, I might let you in on the project, and I'll give you credits anyway if you contribute.

 

Cheers! A nice pic: http://puu.sh/39Lst

Edited by nixolas1

Share this post


Link to post
Share on other sites
julionib

math kills me always smile.gif

 

let me see if i understood, the actual main problem is an vertical portal on wall teleporting to a horizontal portal on ground right? the car enters with 0 pitch and should get out with 90 degrees pitch? in this case, you know what is the direction of each portal? like for example, portal on wall should always pull against street (direction: from wall to street/pavement), portal on ground should pull up (direction: from ground to ground + vector3.worldUp)

 

this can be a very nice mod

Share this post


Link to post
Share on other sites
nixolas1

Yes, the portal object rotations are correct, and heading the correct way. It's the math that is wrong somehow.

Share this post


Link to post
Share on other sites
julionib

right, so if you have the direction vector of the portal you can just push car in that direction after teleport, what you need is just change pitch to something like 80 degrees

 

how are you detecting the wall?

Share this post


Link to post
Share on other sites
nixolas1

the portals are rotated so they align with the walls/floor, just like the sticky bombs. So i have the portal rotation & position. But I can't just set the vehicle speed vector and veh rotation in the direction of the portal, I have to take into account the speed vector and rot the car had before it entered the portal. So what youre saying about just rotating it 80 degrees does not apply here, because the rotation needs to be based on what it was before.

 

The wall detection and wall angle detection is using GetGroundZAtCoordinates, loops and math. You'll see it when i release the mod, as the source will be available, but its basicly trigonometry and stuff.

 

What I need help with is the math here, I think im doing the part of getting the rotations right.

Share this post


Link to post
Share on other sites
julionib

right, i will try some code to test what i sid because its theory hehe

Share this post


Link to post
Share on other sites
julionib

send me your email and i send to you the code that shows what i was trying to explain

Share this post


Link to post
Share on other sites
nixolas1

I figured out how to do it smile.gif

By attaching the car to the object so it achieves the same rotation as it, but with the offsets it had when it entered the first portal!

 

 

Vector3 v;     	f32 vx,vy,vz,fx,fy,fz,sp=95.0f;     	f32 spe;     	GetCarSpeed(veh, &spe);     	GetCarSpeedVector(veh, &v, true);     	GetCarPitch(veh, &vx);     	GetCarRoll(veh, &vz);     	GetCarHeading(veh, &vy);	     	//set correct rotation and speed dir of car     	fx=(-p[c+3]+vx)*PIX; //pitch     	fy=(vy-p[c+5]+180)*PIX; //heading     	fz=0; //roll     	AttachCarToObject(veh, po[a], 0,0,0,0, fx, fy, fz);     	Wait(0);     	DetachCar(veh);     	SetCarCoordinates(veh,p[u],p[u+1],p[u+2]);     	ApplyForceToCar(veh, 3, vx/sp, vy/sp, vz/sp, 0, 0, 0, 0, 1, 1, 1);     	

 

Share this post


Link to post
Share on other sites
julionib

what i did was put car in next portal and use the portal direction to set as new direction, ignoring the entering angle in the first portal

Share this post


Link to post
Share on other sites
nixolas1

Yeah, thats the simple way of doing it, which works, but if you want real portal-physics, you need to take the rot offset between the car and first portal into account.

Share this post


Link to post
Share on other sites
julionib

right, like entering in 45 degree must exit in 45 degree or something like that?

Share this post


Link to post
Share on other sites
nixolas1

Well, basicly yes. But some modifications/simplifications have to be made because GTA has cars and Portal does not. For example, if you drive a car through a horizontal portal (on the ground), to a portal which is on a wall, you will have too much speed to be able to "fall" DOWN into that portal, and you would (realisticly) drive straight over it. But thats no fun! So I'll have to make some special cases with special rules, so that, in this example, the car will go horizontally into the portal on the ground, and horizontally out of the portal on the wall, even though its not how it is supposed to be.

 

Quite interesting stuff to be making! biggrin.gif

And its coming along quite nicely.

Share this post


Link to post
Share on other sites
Frank.s

Just posting to say i'm looking forward to seeing this mod. icon14.gif

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.