FreeBASIC Games Directory Forum
 Welcome, Guest. Please login or register. May 21, 2013, 08:58:59 AM 1 Hour 1 Day 1 Week 1 Month Forever Login with username, password and session length 11.5.2013 - Added a webpage for the latest FBGD competition.13.3.2013 - Members registrations temporary disabled. For all membership requests, please email me: lachie13@yahoo.com 30.11.2012 - The ninth issue of BASIC Gaming is out! Read it here: http://games.freebasic.net/forum/index.php?topic=560.022.11.2012 - Be sure to check our currently running annual FBGD game making competition. This year's theme is SEASONS OF THE YEAR, 300 \$ first place prize, and the competition runs till 18th of February. Link: http://games.freebasic.net/forum/index.php?topic=559.0

Pages: 1 [2] 3 4
 Author Topic: how would i make a 3d interface for rpg S.o.S  (Read 3192 times)
neo
Novice

Gender:
Posts: 57

 « Reply #15 on: July 24, 2010, 01:49:32 AM »

the code i have now is 2d code moving a ball so to say but i have to make the ball
move in 3d ... going to take some time to make but soon we will have a small but nice interface in time .
the code works .
just to understand how to make some thing giving the look of 3d in like a 2d mode .
we all should now like in art 3d is real just 2d its how the brain thinks its 3d odd how the brain does stuff like that.

i will try my best to work on this code to make the ball move in 3d.

dim space1 as integer ,xspace,yspace,zspace
dim moveing as integer   '' working with speed how fast you move.
DIM work_page AS INTEGER, x AS INTEGER, y AS INTEGER

SCREEN 20

COLOR 2, 15
work_page = 0
x = 320
y = 240
DO

x= 2000
y= 2000
z= 2000

sleep
' Let's work on a page while we display the other one
SCREENSET work_page, work_page XOR 1
' Check arrow keys and update position accordingly
IF MULTIKEY(&h4B) AND x > 0 THEN x = x - 1
IF MULTIKEY(&h4D) AND x < 639 THEN x = x + 1
IF MULTIKEY(&h48) AND y > 0 THEN y = y - 1
IF MULTIKEY(&h50) AND y < 479 THEN y = y + 1
CLS

CIRCLE(x, y), 30, , , , ,F
' Page flip
work_page = work_page XOR 1
LOOP WHILE NOT MULTIKEY(&h1)
' Clear input buffer
WHILE INKEY\$ = "": WEND
' Restore both work and visible pages to page 0
SCREENSET
PRINT "Press any key to exit..."
SLEEP
end

 Logged

IF you can make a game that's cool and fun....
in time you may have a good job in time ......

its like at the end of doom 2 what do i have to kill next lol put code in my brain and i will think mmmm css rocks
Brick Break
Forum Sage

Gender:
Posts: 412

 « Reply #16 on: July 25, 2010, 05:00:39 PM »

Please test your code before you post it. If you are using fblite to compile it (and it works for you in that mode) then please say so. There are numerous errors in your code.

dim space1 as integer ,xspace,yspace,zspace
The comma at the beginning of xspace prevents it from compiling. Also, mixing two modes of the command DIM causes a syntax error.

SCREEN 20
That is too high of a screen resolution for most monitors. Stick to screenres 640,480,32,2 so we can see it.

SCREENSET work_page, work_page XOR 1
Horrible! SCREENSET should NEVER be called in a loop. If you want to change pages, use pcopy, as that's what it's for. Also, your work page and visible page should not be the same if you want to use double buffering, if that's what you're trying to do. The "XOR 1" part is completely unnecessary. The command should be SCREENSET 0,1 and put BEFORE your DO statement.

work_page = work_page XOR 1
How is that supposed to switch pages?
 « Last Edit: July 25, 2010, 08:30:28 PM by Brick Break » Logged

neo
Novice

Gender:
Posts: 57

 « Reply #17 on: July 25, 2010, 10:46:53 PM »

do they have any kind of help file in freebasic thats the big one for you not Qbasic
 Logged

IF you can make a game that's cool and fun....
in time you may have a good job in time ......

its like at the end of doom 2 what do i have to kill next lol put code in my brain and i will think mmmm css rocks
Mitchell
Forum Howler

Gender:
Posts: 172

Rockin Geek

 « Reply #18 on: July 25, 2010, 10:51:18 PM »

You mean the FB manual? http://www.freebasic.net/wiki/wikka.php?wakka=DocToc
 Logged

Never underestimate the destructive powers of somebody doing something new without having any clue of how to do it.
neo
Novice

Gender:
Posts: 57

 « Reply #19 on: July 25, 2010, 10:52:18 PM »

yes but they have no help working with any thing in 3d
 Logged

IF you can make a game that's cool and fun....
in time you may have a good job in time ......

its like at the end of doom 2 what do i have to kill next lol put code in my brain and i will think mmmm css rocks
Mitchell
Forum Howler

Gender:
Posts: 172

Rockin Geek

 « Reply #20 on: July 25, 2010, 10:55:37 PM »

Do you want to use a 3d graphics library (OpenGL) or make your own 3d rendering code?
 Logged

Never underestimate the destructive powers of somebody doing something new without having any clue of how to do it.
neo
Novice

Gender:
Posts: 57

 « Reply #21 on: July 25, 2010, 10:58:46 PM »

opengl is not what i am looking for because thats more for hardgamers more for dx10
 Logged

IF you can make a game that's cool and fun....
in time you may have a good job in time ......

its like at the end of doom 2 what do i have to kill next lol put code in my brain and i will think mmmm css rocks
Mitchell
Forum Howler

Gender:
Posts: 172

Rockin Geek

 « Reply #22 on: July 25, 2010, 11:05:42 PM »

Well, to convert a 3d coordinate pair (like a vertex of a polygon) to a screen coordinate is complex.

However, there's a simple way to do it. Take your x coordinate, divide by z, multiply by a constant, and that's the x coordinate of the pixel. Take your y coordinate, divide by z, multiply by a constant, and that's the y coordinate of the pixel. Viola, the world's most primitive 3d engine.

The constant is determined by your aspect ratio, which is equal to . . . I don't remember, something like the tangent function of the ratio between the x and y screen resolution. If in doubt, ignore it and just divide by z.
 Logged

Never underestimate the destructive powers of somebody doing something new without having any clue of how to do it.
neo
Novice

Gender:
Posts: 57

 « Reply #23 on: July 25, 2010, 11:08:17 PM »

dim ballscreenpositionX as integer
dim ballscreenpositionY as integer
dim camerax as integer
dim cameray as integer
dim ball3
DIM work_page AS INTEGER, x AS INTEGER, y AS INTEGER , z as integer

SCREEN 20

COLOR 2, 15
work_page = 0
x = 320
y = 240

' Let's work on a page while we display the other one
SCREENSET work_page, work_page XOR 1

DO

sleep

' Check arrow keys and update position accordingly
IF MULTIKEY(&h4B) AND x > 0 THEN x = x - 1
IF MULTIKEY(&h4D) AND x < 639 THEN x = x + 1
IF MULTIKEY(&h48) AND y > 0 THEN y = y - 1
IF MULTIKEY(&h50) AND y < 479 THEN y = y + 1
CLS

CIRCLE(x, y), 30, , , , ,F
' Page flip
work_page = work_page XOR 1
LOOP WHILE NOT MULTIKEY(&h1)
' Clear input buffer
WHILE INKEY\$ = "": WEND
' Restore both work and visible pages to page 0
SCREENSET
PRINT "Press any key to exit..."
SLEEP
end

 Logged

IF you can make a game that's cool and fun....
in time you may have a good job in time ......

its like at the end of doom 2 what do i have to kill next lol put code in my brain and i will think mmmm css rocks
neo
Novice

Gender:
Posts: 57

 « Reply #24 on: July 25, 2010, 11:09:40 PM »

Well, to convert a 3d coordinate pair (like a vertex of a polygon) to a screen coordinate is complex.

However, there's a simple way to do it. Take your x coordinate, divide by z, multiply by a constant, and that's the x coordinate of the pixel. Take your y coordinate, divide by z, multiply by a constant, and that's the y coordinate of the pixel. Viola, the world's most primitive 3d engine.

The constant is determined by your aspect ratio, which is equal to . . . I don't remember, something like the tangent function of the ratio between the x and y screen resolution. If in doubt, ignore it and just divide by z.

you do that kind of work in the editor .................................................................................................
like if you are going to make a box to jump on you would make it there
 « Last Edit: July 25, 2010, 11:19:31 PM by neo » Logged

IF you can make a game that's cool and fun....
in time you may have a good job in time ......

its like at the end of doom 2 what do i have to kill next lol put code in my brain and i will think mmmm css rocks
neo
Novice

Gender:
Posts: 57

 « Reply #25 on: July 25, 2010, 11:14:04 PM »

i am just looking for some thing very basic to understand how a 3d engine works so i can add to it.... over time .......
all i want to see is how i would make the ball using the Z+  and Z-      then i could work for that ......
i wish for other freebasic programmers to have a head start on looking at code like this not where we are....looking at 2d crap god no .... lol
not saying some of the best games are 2d but 3d is the new wave of making a games.

list of thing  to get done
1- seeing the ball move in y and x and z
2- making ball jump
3- make ball to some person in 3d ........... ?
 « Last Edit: July 25, 2010, 11:28:54 PM by neo » Logged

IF you can make a game that's cool and fun....
in time you may have a good job in time ......

its like at the end of doom 2 what do i have to kill next lol put code in my brain and i will think mmmm css rocks
Brick Break
Forum Sage

Gender:
Posts: 412

 « Reply #26 on: July 25, 2010, 11:30:05 PM »

Well, to convert a 3d coordinate pair (like a vertex of a polygon) to a screen coordinate is complex.

No it's not. To draw 3D shapes to the screen is complex. You can play copypasta with any number of formulas on the internet, but stuff like textured triangles takes time.
 Logged

Brick Break
Forum Sage

Gender:
Posts: 412

 « Reply #27 on: July 25, 2010, 11:34:46 PM »

i am just looking for some thing very basic to understand how a 3d engine works so i can add to it.... over time .......
all i want to see is how i would make the ball using the Z+  and Z-      then i could work for that ......
i wish for other freebasic programmers to have a head start on looking at code like this not where we are....looking at 2d crap god no .... lol
not saying some of the best games are 2d but 3d is the new wave of making a games.

list of thing  to get done
1- seeing the ball move in y and x and z
2- making ball jump
3- make ball to some person in 3d ........... ?
I am making a 3D engine myself. What you are describing, however, is raycasting. Here's a great example:

 Logged

neo
Novice

Gender:
Posts: 57

 « Reply #28 on: July 25, 2010, 11:42:59 PM »

not bad interface look like doom1 or 2 lol
but you are saying there is no easy way to work on code like this because i am slowly making a rpg and it will be online rpg too so i need a good interface to work with.
i could mod using half life 2 edits to make my game but that is so much work for one person lot of c++ crap i would be looking at all the time going wtf .....
ps i am working with fbide
ps with your so doom like game how did you make the map of the game ??
like did you do the map in code
 « Last Edit: July 25, 2010, 11:55:10 PM by neo » Logged

IF you can make a game that's cool and fun....
in time you may have a good job in time ......

its like at the end of doom 2 what do i have to kill next lol put code in my brain and i will think mmmm css rocks
neo
Novice

Gender:
Posts: 57

 « Reply #29 on: July 26, 2010, 12:10:04 AM »

look what i found
i have my interface haaaaaa evil me i know there was one made some where for me
''
'' This Code Was Created By Jeff Molofee 2000
'' A HUGE Thanks To Fredric Echols For Cleaning Up
'' And Optimizing The Base Code, Making It More Flexible!
'' If You've Found This Code Useful, Please Let Me Know.
'' Visit My Site At nehe.gamedev.net
''
''------------------------------------------------------------------------------
'' Use ESC key to quit
'' F key to cycle filters (Nearest, Linear , MipMapped)
'' B key to toggle blending (on/off)
'' PgUp key and PgDn key to look up and look down
'' UpArrow, DnArrow, RightArrow, Left Arrow to move around
''
''------------------------------------------------------------------------------

'' compile as: fbc -s gui lesson10.bas

option explicit

#include once "GL/gl.bi"
#include once "GL/glu.bi"
#include once "crt.bi"          '' scanf is used to parse data file
#include once "fbgfx.bi"        '' for Scan code constants
#include once "createtex.bi"

'' Setup our booleans
const false = 0
const true  = not false

const piover180 = 0.0174532925f
''------------------------------------------------------------------------------
'' Types used by the model
type VERTEX                      '' Build Our Vertex Structure called VERTEX
x as single                  '' 3D Coordinates (x, y, z)
y as single
z as single
u as single                  '' Texture Coordinates (u, v)
v as single
end type

type TRIANGLE                    '' Build Our Triangle Structure called TRIANGLE
vertex(0 to 2) as VERTEX     '' Array Of Three Vertices
end type

type SECTOR                      '' Build Our Sector Structure called SECTOR
numtriangles as integer      '' Number Of Triangles In Sector
triangle as TRIANGLE ptr     '' Pointer To Array Of Triangles
end type

''------------------------------------------------------------------------------
declare sub readstr(byval f as integer, Buffer as string)
declare sub SetupWorld()

dim shared sector1 as SECTOR                   '' Our Model Goes Here

dim shared filter as uinteger                  '' Which Filter To Use
dim shared texture(0 to 2) as uinteger         '' Storage For 3 Textures

dim shared blend as integer                    '' Blending OFF/ON?
dim shared fp as integer                       '' F Pressed?
dim shared bp as integer                       '' B Pressed?

dim heading as single              '' direction of movement
dim xpos as single                 '' X position
dim zpos as single                 '' Y position

dim yrot as single                 '' Y Rotation = heading
dim walkbias as single             '' used with walkbiasangle for bouncing effect
dim walkbiasangle as single        '' used with walkbias for bouncing effect
dim lookupdown as single           '' View direction

dim x_m as single            '' Floating Point For Temp X, Y, Z, U And V Vertices
dim y_m as single
dim z_m as single
dim u_m as single
dim v_m as single

dim xtrans as single         '' Used For Player Translation
dim ztrans as single         '' Used For Player Translation
dim ytrans as single         '' Used For Bouncing Motion Up And Down
dim sceneroty as single      '' 360 Degree Angle For Player Direction

dim as integer numtriangles  '' Integer To Hold The Number Of Triangles
dim as integer loop_m        '' Loop counter

screen 18, 16, , 2

'' ReSizeGLScene
glViewport 0, 0, 640, 480                      '' Reset The Current Viewport
glMatrixMode GL_PROJECTION                     '' Select The Projection Matrix
glLoadIdentity                                 '' Reset The Projection Matrix
gluPerspective 45.0, 640.0/480.0, 0.1, 100.0   '' Calculate The Aspect Ratio Of The Window
glMatrixMode GL_MODELVIEW                      '' Select The Modelview Matrix
glLoadIdentity                                 '' Reset The Modelview Matrix

'' This Lesson is the first to demonstrate the use of BLOAD to load the bitmaps.
redim buffer(256*256*4+4) as ubyte                    '' Size = Width x Height x 4 bytes per pixel + 4 bytes for header
texture(0) = CreateTexture(@buffer(0),TEX_NOFILTER)   '' Nearest Texture
texture(1) = CreateTexture(@buffer(0))                '' Linear Texture (default)
texture(2) = CreateTexture(@buffer(0),TEX_MIPMAP)     '' MipMapped Texture
if texture(0) = 0 or texture(1) = 0 or texture(2) = 0 then end 1

'' All Setup For OpenGL Goes Here
glEnable GL_TEXTURE_2D                                '' Enable Texture Mapping
glBlendFunc GL_SRC_ALPHA, GL_ONE                      '' Set The Blending Function For Translucency
glClearColor 0.0, 0.0, 0.0, 0.5                       '' Black Background
glClearDepth 1.0                                      '' Depth Buffer Setup
glDepthFunc GL_LESS                                   '' The Type Of Depth Test To Do
glEnable GL_DEPTH_TEST                                '' Enables Depth Testing
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST      '' Really Nice Perspective Calculations

SetupWorld()

do
glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT      '' Clear Screen And Depth Buffer

xtrans = - xpos
ztrans = - zpos
ytrans = - walkbias - 0.25                      '' Used For Bouncing Motion Up And Down
sceneroty = 360.0 - yrot                        '' 360 Degree Angle For Player Direction

glRotatef lookupdown, 1.0, 0,0                  '' Rotate Up And Down To Look Up And Down
glRotatef sceneroty, 0, 1.0, 0                  '' Rotate Depending On Direction Player Is Facing

glTranslatef xtrans, ytrans, ztrans             '' Translate The Scene Based On Player Position
glBindTexture GL_TEXTURE_2D, texture(filter)    '' Select A Texture Based On filter

numtriangles = sector1.numtriangles             '' Get The Number Of Triangles In Sector 1

' Process Each Triangle
for loop_m = 0 to numtriangles - 1

glBegin GL_TRIANGLES                          '' Start Drawing Triangles
glNormal3f 0.0, 0.0, 1.0                  '' Normal Pointing Forward
x_m = sector1.triangle[loop_m].vertex(0).x         '' X Vertex Of 1st Point
y_m = sector1.triangle[loop_m].vertex(0).y         '' Y Vertex Of 1st Point
z_m = sector1.triangle[loop_m].vertex(0).z         '' Z Vertex Of 1st Point
u_m = sector1.triangle[loop_m].vertex(0).u         '' U Texture Coord Of 1st Point
v_m = sector1.triangle[loop_m].vertex(0).v         '' V Texture Coord Of 1st Point
glTexCoord2f u_m, v_m : glVertex3f x_m, y_m, z_m   '' Set The TexCoord And Vertice

x_m = sector1.triangle[loop_m].vertex(1).x         '' X Vertex Of 2nd Point
y_m = sector1.triangle[loop_m].vertex(1).y         '' Y Vertex Of 2nd Point
z_m = sector1.triangle[loop_m].vertex(1).z         '' Z Vertex Of 2nd Point
u_m = sector1.triangle[loop_m].vertex(1).u         '' U Texture Coord Of 2nd Point
v_m = sector1.triangle[loop_m].vertex(1).v         '' V Texture Coord Of 2nd Point
glTexCoord2f u_m, v_m : glVertex3f x_m, y_m, z_m   '' Set The TexCoord And Vertice

x_m = sector1.triangle[loop_m].vertex(2).x         '' X Vertex Of 3rd Point
y_m = sector1.triangle[loop_m].vertex(2).y         '' Y Vertex Of 3rd Point
z_m = sector1.triangle[loop_m].vertex(2).z         '' Z Vertex Of 3rd Point
u_m = sector1.triangle[loop_m].vertex(2).u         '' U Texture Coord Of 3rd Point
v_m = sector1.triangle[loop_m].vertex(2).v         '' V Texture Coord Of 3rd Point
glTexCoord2f u_m, v_m : glVertex3f x_m, y_m, z_m   '' Set The TexCoord And Vertice
glEnd
next

'' Keyboard handlers
if multikey(SC_F) and not fp then           '' F Key down
fp = true
filter += 1                             '' Cycle filter 0 -> 1 -> 2
if (filter > 2) then filter = 0         '' 2 -> 0
end if
if not multikey(SC_F) then fp = false       '' F Key Up

if multikey(SC_B) and not bp then           '' B Key down
bp = true
blend = not blend                       '' toggle blending On/Off
if blend then
glEnable(GL_BLEND)                  '' Turn Blending On
glDisable(GL_DEPTH_TEST)            '' Turn Depth Testing Off
else
glDisable(GL_BLEND)                 '' Turn Blending Off
glEnable(GL_DEPTH_TEST)             '' Turn Depth Testing On
end if
end if
if not multikey(SC_B) then bp = false       '' B Key up

