Jump to content
Sign in to follow this  
Yuval

Scope adjustment

Recommended Posts

I am currently trying to make my own scope. I edited a p3d paths to my .pbo and moved all files to the neccessary paths on my PBO, all I need to do now is to edit the config file..

It's not a problem to edit the .paa but I want to add some things to the scope such as a built in rangefinder like the TWS has.

If you could teach me how to do it (because I looked at the ui_f and couldn't understand anything) it will be awesome.

Also, I don't know if it's needed but incase I'm basing my scope on the LRPS - do I need to edit anything so zeroing will fit regular 7.62x51 caliber? (I am using this scope on a custom wepaon, but the ammo of it is the B_762x51 , stock ball)

Thanks for the helpers!

Share this post


Link to post
Share on other sites

It's not a problem to edit the .paa but I want to add some things to the scope such as a built in rangefinder like the TWS has.

If you could teach me how to do it (because I looked at the ui_f and couldn't understand anything) it will be awesome.

I did this to make a custom LRPS scope with the bearing/azimuth that the scope is pointing displayed in either degrees or milliradians. I will release this scope shortly. You can see a video of it at youtube video cDpMbSCfiGU.

It's not hard to get the bearing of the weapon and display it with a custom RscText display that's updated every 0.3-0.5 seconds. But finding the range to the observed position is MUCH more difficult. I spent months trying to figure out this problem, and my own custom solutions were not nearly as good as the BIS solutions. The problem with my solutions is that they would almost always "see through" buildings and other objects. Even after I took that into account, the best I could do was estimate the distance to the center of a large object (like a hangar), not the face of the object nearest to me.

Here's some of the code I used for finding the distance:

fn_GetRange.sqf

/*
File: fn_GetRange.sqf
Author: Michael Zehnpfennig, aka mjblay, aka Zehn

Description:
Find range from a player's eyePos to intersection of the camera direction vector
(obtained by accessing the Z-axis in the array retured by positionCameraToWorld)
with any object.  If no such intersection exists within the player's viewDistance
then return -1.

Parameter(s): None

Returns:
	SCALAR - range in meters

*/

private ["_detectorPos", "_endOfSightLine", "_sightLineObjects", "_range", "_detectorObjects", "_Ubound"];

// --------------------------------------------------------------------
// SIGHT-LINE OBJECTS METHOD
// --------------------------------------------------------------------
// This method uses the lineIntersectsWith command to collect an array
// of objects with which the line between the player's eye position and
// a point (viewDistance + 1000m) away down the player's sight-line.
// the objects in the array are ordered in from farthest to nearest, so
// taking the last one and grabbing its position allows for calculation
// of the distance between it and the player.  This method has two flaws:
// first, large objects like an airport hangar may intersect the
// sight-line several meters away from their center, but getting their
// position returns the center of the object.  The second is that this will
// detect objects along the sight-line on the other side of terrain and
// return their distances.

_rangeSLO = 0; // range from sight line objects
_endOfSightLine = positionCameraToWorld [0, 0, viewDistance + 1000];
_sightLineObjects = lineIntersectsWith [eyePos player, _endOfSightLine, player, objNull, true];

if ((count _sightLineObjects) > 0) then
{
_Ubound = count _sightLineObjects;
_rangeSLO = (eyePos player) distance (getPosATL (_sightLineObjects select (_Ubound - 1)));
};

// --------------------------------------------------------------------
// SCREEN-TO-WORLD METHOD
// --------------------------------------------------------------------
// This method seems less "authentic" but it may use less resources,
// and I may substitute it with the for-loop near-objects method below

// _range = (eyePos player) distance screenToWorld [0.5,0.5];
// if ((_range > viewDistance) || (_range > 4000)) exitWith {_range = -1;};

// --------------------------------------------------------------------
// NEAR-OBJECTS METHOD (inspired by ArmA 2 ACE)
// --------------------------------------------------------------------
// This method takes the weapon direction vector and marches down that
// vector starting 10 m from its origin at the player's weapon/binoc,
// taking 1m steps.  At each step, it assesses for objects (any kind of
// object -- house, plant, unit, etc) within 1 meter and if an object is
// found, it exits the loop and _rangeNeO is no longer increased.  This
// also happens if its height above terrain level reaches zero,
// indicating a collision with land.  Unfortunately, this method seems
// particularly bad at detecting houses and buildings, so I had to add
// the sight-line objects method above. If neither of the above happens,
// the weapon vector is probably pointed toward the sky, so return -1.

_rangeNeO = 0; // range from near objects
_detectorPos = [0, 0, 0];
for [{_rangeNeO = 10}, {(_rangeNeO < (viewDistance + 1000))}, {_rangeNeO = _rangeNeO + 1}] do
{
_detectorPos = positionCameraToWorld [0, 0, _rangeNeO];
_detectorObjects = _detectorPos nearObjects 1;

if (((_detectorPos select 2) < 0) || ((count _detectorObjects) > 0)) exitWith {};
if (_rangeNeO > viewDistance) exitWith
{
	_rangeNeO = -1;
};
};

// Unfortunately, it is necessary to calculate range using both the
// sight-line objects method and the near-objects method. I tried
// putting an if-then loop above to bypass the near-object's for loop
// if objects were found using the sight-line objects method, but
// occasionally when pointing at terrain only, an unexpectedly high
// range would be displayed indicating that an object was in the line
// of sight, but on the other side of a hill.  A way to toss out that
// result would be to use the terrainIntersects command to check if
// terrain intersected the line between the closes object and the
// player's eye position, but that command is reportedly very CPU
// intensive so I avoided it.  Instead, I get both ranges above and
// use the logic below to choose the most appropriate range.

if (((count _sightLineObjects) == 0) || (_rangeNeO == -1)) then
{
// either no sight-line objects were found or no near objects were found;
// either way, return the result of the near objects method
_range = _rangeNeO;
}
else
{
if ((_rangeNeO < _rangeSLO) && (_rangeNeO > 0)) then
{
	// sight-line objects were found, but their range was greater
	// than that of the near-objects/terrain intersection found
	// using the near-objects method so return its range
	_range = _rangeNeO;
}
else
{
	// sight-line objects were found, and their range was lesser
	// than that of the near-objects/terrain intersection found
	// using the near-objects method so return the sight-line
	// object's range
	_range = _rangeSLO;
};
};

// return the appropriate range
_range

-Zehn

---------- Post added at 01:11 ---------- Previous post was at 01:06 ----------

Since it's my first post here, it wouldn't let me attach the video. Here it is:

-Zehn

Share this post


Link to post
Share on other sites

Actually, thinking back to it, I found that the hardest part about putting the bearing in the scope was finding a way to be sure the RscText displayed every time your soldier was looking through the scope. Unfortunately, there is no event handler that fires when you look through the scope. You could attach an initialization event handler to the soldier/unit and have it check the cameraView every 0.5 seconds to see if it changed to Gunner, but I worried that would be really CPU intensive.

Instead, I just developed a pretty comprehensive key press handler and attached it to the main display using the keydown event handler. This way, every time a key is pressed, it checks if the key is the optics key and if it is, it displays the RscText and starts a while loop that updates it. The while loop only runs while cameraView == "GUNNER" (since the camera view changes when you are not looking through the scope anymore) and after the while-loop exits, it hides the custom RscText again.

Anyone have any input on these two methods or know of any better way to start a while-loop only when your solider is looking through the scope?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×