|
MyWorld
Aug 15, 2010 13:07:51 GMT -5
Post by James :) (aka Madcow) on Aug 15, 2010 13:07:51 GMT -5
Been a while since i've been here being busy and all Now Having to Run it on Wine as Windows Borked Up But everything Works including Plugins . But ive decided to make one last thing in Basic4GL to try and push it to its limits using what i've learnt from the few small games, experiments and the B4Messenger I Wrote. As you can see this is also powered by a Libary called Basic4GL Plus, I've Written that comes with a lot of Functions and Subroutines to ease development and hopefully make you type less im hoping that this project will also help make some more libarys, for others to use. i may not finish this but im hoping to make some last contributions to Basic4GL although i might return the once in a while. Anyways what i needed help with as i'm not much of a mathmatition, is i want to roatate the camera when i press the left or right arrow keys and still go in the direction it's facing, thats the bit im not so good at of course whis will be all easy stuff for you guys :L pb4.wikispaces.com/file/view/MyWorld2.tar.gz/156890647/MyWorld2.tar.gz ^- thats the code you can examine Ofcourse Suggestions and Comments Welcome
|
|
|
MyWorld
Aug 15, 2010 13:44:40 GMT -5
Post by Supermonkey on Aug 15, 2010 13:44:40 GMT -5
|
|
|
MyWorld
Aug 15, 2010 14:08:55 GMT -5
Post by shadow008 on Aug 15, 2010 14:08:55 GMT -5
I have an idea, why not use gluLookAt() and calculate the position and look at position. When u have that, normalize the direction of the look at direction and add it to position, recalculate, and repeat.
|
|
|
MyWorld
Aug 15, 2010 15:05:46 GMT -5
Post by James :) (aka Madcow) on Aug 15, 2010 15:05:46 GMT -5
Thanks Supermonkey I knew you had written something but oh well Sorry I hve neve used that comman shadow, care to explain
|
|
|
MyWorld
Aug 15, 2010 15:47:00 GMT -5
Post by James :) (aka Madcow) on Aug 15, 2010 15:47:00 GMT -5
okay ive implemented that and it works fine just gunna work on the height map routine and then ill had some other things maybe devloping the file format i might try get an xml parser working it shoudnt be too hard
|
|
|
MyWorld
Aug 15, 2010 16:25:49 GMT -5
Post by comethenleave on Aug 15, 2010 16:25:49 GMT -5
okay ive implemented that and it works fine just gunna work on the height map routine and then ill had some other things maybe devloping the file format i might try get an xml parser working it shoudnt be too hard I've never seen ANYONE use as many smiley's as you
|
|
|
MyWorld
Aug 15, 2010 16:32:00 GMT -5
Post by Supermonkey on Aug 15, 2010 16:32:00 GMT -5
It's a smily fest. At least the content of the post is actually programming related, which is always positive on a programming forum .
|
|
|
MyWorld
Aug 16, 2010 3:34:02 GMT -5
Post by James :) (aka Madcow) on Aug 16, 2010 3:34:02 GMT -5
haha, sorry. it's bad habit's proberly aquired from facebook or msn but at least it cheers up my posts, everyone needs a smile
|
|
|
MyWorld
Aug 16, 2010 12:30:21 GMT -5
Post by shadow008 on Aug 16, 2010 12:30:21 GMT -5
Sorry for the crappy post, i was in a rush First off, you would use gluLookAt() instead of gltranslatef()/glrotatef() glulookat(pos(0),pos(1),pos(2),lookat(0),lookat(1),lookat(2),0,1,0) (the (0,1,0) at then end of the function is the "up" direction(in opengl's case, its "Y")) next, you would calculate the lookat point: function GetLookatPos(&pos() as single,&lookat() as single,xang as single,yang as single)
lookat(0) = pos(0) - (sind(xang)*cosd(yang)) * 5 lookat(1) = pos(1) + (sind(yang)) * 5 lookat(2) = pos(2) + (cosd(xang)*cosd(yang)) * 5
return 0
endfunction pos is the camera position, lookat is the lookat pos, xang is the x angle, and yang is the y angle. X and Y angle could be modded something like this: if scankeydown(vk_right) then xang = xang + 1:endif if scankeydown(vk_left) then xang = xang - 1:endif you should really use mouse movement for that instead, like this: xang = xang + mouse_xd() * 20 yang = yang + mouse_yd() * 20 then, after you get the lookat point, the ray between the cam pos and the lookat point is directly ahead . In the function i provided, mess around with the value the numbers are all multiplied by to speed up, or slow down movement(i used 5). And then: Direction = -(Lookat - pos) 'keep it inverted(i think? :P) if (forward button pressed) then pos = pos + Direction endif
and vice versa for backwards.... Hope i explained everything for you If not, i also took the liberty of doing it for you ;D include Basic4GLPlusLibary.gb Init() setZBuffer(false) const heightScale# = 5
Struc SCamera Dim pos(2) as single Dim Lookat(2) as single Dim rot(1) as single Dim Direction(2) as single endStruc
Struc SHeightMap Dim XSize Dim YSize Dim &HeightData#()() endStruc
Function SHeightMap LoadHeightMap(Filename$) Dim File = openFileRead(Filename$) if FileError() <> "" then Echo(FileError(), false) closeFile(File) end endif Dim SHeightMap HeightMap Dim x, y HeightMap.XSize = Val(ReadLine(File)) HeightMap.YSize = Val(ReadLine(File)) alloc HeightMap.HeightData#, HeightMap.XSize - 1, HeightMap.YSize - 1 for x = 0 to HeightMap.Xsize - 1 for y = 0 to HeightMap.Ysize - 1 HeightMap.HeightData#(x)(y) = Val(ReadText(File, true)) * heightScale# next next closeFile(File) return HeightMap endFunction
Function SCamera setCameraDefaults() Dim SCamera Camera Camera.pos(0) = -10 Camera.pos(1) = -30 Camera.pos(2) = -110 return Camera endFunction
function GetLookatPos(&pos() as single,&lookat() as single,xang as single,yang as single)
lookat(0) = pos(0) - (sind(xang)*cosd(yang)) * 5 lookat(1) = pos(1) + (sind(yang)) * 5 lookat(2) = pos(2) + (cosd(xang)*cosd(yang)) * 5 return 0
endfunction
Sub UpdateCamera(SCamera &Camera) gluLookat(Camera.pos(0),Camera.pos(1),Camera.pos(2),Camera.Lookat(0),Camera.Lookat(1),Camera.Lookat(2),0,1,0) camera.rot(0) = camera.rot(0) + mouse_xd() * 20 camera.rot(1) = camera.rot(1) - mouse_yd() * 20 Camera.Direction = (Camera.Lookat - Camera.pos) if KeyDown("S") then Camera.pos = camera.pos - Camera.Direction elseif KeyDown("W") then Camera.pos = camera.pos + Camera.Direction endif endSub
Sub DrawHeightMap(SHeightMap HeightMap) Dim x, y glBegin (GL_POINTS) for x = 0 to HeightMap.XSize - 1 for y = 0 to HeightMap.YSize - 1 glVertex3f(x, HeightMap.HeightData#(x)(y)*heightScale#, y) next next glEnd() endSub Dim SHeightMap World = LoadHeightMap("Files\Hills01.dat") Dim SCamera Camera = setCameraDefaults()
while true TextLocation(0, 0) Echo("My World v0.1", false) UpdateCamera(Camera) DrawHeightMap(World) Redraw() GetLookAtPos(Camera.pos,Camera.LookAt,Camera.rot(0),Camera.rot(1)) Clear() wend I used this technique(similar concepts) in my project: basic4gl.proboards.com/index.cgi?board=demo&action=display&thread=3279gl w/ ur project!!! ;D
|
|
|
MyWorld
Aug 16, 2010 14:22:11 GMT -5
Post by James :) (aka Madcow) on Aug 16, 2010 14:22:11 GMT -5
Thanks I'll take a look see if i can get my head round it
|
|
|
MyWorld
Aug 19, 2010 4:29:48 GMT -5
Post by James :) (aka Madcow) on Aug 19, 2010 4:29:48 GMT -5
Heres My Latest Update Still Need to Update it to use the Glu Code, But My Basic4GL Plus Libary Comes with a few more functions that are helpfull, that i seem to use alot and stop me typing as much. but also my first release of my XMLParser for Basic4GL is now in use, atm it dosnt support parent, next sibling or previous sibling, it wont parse cdata tags, comment tags or attributes correctly but thats planned for the next release but its a very primative parser and im happy i managed to get it working in basic4gl plus it tests out basic4gls seek function which is never used im sure their are ways i could speed it up as its not the fastest of parsers. pb4.wikispaces.com/file/view/MyWorld5.tar.gz/157302797/MyWorld5.tar.gzNote: Supermonkey move this to Demo Section ?
|
|