Post by Dan on Nov 25, 2005 16:14:23 GMT -5
This is giving me a HELL of a headache.
Ive just started work on what should eventually be a mixture between command and conquer and black and white.
It was starting to look like a beatifully simple task. Then i realised that for both the map editor and for selecting units et-cetera I was going to have a problem.
If i was powering the thing via a keyboard-controlled cursor then i'd have no problemo. But obviously I need to be able to select 3d objects with the mouse.
The most obvious example of this is in a map-editor. Say I want to detect which tile is being selected when the mouse button is clicked, I need to translate the regular mouse co-ordinates into the correct ones for the 3d objects.
The only thing which works in my favour is that the rotation and tilt of the camera is static, the only camera movement is X, Y and Zoom (not quite Z).
What works AGAINST me is that the map is scrollable (hence the X, Y movement).
Does anybody have tips, or even better -example code which might help me out?
Heres some example code of what i need to work with:
and here is the contents of mapdata.txt:
the idea of the mapdata.txt is to allow a texture, to be applied to a tile, as well as the elevation of each corner... i even allowed comments (square brackets) for the data part of it!!!!
The reason that textmsg$ exists was that I was going to use it to print onto the screen the X-index of the tile which was selected. didn't get that far tho .... hence this desperate and long message lol
Ive just started work on what should eventually be a mixture between command and conquer and black and white.
It was starting to look like a beatifully simple task. Then i realised that for both the map editor and for selecting units et-cetera I was going to have a problem.
If i was powering the thing via a keyboard-controlled cursor then i'd have no problemo. But obviously I need to be able to select 3d objects with the mouse.
The most obvious example of this is in a map-editor. Say I want to detect which tile is being selected when the mouse button is clicked, I need to translate the regular mouse co-ordinates into the correct ones for the 3d objects.
The only thing which works in my favour is that the rotation and tilt of the camera is static, the only camera movement is X, Y and Zoom (not quite Z).
What works AGAINST me is that the map is scrollable (hence the X, Y movement).
Does anybody have tips, or even better -example code which might help me out?
Heres some example code of what i need to work with:
' Begin Initialise
dim xSize, ySize, file, x, y, i, maxtextures
dim header$, textmsg$
dim camX#, camY#, camZ, camVX#, camVY#, scrollspeed#
Start:
file = OpenFileRead ("Files\mapdata.txt")
gosub CheckError
xSize = Val(ReadLine (file))
ySize = Val(ReadLine (file))
maxtextures = Val(ReadLine (file))
dim tex(maxtextures)
for i = 1 to maxtextures
tex(i)=LoadTexture(ReadLine (file))
next
dim texdata#(xSize,ySize)
dim RTdata#(xSize,ySize)
dim LTdata#(xSize,ySize)
dim RBdata#(xSize,ySize)
dim LBdata#(xSize,ySize)
for y = (ySize-1) to 0 step - 1
for x = 0 to (xSize-1)
do
header$=ReadText (file, true)
loop until left$(header$,1) <> "["
texdata#(x,y)=val(header$)
LTdata#(x,y) = val(ReadText (file, true))
RTdata#(x,y) = val(ReadText (file, true))
LBdata#(x,y) = val(ReadText (file, true))
RBdata#(x,y) = val(ReadText (file, true))
gosub CheckError
next
next
CloseFile (file)
camX# = 0
camY# = 0
camZ = 10
scrollspeed#=0.008
glEnable (GL_FOG)
glFogf (GL_FOG_END, 140)
glFogf (GL_FOG_MODE, GL_LINEAR)
glEnable (GL_TEXTURE_2D)
glMatrixMode (GL_PROJECTION)
glLoadIdentity ()
gluPerspective (45, (1.0*WindowWidth()) / WindowHeight(), 0.1, 160)
glMatrixMode (GL_MODELVIEW)
' End Initialise
TextMode (TEXT_OVERLAID)
textmsg$="moo"
while true
locate 1, 1: print textmsg$
glClear (GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
glLoadIdentity ()
glTranslatef (-camX#, -camY#, -camZ+camY#)
glRotatef (-45,1,0,0)
glRotatef (30,0,0,1)
' Begin Map Code
for x = 0 to (xSize-1)
for y = 0 to (ySize-1 )
glBindTexture (GL_TEXTURE_2D, tex(texdata#(x,y)))
glBegin (GL_QUADS)
glTexCoord2f ( 0, 0): glVertex3f ( x*2, y*2, LBdata#(x,y))
glTexCoord2f ( 0, 1): glVertex3f ( x*2, (y*2)+2, LTdata#(x,y))
glTexCoord2f ( 1, 1): glVertex3f ( (x*2)+2, (y*2)+2 , RTdata#(x,y))
glTexCoord2f ( 1, 0): glVertex3f ( (x*2)+2, y*2, RBdata#(x,y))
glEnd ()
next
next
' End map code
DrawText ()
SwapBuffers ()
while SyncTimer (10)
if Mouse_X()>.9 and camVX# < 1.5 then camVX#=camVX#+(scrollspeed#): endif
if Mouse_X()<.1 and camVX# > -1.5 then camVX#=camVX#-(scrollspeed#): endif
if Mouse_Y()>.9 and camVY# < 1.5 then camVY#=camVY#-(scrollspeed#): endif
if Mouse_Y()<.1 and camVY# > -1.5 then camVY#=camVY#+(scrollspeed#): endif
camZ=camZ-Mouse_Wheel ()
if camZ>120 then camZ=120: endif
if camZ<10 then camZ=10: endif
wend
camX#=camX#+(camVX#*camZ*0.04) 'move camera different speeds for
camY#=camY#+(camVY#*camZ*0.04) 'different elevations
camVX#=camVX#*0.96
camVY#=camVY#*0.96
wend
CheckError:
' Check for file error
if FileError () <> "" then
print FileError ()
CloseFile (file)
end
endif
return
and here is the contents of mapdata.txt:
8
8
2
textures\00001.jpg
textures\00002.jpg
[tile_format:texture_index,RT,LT,RB,RB]
[level1]
1 0 0 0 0
2 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
[level2]
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
2 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
2 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
2 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
the idea of the mapdata.txt is to allow a texture, to be applied to a tile, as well as the elevation of each corner... i even allowed comments (square brackets) for the data part of it!!!!
The reason that textmsg$ exists was that I was going to use it to print onto the screen the X-index of the tile which was selected. didn't get that far tho .... hence this desperate and long message lol