Its necessary to bind every glVertex3f Point into collision function?
Help is Welcome thanks
Code: Select all
' question about openGL and collision
'
#include "gl/glu.bi"
#include "fbgfx.bi"
' Screencontrol fb.SET_GL_2D_MODE ,fb.OGL_2D_MANUAL_SYNC
' Screencontrol doesnt work here, don't know why?
'
' how I can make a simple collision between these two cubes?
' via pushing up,down,left,right arrow keys? multikey() ?
'
Sub glsetup(xres As Long,yres As Long)
glShadeModel(GL_SMOOTH) ' Enables Smooth Color Shading
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
glBlendFunc(GL_ONE,GL_ONE)
glEnable GL_ALPHA
glEnable GL_BLEND
glViewport(0, 0, xres, yres) ' Set the viewport
glMatrixMode(GL_PROJECTION) ' Change Matrix Mode to Projection
glLoadIdentity ' Reset View
gluPerspective(45.0, xres/yres, 1.0, 100.0)
glMatrixMode(GL_MODELVIEW) ' Return to the modelview matrix
glLoadIdentity ' Reset View
glclearcolor .2,.2,.2,1 'optional
End Sub
'Rotate and draw the cube with texturing on each face
Sub DrawGlCube(Byref rotangle As Single)
glLoadIdentity()
glTranslatef(2,0,-7)
glRotatef(rotangle,1,.5,.25) ' Rotate
glBegin(GL_QUADS)
glcolor3ub 255,0,0
glVertex3f( 1.0, 1.0,-1.0) ' Top right of the quad (top)
glVertex3f(-1.0, 1.0,-1.0) ' Top left of the quad (top)
glVertex3f(-1.0, 1.0, 1.0) ' Bottom left of the quad (top)
glVertex3f( 1.0, 1.0, 1.0) ' Bottom right of the quad (top)
glcolor3ub 255,100,0
glVertex3f( 1.0,-1.0, 1.0) ' Top right of the quad (bottom)
glVertex3f(-1.0,-1.0, 1.0) ' Top left of the quad (bottom)
glVertex3f(-1.0,-1.0,-1.0) ' Bottom left of the quad (bottom)
glVertex3f( 1.0,-1.0,-1.0) ' Bottom right of the quad (bottom)
glcolor3ub 255,0,255
glVertex3f( 1.0, 1.0, 1.0) ' Top right of the quad (front)
glVertex3f(-1.0, 1.0, 1.0) ' Top left of the quad (front)
glVertex3f(-1.0,-1.0, 1.0) ' Bottom left of the quad (front)
glVertex3f( 1.0,-1.0, 1.0) ' Bottom right of the quad (front)
glcolor3ub 0,0,200
glVertex3f( 1.0,-1.0,-1.0) ' Bottom left of the quad (back)
glVertex3f(-1.0,-1.0,-1.0) ' Bottom right of the quad (back)
glVertex3f(-1.0, 1.0,-1.0) ' Top right of the quad (back)
glVertex3f( 1.0, 1.0,-1.0) ' Top left of the quad (back)
glcolor3ub 0,255,0
glVertex3f(-1.0, 1.0, 1.0) ' Top right of the quad (left)
glVertex3f(-1.0, 1.0,-1.0) ' Top left of the quad (left)
glVertex3f(-1.0,-1.0,-1.0) ' Bottom left of the quad (left)
glVertex3f(-1.0,-1.0, 1.0) ' Bottom right of the quad (left)
glcolor3ub 255,0,100
glVertex3f( 1.0, 1.0,-1.0) ' Top right of the quad (right)
glVertex3f( 1.0, 1.0, 1.0) ' Top left of the quad (right)
glVertex3f( 1.0,-1.0, 1.0) ' Bottom left of the quad (right)
glVertex3f( 1.0,-1.0,-1.0)
glend
End Sub
Sub DrawGlCube2(Byref rotangle As Single)
glLoadIdentity()
glTranslatef(-2,0,-7)
glRotatef(rotangle,1,.5,.25) ' Rotate
glBegin(GL_QUADS)
glcolor3ub 255,0,0
glVertex3f( 1.0, 1.0,-1.0) ' Top right of the quad (top)
glVertex3f(-1.0, 1.0,-1.0) ' Top left of the quad (top)
glVertex3f(-1.0, 1.0, 1.0) ' Bottom left of the quad (top)
glVertex3f( 1.0, 1.0, 1.0) ' Bottom right of the quad (top)
glcolor3ub 255,100,0
glVertex3f( 1.0,-1.0, 1.0) ' Top right of the quad (bottom)
glVertex3f(-1.0,-1.0, 1.0) ' Top left of the quad (bottom)
glVertex3f(-1.0,-1.0,-1.0) ' Bottom left of the quad (bottom)
glVertex3f( 1.0,-1.0,-1.0) ' Bottom right of the quad (bottom)
glcolor3ub 255,0,255
glVertex3f( 1.0, 1.0, 1.0) ' Top right of the quad (front)
glVertex3f(-1.0, 1.0, 1.0) ' Top left of the quad (front)
glVertex3f(-1.0,-1.0, 1.0) ' Bottom left of the quad (front)
glVertex3f( 1.0,-1.0, 1.0) ' Bottom right of the quad (front)
glcolor3ub 0,0,200
glVertex3f( 1.0,-1.0,-1.0) ' Bottom left of the quad (back)
glVertex3f(-1.0,-1.0,-1.0) ' Bottom right of the quad (back)
glVertex3f(-1.0, 1.0,-1.0) ' Top right of the quad (back)
glVertex3f( 1.0, 1.0,-1.0) ' Top left of the quad (back)
glcolor3ub 0,255,0
glVertex3f(-1.0, 1.0, 1.0) ' Top right of the quad (left)
glVertex3f(-1.0, 1.0,-1.0) ' Top left of the quad (left)
glVertex3f(-1.0,-1.0,-1.0) ' Bottom left of the quad (left)
glVertex3f(-1.0,-1.0, 1.0) ' Bottom right of the quad (left)
glcolor3ub 255,0,100
glVertex3f( 1.0, 1.0,-1.0) ' Top right of the quad (right)
glVertex3f( 1.0, 1.0, 1.0) ' Top left of the quad (right)
glVertex3f( 1.0,-1.0, 1.0) ' Bottom left of the quad (right)
glVertex3f( 1.0,-1.0,-1.0)
glend
End Sub
Sub drawstring(xpos As Integer,ypos As Integer,text As String,colour As Ulong,size As Single,textangle As Single=0,charangle As Single=0,xres As Long=0,yres As Long=0)
glMatrixMode GL_PROJECTION 'save projection
glPushMatrix
glMatrixMode GL_MODELVIEW
glPushMatrix
glMatrixMode GL_PROJECTION 'make ortho
glLoadIdentity
glOrtho 0, xres, yres, 0,-1, 1
glMatrixMode GL_MODELVIEW
glLoadIdentity
#define Red(c) ((c) Shr 16 And 255)
#define Green(c) ((c) Shr 8 And 255)
#define Blue(c) ((c) And 255)
#define Alph(c) ((c) Shr 24)
glColor4ub Red(colour),Green(colour),Blue(colour),alph(colour)
glend
glpointsize(1.1*size)
glBegin (GL_POINTS)
Type point2d
As Single x,y
As Ulong col
End Type
Dim As Integer flag,codenum=256
If Instr(text,Chr(10)) Then flag=1
Static As Long runflag
Static As point2d infoarray()
Redim Preserve As point2d infoarray(128,codenum)
If runflag=0 Then
Dim As Ulong background=0
Screen 8
Width 640\8,200\16
Dim count As Long
For ch As Integer=1 To codenum
Cls
Draw String(1,1),Chr(ch)
For x As Long=1 To 8
For y As Long=1 To 16
If Point(x,y)<>background Then
count=count+1
infoarray(count,ch)=Type<point2d>(x,y)
End If
Next y
Next x
count=0
Next ch
runflag=1
End If
If size=0 Then Exit Sub
Dim As point2d temp(1 To 128,codenum),np
Dim As Single cr= 0.01745329 'degs to radians
#macro rotate(p1,p2,a,d)
np.col=p2.col
np.x=d*(Cos(a*cr)*(p2.x-p1.x)-Sin(a*cr)*(p2.y-p1.y)) +p1.x
np.y=d*(Sin(a*cr)*(p2.x-p1.x)+Cos(a*cr)*(p2.y-p1.y)) +p1.y
#endmacro
Dim As point2d cpt(1 To 128),c=Type<point2d>(xpos,ypos),c2
Dim As Integer dx=xpos,dy=ypos
For z6 As Integer=1 To Len(text)
Var asci=text[z6-1]
If asci=10 Then
If charangle<>0 Then xpos=xpos+12*Sin(charangle*cr)
dx=xpos:dy=dy+16:Goto skip 'chr(10) for new line
End If
For _x1 As Integer=1 To 128
temp(_x1,asci).x=infoarray(_x1,asci).x+dx
temp(_x1,asci).y=infoarray(_x1,asci).y+dy
temp(_x1,asci).col=colour
rotate(c,temp(_x1,asci),textangle,size)
cpt(_x1)=np
Var copyy=np.y
If charangle<>0 Then
Dim As Long p
If flag Then p=1 Else p=(z6-1)
c2=Type<point2d>(xpos+(size*8)*p*(Cos(textangle*cr)),ypos+(size*8)*p*(Sin(textangle*cr)))
rotate(c2,cpt(_x1),charangle,1)
If flag Then np.y=copyy
cpt(_x1)=np
End If
If infoarray(_x1,asci).x<>0 Then
If Abs(size)>1 Then
glVertex3f (cpt(_x1).x,(cpt(_x1).y),0)
End If
End If
Next _x1
dx=dx+9+4*(Sin(charangle*cr))*flag
skip:
Next z6
glend
glMatrixMode GL_PROJECTION 'restore
glPopMatrix
glMatrixMode GL_MODELVIEW
glPopMatrix
End Sub
Sub init Constructor
drawstring(0,0," ",0,0,0,0,0,0)
End Sub
Function Regulate(Byval MyFps As Long,Byref fps As Long) As Long
Static As Double timervalue,lastsleeptime,t3,frames
Dim As Double t=Timer
frames+=1
If (t-t3)>=1 Then t3=t:fps=frames:frames=0
Dim As Long sleeptime=lastsleeptime+((1/myfps)-T+timervalue)*1000
If sleeptime<1 Then sleeptime=1
lastsleeptime=sleeptime
timervalue=T
Return sleeptime
End Function
Screenres 800,600,32,,2
width 800\8,600\16 'larger dos fonts
glsetup(800,600)
Dim As Single angle
Dim As Long fps
Do
'angle+=1
glClear(GL_COLOR_BUFFER_BIT)
glEnable (GL_CULL_FACE)
DrawGlcube(angle)
DrawGlCube2(angle)
gldisable (GL_CULL_FACE) 'disable to use fb draw string
Draw String(5,5),"This is fb draw string, line 3 is set screencontrol fb.SET_GL_2D_MODE ,fb.OGL_2D_MANUAL_SYNC",rgb(255,255,255)
drawstring(20,20,"Test font with opengl",Rgb(200,100,0),3,0,0,800,600)
drawstring(550,80,"fps = " & fps,Rgb(0,100,200),2,10,0,800,600)
drawstring(200,100,"Free"+Chr(10)+"BASIC (rotated 90 degrees)",Rgb(200,0,0),2,90,0,800,600)
drawstring(200,560,"Press esc to end",Rgb(0,200,0),2,0,10,800,600)
glcolor3ub 255,255,255 'reset the opengl colour
Flip
Sleep regulate(35,fps),1
Loop Until Multikey(1)'esc key
Sleep
' ends
PS please wait perhaps I have the solution!