minimap

Blitz3D Forums/Blitz3D Programming/minimap

Mr. Slat(Posted 2010) [#1]
I made a minimap... but the background is black
and I wanted to give it a background texture of the heightmap or the colormap of the terrain, How can I match the Player 3D position with the texture position


GIB3D(Posted 2010) [#2]
PlayerBlipX = MiniMapX + (Player3DX/MiniMapWidth)
PlayerBlipY = MiniMapY + (Player3DY/MiniMapHeight)



Mr. Slat(Posted 2010) [#3]
????
I mean the backgroud is a texture

the player in the texture doesn't move or rotate, the objects and the texture will...


Kryzon(Posted 2010) [#4]
You'll need to make sure that the texture is well-aligned when you get the player's START position (meaning, the first register of the player position since you started the game).
From then on, you'll move the map using the texture position and rotation functions (you'll need a bit of testing to align things properly).
Since you started aligned at first, now the rest of the time the minimap will be properly aligned.

To make things easier, you also need to create your minimap mesh with the appropriate UV's on the vertices, so that when you move the texture it won't warp or distort in any way. You can do this in a modelling application (so-so) or procedurally (better):




Mr. Slat(Posted 2010) [#5]
Yes that's it..... I just don't understand, how to do this properly.


Mahan(Posted 2010) [#6]
This is code from a tilemap engine I've been writing in B3D:

The code copied deals with mapping between the screen coords and the tile coords.

Obviously you'll have to rewrite it to deal with the mapping between 3D-world coords and minimap-bitmap coords, but I still think you might get some ideas from the code, so here it is:



Looking at the comments above some have been talking about rotating the minimap-bitmap depending on the players (i presume) direction. Another idea might be to just let "north" on the map always be upwards, and just indicate the current direction of the player with an arrow or something like that.

Hope any of this helps you with some ideas for your problem.

edit: spelling


Mr. Slat(Posted 2010) [#7]
I dont't understand how this could help me.
I mean I just need to rotate the TEXTURE to same rotation of the character.

this is what I have so far

Type RadarObjects
Field Kind,ent
Field x#,y#,z#
Field relativeX#,relativeY#,relativeZ#
End Type

Type Radar
Field Entity,PlayerImage,BackGround
Field Texture, Source, FrameCount,image
End Type

Function AddRadarObject(ent,Kind%)
ARO.RadarObjects=New RadarObjects
ARO\ent = ent
ARO\Kind=Kind%
ARO\x#=EntityX#(ent):ARO\y#=EntityY#(ent):ARO\z#=EntityZ#(ent)
End Function

Function NewRadar(ThisRadar.Radar,Source,cam)
ThisRadar\Entity=CreateSprite(cam)
ThisRadar\Texture=CreateTexture(32*2,32*2)
ThisRadar\PlayerImage=LoadImage("Media\RadarPlayer.bmp")
ThisRadar\Source=CreateCone(3,1):ScaleMesh ThisRadar\Source,10,10,5:RotateMesh ThisRadar\Source,-90,0,0:EntityAlpha ThisRadar\Source,0
ThisRadar\BackGround=LoadTexture("Media\minimapblend.bmp",2):ThisRadar\image = LoadTexture("Game\Data\horrust Color.bmp")
SetBuffer(TextureBuffer(ThisRadar\Texture)):ClsColor(0,0,0):Cls()
SetBuffer(BackBuffer()):;EntityTexture(ThisRadar\Entity,ThisRadar\BackGround,0,0):
ScaleTexture(ThisRadar\image,20,20)
Sprite_Control(ThisRadar\Entity, -1.4,-0.8,1.8, 0,0,1,1,0.8,1):ScaleSprite ThisRadar\Entity,0.3,0.3:ThisRadar\FrameCount = 0
EntityTexture(ThisRadar\Entity, ThisRadar\Texture,0,1):
EntityTexture(ThisRadar\Entity, ThisRadar\image,0,0)
TextureBlend ThisRadar\Texture,3:EntityAlpha ThisRadar\Entity, 0.8
End Function

Function RefreshRadar(TheRadar.Radar, ThisPoint.RadarObjects)
ThisPoint\x#=EntityX#(ThisPoint\ent):ThisPoint\y#=EntityY#(ThisPoint\ent):ThisPoint\z#=EntityZ#(ThisPoint\ent)
TFormPoint (ThisPoint\x#,ThisPoint\y#,ThisPoint\z#,0,TheRadar\Source)
ThisPoint\relativeX=(0-TFormedX())
ThisPoint\relativeY=TFormedY()
ThisPoint\relativeZ=TFormedZ()
Select ThisPoint\Kind
Case 1:Color 255,0,0
Case 2:Color 0,255,0
Case 3:Color 0,255,255
End Select
DrawImage TheRadar\PlayerImage, (TextureWidth(TheRadar\Texture)/2)-(ImageWidth(TheRadar\PlayerImage)/2),(TextureHeight(TheRadar\Texture)/2)-(ImageWidth(TheRadar\PlayerImage)/2)
Plot (TextureWidth(TheRadar\Texture)/2)+ThisPoint\relativeX/100,(TextureHeight(TheRadar\Texture)/2)+ThisPoint\relativeZ/100
End Function

Function RenderRadar(TheRadar.Radar)
PositionEntity TheRadar\Source, EntityX(Slat), EntityY(Slat), EntityZ(Slat)
RotateEntity TheRadar\Source, EntityPitch(Slat), EntityYaw(Slat), EntityRoll(Slat)
RotateTexture TheRadar\BackGround,TheRadar\FrameCount/10
PositionTexture TheRadar\image,((TextureWidth(TheRadar\image)/2)-((EntityX(Slat)/TextureWidth(TheRadar\image))))/100, (((TextureHeight(TheRadar\image)/2)+EntityZ(Slat)/TextureHeight(TheRadar\image)))/100
End Function

Function UpdateRadar()
For ThisRadar.Radar=Each Radar
ThisRadar\FrameCount=ThisRadar\FrameCOunt+1
If thisRadar\FrameCount=180 Then ThisRadar\FrameCOunt=0
If ThisRadar\FrameCOunt Mod 10 Then
SetBuffer(TextureBuffer(ThisRadar\Texture))
Cls()
For Radarpoint.RadarObjects=Each RadarObjects
RefreshRadar(ThisRadar, RadarPoint)
Next
SetBuffer(BackBuffer())
EndIf
RenderRadar(ThisRadar)
Next
End Function

Function CreateRadar(cam)
RD.Radar=New Radar
NewRadar(RD,Slat,cam)
End Function


I also need to check the Size of the texture to match the real position...

->Sprite_Control(Sprite, SpriteXPos#, SpriteYPos#, SpriteZPos#, SpriteTexture, SpriteBlend%, SpriteAlpha#,ScaleX#, ScaleY#, ViewSpriteMode)

-> Slat is the Entity of the Character

I guess I'm Stuck Here.... I thought making a vector defining north or something and then rotate the texture exactly like the character rotates, but i don't know where to start.

....:/


Mr. Slat(Posted 2010) [#8]
Any help?


Nate the Great(Posted 2010) [#9]
well what you need is some sort of rotation and movement algorithms for your polygon's uv's... I dont know exactly how to implement this in b3d off the top of my head but here is a break down...

you have the original point x and y, opx and opy
you need an x,y and rotation of the player.

use atan2(y,x) and sin and cos functions to rotate the map... I guess it might go like this, I could be wrong tho...

angle = atan2(opx,opy)
angle = angle + rotation
u = cos(angle)
v = sin(angle)

now translate it by the x and y of the player and...

u = u + x
v = v + y

do that every frame for every point on the border of the minimap and you are done :)

you may get some oddities like some odd looking maps but im pretty sure this is correct, if not then mess around with switching sin and cos and maybe adding some +90 or -90 here and there, its really close...


Mr. Slat(Posted 2010) [#10]
ok,I also need to scale the texture, so that the texture moves in scale...


Dreamora(Posted 2010) [#11]
just add a *radius to the cos(...), sin(...) lines with radius your current "scale"