[Math problem] Need fit markers on the edge of minimap

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Post Reply
User avatar
Posts: 1899
Joined: 25 Aug 2011, 21:45
Location: Poland

[Math problem] Need fit markers on the edge of minimap

Post by Dommy » 21 Jun 2016, 14:41

Since I'm dumb and can't figure it out by myself, I'm asking here. I want markers, that go off-frame to appear on the frame edge. Short explaination:
- I have minimap, which rotates with player AimYaw.
- I have frame containing markers, which has common center with the minimap.
- Frame with markers rotates in opposite direction to player AimYaw, which makes the makers appear in correct position on the minimap.
- Yes, I have clip="1" over markers frame, which prevents them from being displayed beyond minimap egde.

It would be easy to display markers over map edge, if the minimap wasn't rotating. Because the minimap is rotating, the X and Y axes of the markers frame don't match with global X and Y axes.


As it appears on image, I need some of blue markers be placed in visible spot, over the map edge. If the marker remains inside the minimap square, it hould be left there untouched, as it's placed correctly.

Some of the code where I set markers position:
(part that rotates markers frame along with minimap map yaw is located in other part of script, and it's done automatically)

Code: Select all

// ---------------------------------- //
/** Set custom marker minimap position
 *	@param	_Marker		The marker to set position
 *	@param	_Minimap	The minimap to set marker
 *	@param	_Position	Position of the marker in world
 *	@param	_Weight		Weight of the marker
 *	@param	_FitToEdge	Move the marker to the map edge if its behind it
Void SetMarkerPosition(CMlControl _Marker, CMlMinimap _Minimap, Vec3 _Position, Integer _Weight, Boolean _FitToEdge) {
	if (_Marker == Null || _Minimap == Null || G_EnvironmentSize <= 0) return;
	declare OutputPosition = <0., 0., _Weight * .1>;
	// ---------------------------------- //
	// Compute marker position
	for (I, 0, 1) {
		OutputPosition[I] =
			// Substract positions
			(_Position[I*2] - _Minimap.WorldPosition[I*2])
			// Multiply
			* _Minimap.Size[I]
			// Adjust border
			/ (G_EnvironmentSize / _Minimap.ZoomFactor)
		if (I == 0) OutputPosition[I] *= -1; 
	// ---------------------------------- //
	// Fit marker to the map edge (to be re-worked)
	if (_FitToEdge) {
	// ---------------------------------- //
	// Set marker position
	_Marker.RelativePosition = OutputPosition;
If you have time and you're smart enough, I would appreciate your help very much :)
Ryzen 7 2700X, GTX 1070 Ti, 16 GB RAM, Windows 10 Insider Build


Posts: 1041
Joined: 15 Jun 2010, 15:46

Re: [Math problem] Need fit markers on the edge of minimap

Post by The_Big_Boo » 21 Jun 2016, 23:07

So if I understood correctly, you're putting your markers on a frame then rotate that frame to match the minimap. If you really want to do it this way, you need to use a rotation matrix to get the final position of your markers, clamp them to the edges then use the inverse matrix.

In pseudocode, considering all vectors have only 2 coordinates, it should be something like this (if I'm not too tired):

Code: Select all

Raw = (Position - MinimapCenter) * Scale

// Getting position after frame rotation
Rotated = <Raw.X * Cos(Yaw) - Raw.Y * Sin(Yaw), Raw.X * Sin(Yaw) + Raw.Y * Cos(Yaw)>

// Clamping to edges
Rotated.X = Clamp(Rotated.X, MinimapLeftEdge, MinimapRightEdge)
Rotated.Y = Clamp(Rotated.Y, MinimapTopEdge, MinimapBottomEdge)

// Rotating back
Out = <Rotated.X * Cos(Yaw) + Rotated.Y * Sin(Yaw), - Rotated.X * Sin(Yaw) + Rotated.Y * Cos(Yaw)>
OS: Win 7 Pro x64
RAM: 2x4GB Corsair @ 1600MHz
CPU: Intel i5 760 @ 3.6GHz
Mobo: Asus P7P55D-E
GPU: NVidia GTX 760 2GB
HDD: WD Black 1TB
Sound: VIA VT1828S (onboard)
Peripherals: Razer DeathAdder - Razer DeathStalker - Logitech F310

Post Reply

Return to “ManiaScript”

Who is online

Users browsing this forum: No registered users and 2 guests