![](sad.gif)
What's Wrong with this !!! :(
What''s wrong with this code.
I want to make it so you can walk aroung like real life but it isn''t working
''Code Begins Here
''
''****************
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
xpos = xpos + Sine(faceang)
zpos = zpos + Cose(faceang)
Case vbKeyDown
xpos = xpos - Sine(faceang)
zpos = zpos - Cose(faceang)
Case vbKeyLeft
faceang = faceang - 5
Case vbKeyRight
faceang = faceang + 5
End Select
If faceang <= -1 Then faceang = faceang + 360
If faceang >= 360 Then faceang = faceang - 360
Form_Paint
Form2.Label1 = "X - " & xpos
Form2.Label2 = "Z - " & zpos
Form2.Label3 = "Ang - " & faceang
End Sub
Private Sub Form_Load()
Dim hGLRC As Long
SetupPixelFormat hDC
hGLRC = wglCreateContext(hDC)
wglMakeCurrent hDC, hGLRC
For i = 0 To 359
Sine(i) = Sin((i * 3.145) / 180)
Cose(i) = Cos((i * 3.145) / 180)
Next i
glEnable GL_LIGHTING
glEnable GL_LIGHT0
glEnable GL_DEPTH_TEST
glEnable GL_DEPTH_BUFFER_BIT
glClearColor 0, 0, 0, 0
Form2.Show
End Sub
Private Sub Form_Paint()
glClear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT
glMatrixMode GL_MODELVIEW
glPushMatrix
glTranslatef xpos, 0, zpos
glRotatef faceang, 0, 1, 0
glPushMatrix
glutSolidCube 10
glTranslatef 10, 5, 1
glutWireSphere 5, 9, 9
glPopMatrix
glPopMatrix
SwapBuffers hDC
End Sub
Private Sub Form_Resize()
glViewport 0, 0, Form1.ScaleWidth, Form1.ScaleHeight
glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective 60, Form1.ScaleWidth / Form1.ScaleHeight, 1, 100
glMatrixMode GL_MODELVIEW
glLoadIdentity
End Sub
''****************
''
''Code Ends Here
![](sad.gif)
It''s in VB? Thats about all I can think of
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
![](wink.gif)
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
Simple! You are adding using degrees. Sin and Cos (I don''t think Sine and Cose are functions) accept parameters in RADIANS. Add 0.05 or so... 360 degrees in radians is pi*2.
Zer,
The array of sine(359) and cose(359) are changed from radians to degrees
>>For i = 0 To 359
>>Sine(i) = Sin((i * 3.145) / 180)
>>Cose(i) = Cos((i * 3.145) / 180)
>>Next i
-Jamie
The array of sine(359) and cose(359) are changed from radians to degrees
>>For i = 0 To 359
>>Sine(i) = Sin((i * 3.145) / 180)
>>Cose(i) = Cos((i * 3.145) / 180)
>>Next i
-Jamie
I think that a closer approximation of pi is 3.14159. You seem to have missed a 1 between your 4 and 5
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
![](wink.gif)
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
Was that out of memory or calculator?
Calc says: 3.1415926535897932384626433832795![](tongue.gif)
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
Calc says: 3.1415926535897932384626433832795
![](tongue.gif)
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
Enough on the pi already eh. :D ![](wink.gif)
any way, i figured you need to put the rotatef before the transalatef.
Or do you.....?
-Jamie
![](wink.gif)
any way, i figured you need to put the rotatef before the transalatef.
Or do you.....?
-Jamie
Of course that is the way you have to do it... for example, if you translate everything 100 units away, they all will get rotated around <0,0,0> and that would make it appear in some really weird places. Makes sense to rotate first and THEN translate it
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
![](smile.gif)
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
When I try this out it still doesn''t work though. ![](tongue.gif)
I don''t know why. I have made something where I can walk around in 3D before but I droped my 4.3gb HDD so I had to buy a 20gig![](smile.gif)
I lost all my stuff that I made. Even though it wasn''t very good I could still use it to look at for examples.
When I do this It translates weird when I go to walk, It is like I am walking but facing a different direction.
![](tongue.gif)
I don''t know why. I have made something where I can walk around in 3D before but I droped my 4.3gb HDD so I had to buy a 20gig
![](smile.gif)
I lost all my stuff that I made. Even though it wasn''t very good I could still use it to look at for examples.
When I do this It translates weird when I go to walk, It is like I am walking but facing a different direction.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement