jstq Posted May 1, 2013 Share Posted May 1, 2013 black 1 is player's car red 2 is player's car direction green 3 is camera direction gray 4 is on screen area, expanding to left and red 5 is not on screen area I need code which will return true for any car in area 5. Method isOnScreen often returns true for not on screen cars, so its bad for me. And some question - how much foots is screen width while player is in car/not in car for 1920 pixels? How to get foots count for maximum view distance? Whats the fastest way to know, is really car displayed on screen or not? (isOnScreen will return true if between car and player is a building or wall). Link to comment Share on other sites More sharing options...
sextitsboobsyeah Posted May 1, 2013 Share Posted May 1, 2013 (edited) if u disregard the z value from a vector3 point, u can calculate this line with the car's position being the focus at a 0, 0 coordiante then u check car's relationship to the line, disregard what it says about sunlight i just went to google images for parabula and fount that and it looked like your picture u know vector math? Edited May 1, 2013 by sextitsboobsyeah Link to comment Share on other sites More sharing options...
jstq Posted May 1, 2013 Author Share Posted May 1, 2013 no im noob in math :< ill try to figure out some code in hope for some good method, maybe someone already did that b4. vector3.z its height? Link to comment Share on other sites More sharing options...
sextitsboobsyeah Posted May 1, 2013 Share Posted May 1, 2013 (edited) what i posted isnt hard if u read a little and u will learn something useful, think of the car being at 0, 0 on that graph and the focus point would be 0, 0... by getting a car's offset position u can use the offset value as the values u process with the formula... maybe if i get bored ill write it for u a = distance from car to camera then just plug in x values and u get your y values from formula then those x and y's u use getoffsetposition and u can draw that line, then u check other cars distance to any point on the line Edited May 1, 2013 by sextitsboobsyeah Link to comment Share on other sites More sharing options...
jstq Posted May 1, 2013 Author Share Posted May 1, 2013 for me car position is at focus point... sorry my natural language isnt english, so i misunderstand your words a little (like when i ask bout z value - i didnt know what word disregard means, i thought that you use Z value in calculations, but then i googled its value ) Link to comment Share on other sites More sharing options...
sextitsboobsyeah Posted May 1, 2013 Share Posted May 1, 2013 (edited) lol... i will draw a picture and try to explain that way... one moment, what language u speak? give me few minutes i have to google stuff, i dont use this type of math normally i will draw a nice picture with some code to explain Edited May 1, 2013 by sextitsboobsyeah Link to comment Share on other sites More sharing options...
jstq Posted May 1, 2013 Author Share Posted May 1, 2013 (edited) and actually i didnt understand what offset is. this method is in vehicle class, not in position, and returns some world coordinates for some vector. but how that coordinates calculated, what are they means? some position in some vector3 direction from come car position? my language is russian Edited May 1, 2013 by jstq Link to comment Share on other sites More sharing options...
sextitsboobsyeah Posted May 1, 2013 Share Posted May 1, 2013 (edited) ah ok, i know some spanish, nm lol take this example: vehicle.Position == vehicle.GetOffsetPosition(new Vector3(0, 0, 0)) is true so a point in front of car or behind u change y value vehicle.GetOffsetPosition(new Vector3(0, 5, 0)) is about 5 meters in front of car so a point to left or right u change x value vehicle.GetOffsetPosition(new Vector3(5, 0, 0)) is about 5 meters to right and to get a point behind and to the left vehicle.GetOffsetPosition(new Vector3(-5, -5, 0)) vehicle.GetOffsetPosition(new Vector3(left/right, front/back, up/down)) now because u are using offset positions and not world positions, u can create your picture using a horizontal parabola formula, i dont use normally but i understand how these things work so i am studying a little and i will make a picture to explain in your picture i would say the point for that offset is something like... vehicle.GetOffsetPosition(new Vector3(7.5, 2.6, 0)), something like that, just a guess but u can use algebra to calculate any point relative to your focus point... being the car this is cool, i just found... http://www.wolframalpha.com/input/?i=plot+...-+3%29^2+%3D+11 Edited May 1, 2013 by sextitsboobsyeah Link to comment Share on other sites More sharing options...
jstq Posted May 1, 2013 Author Share Posted May 1, 2013 but what if i need offset in direction where player looks (camera direction)? is that correct? Player.Vehicle.GetOffsetPosition(Player.Direction*150);//150 or whatever range of view this is and player.position is verctor from zero point to player position? Link to comment Share on other sites More sharing options...
sextitsboobsyeah Posted May 1, 2013 Share Posted May 1, 2013 (edited) Player.Vehicle.GetOffsetPosition(Player.Position + Player.Direction*150); fixed, also i dont understand what u mean for this, u need to study vector math to understand how to calculate stuff with vectors, this is cool though i like to learn this stuff and now im reading about parabolas lol ill try to post an example tomorrow Edited May 1, 2013 by sextitsboobsyeah Link to comment Share on other sites More sharing options...
jstq Posted May 1, 2013 Author Share Posted May 1, 2013 i just dint get why that offset function is in vehicle class. If we have player position and some vector, we do not need any vehicle to calculate offset position imo. Or we need, cus that function is in vehicle class? In other way, what this function takes from vehicle exemplar to calculate offset? If it gets vehicle position, why we need player.position? Link to comment Share on other sites More sharing options...
sextitsboobsyeah Posted May 2, 2013 Share Posted May 2, 2013 (edited) i just dint get why that offset function is in vehicle class. If we have player position and some vector, we do not need any vehicle to calculate offset position imo. Or we need, cus that function is in vehicle class? In other way, what this function takes from vehicle exemplar to calculate offset? If it gets vehicle position, why we need player.position? it uses a native function to get the offset of a vehicle, it is what r* created, not sure why they didnt make one to get offsets from peds this is what the code inside that method is: <Module>.Scripting.?A0x8c04474b.GetOffsetFromCarInWorldCoords(this.pHandle, Offset.X, Offset.Y, Offset.Z, &x, &y, &z); GetOffsetFromCarInWorldCoords was created by rockstar so u can see the method is specific to cars only, so it couldnt be applied to a ped unless u do some reversing and make the method think a ped is a car... that's another story, im sure it is possible though... maybe there is an offset for ped native?? also im not understanding your question but u use offset from car so u dont have to deal with world coordinates and the direction of your car will always be looking up on the y axis and the x axis will always be to the left and right of the car what u need to do is use a horizontal parabola formula opening to the right and position it to the left of your car, think of your car on a x and y axis, the car is at 0, 0 Example: namespace Parabola{ using System; using System.Drawing; using System.Windows.Forms; using System.Collections.Generic; using GTA; public class Main : Script { Blip[] blips; public Main() { BindKey(Keys.B, Draw); blips = new Blip[61]; } private void Draw() { foreach (Blip blip in blips) if (Game.Exists(blip)) blip.Delete(); if (!Game.LocalPlayer.Character.isInVehicle()) return; for (float y = -30; y < 31; y++) blips[(int)y + 30] = Blip.AddBlip(Game.LocalPlayer.Character.CurrentVehicle.GetOffsetPosition(new Vector3(xVal(y, -5, 0, 5), y, 0))); foreach (Blip blip in blips) if (Game.Exists(blip)) blip.Scale = 0.5f; } private float xVal(float y, float h, float k, float a) { float x = 0; x = 1 / (4 * a) * ((y - k) * (y - k)) + h; return x; } }} last thing u must do is determine if another car is inside or outside this parabola, the shape of the parabola can be modified by messing with the "a" value, eventually u will position the camera at the vertex and the car will be the focus point at (0, 0)... here i made vertex at (-5, 0) so a = 5 since that is how far vertex is from focus so u would do someting like... camera.Position = vehicle.GetOffsetPosition(new Vetcor3(-5, 0, 0)) Edited May 2, 2013 by sextitsboobsyeah Link to comment Share on other sites More sharing options...
jstq Posted May 8, 2013 Author Share Posted May 8, 2013 (edited) this parabola position is related only by car position, not by camera position GTA.Game.CurrentCamera.Direction - this is camera direction, now i need to learn some vector math and maybe ill figure out something Edited May 8, 2013 by jstq Link to comment Share on other sites More sharing options...
blowjobcumpussy Posted May 10, 2013 Share Posted May 10, 2013 (edited) but the camera's position is relative to the car so the parabola is also relative to the camera btw valid a values when camera is positioned at vertex would be: a = Game.CurrentCamera.Position.DistanceTo2D(vehicle.Position); Edited May 10, 2013 by blowjobcumpussy Link to comment Share on other sites More sharing options...
blowjobcumpussy Posted May 10, 2013 Share Posted May 10, 2013 (edited) Player.Position + Player.Direction*150; what i wrote before i dont think was correct im just noticing, i fixed it now in quote to what i think u meant to write earlier this is how it works, u start at your player, now your direction represents a length of 1 in the game so it's distance is 1f in the world... understand? so if u have this direction and make it's range 150 times bigger, you can use that value to travel from any point 150f in the direction player is looking Direction Example: let's say u need a direction from ped to another ped Vector3.Normalize method takes a vector3 value and converts it into a length of 1... example: Vector3.Normalize(Player.Character.Direction * 150) == Player.Character.Direction //this is true this is how a Vector3's length is calculated: (x^2 + y^2 + z^2)^0.5 or float vector3Length = (float)Math.Sqrt((vector3.X * vector3.X) + (vector3.Y * vector3.Y) + (vector3.Z * vector3.Z)); I explain these because they are important and can help u to understand how to calculate directions or to get a direction from one object to another. For directions from one object to another u simply subtract the position of the object, that the direction originates from, from the position of the object you are looking at. That vector3 value resulting from the subtraction tells u the direction but it is more that 1 unit long so u normalize it, this example below gives u direction from ped1 to ped2: Vector3 directironFromPed1ToPed2 = Vector3.Normalize(ped2.Position - ped1.Position) so normalizing the vector3 in this example is actually doing this: Vecto3 vector3 = ped2.Position - ped1.Position;float normalizeMultiplier = 1 / vector3.Length();//see length code aboveVector3 directironFromPed1ToPed2 = new Vector3(vector3.X * normalizeMultiplier, vector3.Y * normalizeMultiplier, vector3.Z * normalizeMultiplier); this will return true just to illustrate it ped2.Position == Vector3.Normalize(ped2.Position - ped1.Position) * ped1.Position.DistanceTo(ped2.Position) + ped1.Position so i think this what u were originally trying to write, hope that makes sense with google translate Edited May 11, 2013 by blowjobcumpussy Link to comment Share on other sites More sharing options...
nixolas1 Posted June 6, 2013 Share Posted June 6, 2013 very nice math and all, but it still dosnt fix the problem of vehicles being "on screen" even if behind buildings... i would run a (c++) if(isCarOnScreen(thatcar) && inLineOfSight(mycar, thatcar)){do stuff}where inLineOfSight is something like:bool Inlineofsight(car1, car2){getcarcoods(car1, x,y,z);getcarcoods(car2, xx,yy,zz);Getgamecam(&gcam);getCamPosition(gcam, cx,cy,cz);f32 g=0;GetGroundZFor3DCoord(xx, yy, zz+1000,&g);while(g<=cz+20 && d>1){ //if ground position is lower than cam, there is no obstacle.getdistance3d(x,y,z,xx,yy,zz,&d);xx+=(x-xx)/d; //move check position closer to your caryy+=(y-yy)/d;zz+=(z-zz)/d;GetGroundZFor3DCoord(xx, yy, zz+1000,&g);}if(g>cz+20)return false;return true;} sorry about the incredibly messy code, but im incredibly tired. good luck understanding it, but i really believe it could work. good night (3am) Link to comment Share on other sites More sharing options...
hellothereyoupieceofshit Posted June 6, 2013 Share Posted June 6, 2013 (edited) very nice math and all, but it still dosnt fix the problem of vehicles being "on screen" even if behind buildings... i would run a (c++) if(isCarOnScreen(thatcar) && inLineOfSight(mycar, thatcar)){do stuff}where inLineOfSight is something like:bool Inlineofsight(car1, car2){getcarcoods(car1, x,y,z);getcarcoods(car2, xx,yy,zz);Getgamecam(&gcam);getCamPosition(gcam, cx,cy,cz);f32 g=0;GetGroundZFor3DCoord(xx, yy, zz+1000,&g);while(g<=cz+20 && d>1){ //if ground position is lower than cam, there is no obstacle.getdistance3d(x,y,z,xx,yy,zz,&d);xx+=(x-xx)/d; //move check position closer to your caryy+=(y-yy)/d;zz+=(z-zz)/d;GetGroundZFor3DCoord(xx, yy, zz+1000,&g);}if(g>cz+20)return false;return true;} sorry about the incredibly messy code, but im incredibly tired. good luck understanding it, but i really believe it could work. good night (3am) hi yes hello, welcome to jitsuin's forums, i hope you enjoy your stay... it was only to provide ideas, i wasnt gonna write the thing lol but thanks and yes i am the same person Edited June 6, 2013 by hellothereyoupieceofshit Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now