if multikey(SC_UP) then
xpos = xpos - sin(heading*piover180) * 0.05    '' Move On The X-Plane Based On Player Direction
zpos = zpos - cos(heading*piover180) * 0.05    '' Move On The Z-Plane Based On Player Direction
if walkbiasangle >= 359.0 then                 '' Is walkbiasangle>=359?
walkbiasangle = 0.0                        '' Make walkbiasangle Equal 0
else
walkbiasangle = walkbiasangle + 10         '' If walkbiasangle < 359 Increase It By 10
end if
walkbias = sin(walkbiasangle * piover180)/20.0 '' Causes The Player To Bounce
end if

if multikey(SC_DOWN) then
xpos = xpos + sin(heading*piover180) * 0.05    '' Move On The X-Plane Based On Player Direction
zpos = zpos + cos(heading*piover180) * 0.05    '' Move On The Z-Plane Based On Player Direction
if walkbiasangle <= 1.0 then                   '' Is walkbiasangle<=1?
walkbiasangle = 359.0                      '' Make walkbiasangle Equal 359
else
walkbiasangle = walkbiasangle - 10         '' If walkbiasangle > 1 Decrease It By 10
end if
walkbias = sin(walkbiasangle * piover180)/20.0 '' Causes The Player To Bounce
end if

if multikey(SC_RIGHT) then
heading = heading - 1.0        '' Rotate The Scene To The Left
end if

if multikey(SC_LEFT) then
heading = heading + 1.0        '' Rotate The Scene To The Right
end if

if multikey(SC_PAGEUP) then
lookupdown = lookupdown - 1.0  '' look up
end if

if multikey(SC_PAGEDOWN) then
lookupdown = lookupdown + 1.0  '' look down
end if

flip  '' flip or crash
if inkey = chr(255)+"X" then exit do
loop while not multikey(SC_ESCAPE)

'' Empty keyboard buffer
while inkey\$ <> "": wend

end

''------------------------------------------------------------------------------
sub readstr(byval f as integer, Buffer as string)
do
line input #f, Buffer        '' Get one line
loop while (left(Buffer,1) = "/") or (Buffer = "")   '' See If It Is Worthy Of Processing
end sub

'-------------------------------------------------------------------------------
sub SetupWorld()
dim as single x, y, z, u, v         '' 3D And Texture Coordinates
dim as integer numtriangles         '' Number Of Triangles In Sector
dim oneline as string               '' String To Store Data In
dim as integer gl_loop, vert
dim fp as integer

fp = freefile
if (open (exepath + "\data\World.txt", for input, as #fp) <> 0) then end 1
readstr(fp, oneline)                                      '' Get Single Line Of Data
if oneline = "" then end 1                                '' Data file error, exit
sscanf(strptr(oneline), "NUMPOLLIES %d\n", @numtriangles) '' Read In Number Of Triangles
sector1.triangle = allocate(len(TRIANGLE)*numtriangles)   '' Allocate Memory For numtriangles And Set Pointer
sector1.numtriangles = numtriangles                       '' Define The Number Of Triangles In Sector 1
for gl_loop = 0 to numtriangles-1                         '' Loop Through All The Triangles
for vert = 0 to 2                                     '' Loop Through All The Vertices
if oneline = "" then end 1                        '' Data file error, exit
'' Read Data Into Respective Vertex Values
sscanf(strptr(oneline), "%f %f %f %f %f", @x, @y, @z, @u, @v)
'' Store Values Into Respective Vertices
sector1.triangle[gl_loop].vertex(vert).x = x    '' Sector 1, Triangle triloop, Vertice vertloop, x Value=x
sector1.triangle[gl_loop].vertex(vert).y = y    '' Sector 1, Triangle triloop, Vertice vertloop, y Value=y
sector1.triangle[gl_loop].vertex(vert).z = z    '' Sector 1, Triangle triloop, Vertice vertloop, z Value=z
sector1.triangle[gl_loop].vertex(vert).u = u    '' Sector 1, Triangle triloop, Vertice vertloop, u Value=u
sector1.triangle[gl_loop].vertex(vert).v = v    '' Sector 1, Triangle triloop, Vertice vertloop, v Value=v
next
next
close #fp
end sub

 Logged

IF you can make a game that's cool and fun....
in time you may have a good job in time ......

its like at the end of doom 2 what do i have to kill next lol put code in my brain and i will think mmmm css rocks
Pages: 1 [2] 3 4