can anyone help me with collision
can anyone help me with collision
can you put collisions in pb yet i want to make a game but cant find anything about how to do collisions thanks
did you try these functions ?
Result = SpriteCollision(#Sprite1, x1, y1, #Sprite2, x2, y2)
Result = SpritePixelCollision(#Sprite1, x1, y1, #Sprite2, x2, y2)
Result = SpriteCollision(#Sprite1, x1, y1, #Sprite2, x2, y2)
Result = SpritePixelCollision(#Sprite1, x1, y1, #Sprite2, x2, y2)
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
cool guess its a good thing i bought the a copy thanks for the help
Yeah, 3D is a new direction PB is taking, and i must say its very exciting


i read all slides presented in O.D.E website. You said Fred's agree to implement such a physic model ! Marvelous... Hope i will be good enough to use such complicated things :roll: One small step for Fred, one giant leap for purebasic-users 

No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
erm all good but from the current commands and the above, it seems pb`s 3d parts could turn into a darkbasic type thing (bad) as apposed to a b3d way of coding 3d (better)
stuff like CameraLocate(0, 128, 25, 128) ehh, why have a special command to position a camera? surely it would make sense to just use one for all entitys, same goes for some others... maybe some like it i dunno, but surely it dont make real sense.
also shouldnt physics etc be left to the coders? (dont like the idea of pb turning into a kinda click n play thing like the above makes it sound)
stuff like CameraLocate(0, 128, 25, 128) ehh, why have a special command to position a camera? surely it would make sense to just use one for all entitys, same goes for some others... maybe some like it i dunno, but surely it dont make real sense.
also shouldnt physics etc be left to the coders? (dont like the idea of pb turning into a kinda click n play thing like the above makes it sound)
stuff like CameraLocate(0, 128, 25, 128) ehh, why have a special command to position a camera? surely it would make sense to just use one for all entitys, same goes for some others... maybe some like it i dunno, but surely it dont make real sense.

Surely its easier to move the camera around any given scene instead of moving the entire scene (and entities) around the camera?
Why re-invent the wheel? if a good physics lib exsists why not plug it into PB? BTW PB will never turn into a click and play thing! What have you been reading?also shouldnt physics etc be left to the coders? (dont like the idea of pb turning into a kinda click n play thing like the above makes it sound)
I agree DarkBasic is sh!te, but i think we're quite safe in thinking that PB will be vastly superiour! (I've had no experience of B3D)it seems pb`s 3d parts could turn into a darkbasic type thing (bad) as apposed to a b3d way of coding 3d (better)
I think he was referring to a similar command for all entities (even camera). like:
stuff like CameraLocate(0, 128, 25, 128) ehh, why have a special command to position a camera? surely it would make sense to just use one for all entitys, same goes for some others... maybe some like it i dunno, but surely it dont make real sense.
Surely its easier to move the camera around any given scene instead of moving the entire scene (and entities) around the camera?
Code: Select all
MoveEntity #Camera,X,Y,Z
ODE is widely used in other (C++) games/apps, so why not take advantage of it, and not reinvent the weel, as Kale mentioned here.
-Lars
Last edited by LarsG on Sat Aug 16, 2003 2:41 pm, edited 1 time in total.
AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Why not...
Why not do the 3D engine in pure assembly code? The ultimate 3D engine. There's some assembly code 3D out there that blows away the speed of OGRE, OGRE is not even close. I found one assembly code Fastgraph 6 that on speed test after speed test came out, at times, 1000% faster than DirectX!!!
Check this assembly code out, it's more of a 3D in 2D sort of thing but very interesting for assembly doing 3D nevertheless:
Check this assembly code out, it's more of a 3D in 2D sort of thing but very interesting for assembly doing 3D nevertheless:
Code: Select all
;-=-=-=-=-=-=-=-=-=-=-
; Toby Opferman
; _Secret/Scrat
; 3D Wire Frame Cube
; http://www.opferman.com
; programming@opferman.com
;
; ** This Program Requires a Math CO-Processor **
; ** No Bounds Checking, Don't Go Off Screen **
; ** X, Y, Z Rotation, +/- Scaling **
;
; Program uses World Positioning 0 , 0, 300
; and Camera View of 0, 0, 0 and 0, 0, 0 degrees
;-=-=-=-=-=-=-=-=-=-=-
.MODEL TINY
.386
.CODE
ORG 100h
START:
MOV AL, 13h
INT 10h ; Set Mode 13h
ROTATE:
XOR EAX, EAX
PUSH DS
POP ES
MOV DI, Offset Buffer
MOV ECX, 16000
REP STOSD ; Clear Double Buffer
XOR AX, AX
CMP RY, AL
JZ SHORT R2
CALL ROTATEY ; Rotate On Y Axis
R2:
CMP RX, AL
JZ SHORT R3
CALL ROTATEX ; Rotate On X Axis
R3:
CMP RZ, AL
JZ SHORT R4
CALL ROTATEZ ; Rotate On Z Axis
R4:
MOV SI, OFFSET Face1 ; Start at Face 1
MOV ECX, 6 ; Loop Through The 6 Faces
PLOT:
PUSH ECX
MOV ECX, 3 ; Save CX and Plot 3 Lines
LINEPLOT:
PUSH ECX
MOV BL, CL
NEG BL
ADD BL, 3 ; Convert CL (3-0) Into (0-3)
XOR BH, BH
MOV AL, DS:[SI + BX] ; Get Point 1
CALL PROJECT1
MOV AL, DS:[SI + BX + 1] ; Get Point 2
CALL PROJECT2
CALL LINE ; Draw Line
POP ECX
LOOP SHORT LINEPLOT
POP ECX
MOV AL, DS:[SI] ; Get First Point
CALL PROJECT1
CALL LINE ; Plot Last Line
ADD SI, 4 ; Next Face
LOOP SHORT PLOT
MOV SI, Offset Buffer
XOR DI, DI
PUSH 0A000h
POP ES
MOV ECX, 16000
REP MOVSD ; Update Video Screen
MOV AH, 1 ; Check Key Press
INT 16h
JNZ SHORT GETKEY ; No Key Press? Continue
JMP ROTATE
GETKEY:
XOR AH, AH ; Get Key
INT 16h
CALL KEYS
TEST BX, BX
JNZ SHORT FINISH
JMP ROTATE
FINISH:
MOV AX, 3 ; Return To Text Mode
INT 10h
RET
;-=-=-=-=-=-=-=-=-=-
; Keys
; Tests Keyboard Input
;-=-=-=-=-=-=-=-=-=-
KEYS PROC
XOR BX, BX
CMP AH, 45 ; Scan Code For X
JNE SHORT N1
NOT RX ; Set Rotation Of X
N1:
CMP AH, 21 ; Scan Code For Y
JNE SHORT N2
NOT RY ; Set Rotation Of Y
N2:
CMP AH, 44 ; Scan Code For Z
JNE SHORT N3
NOT RZ ; Set Rotation Of Z
N3:
CMP AH, 1 ; Scan Code For Escape
JNE SHORT N4
NOT BX ; Set Quit
N4:
CMP AH, 13 ; Scale UP
JNE SHORT N5
CALL SCALEUP
N5:
CMP AH, 12 ; Scale Down
JNE SHORT N6
CALL SCALEDOWN
N6:
RET
ENDP KEYS
;-=-=-=-=-=-=-=-=-
; Scale Up
;-=-=-=-=-=-=-=-=-
SCALEUP PROC
PUSHA ; Save Registers
MOV SI, Offset X ; Get X, Y, Z Varibles
MOV DI, Offset Y
MOV BX, Offset Z
MOV ECX, 8 ; Do All 8 Points
SKUP:
FLD DWORD PTR [SI] ; Scale X
FMUL ScaleFactor
FSTP DWORD PTR [SI]
FLD DWORD PTR [DI] ; Scale Y
FMUL ScaleFactor
FSTP DWORD PTR [DI]
FLD DWORD PTR [BX] ; Scale Z
FMUL ScaleFactor
FSTP DWORD PTR [BX]
ADD SI, 4 ; Next Point
ADD DI, 4
ADD BX, 4
LOOP SHORT SKUP ; Loop Back
POPA ; Restore Registers
RET
ENDP SCALEUP
;-=-=-=-=-=-=-=-=-
; Scale Down
;-=-=-=-=-=-=-=-=-
SCALEDOWN PROC
PUSHA ; Save Registers
MOV SI, Offset X ; Get X, Y, Z Varibles
MOV DI, Offset Y
MOV BX, Offset Z
MOV ECX, 8 ; Do All 8 Points
SKDN:
FLD DWORD PTR [SI] ; Scale X
FDIV ScaleFactor
FSTP DWORD PTR [SI]
FLD DWORD PTR [DI] ; Scale Y
FDIV ScaleFactor
FSTP DWORD PTR [DI]
FLD DWORD PTR [BX] ; Scale Z
FDIV ScaleFactor
FSTP DWORD PTR [BX]
ADD SI, 4 ; Next Point
ADD DI, 4
ADD BX, 4
LOOP SHORT SKDN ; Loop Back
POPA ; Restore Registers
RET
ENDP SCALEDOWN
;-=-=-=-=-=-=-=-=-=-
; Line Drawing Procedure
; Draws a Line From
; (TempX, TempY) To (TempX2, TempY2)
;-=-=-=-=-=-=-=-=-=-
LINE PROC
PUSHA
MOV DI, OFFSET Buffer ; DI = Buffer + X + Y*320
ADD DI, TempX ; Setting Up Starting Point
MOV AX, TempY
SHL AX, 6
ADD DI, AX
SHL AX, 2
ADD DI, AX
XOR AX, AX
MOV Error, AX
MOV AX, TempX2 ; Set Delta X
SUB AX, TempX
MOV DeltaX, AX
MOV AX, TempY2 ; Set Delta Y
SUB AX, TempY
MOV DeltaY, AX
MOV AX, 1 ; Set X_INC To 1
MOV X_INC, AX
MOV AX, 320 ; Set Y_INC To 320
MOV Y_INC, AX
XOR AX, AX ; Test Delta X Against 0
CMP DeltaX, AX
JGE SHORT SKIP1
NEG X_INC ; Negate Them
NEG DeltaX
SKIP1:
CMP DeltaY, AX ; Test DeltaY Against Zero
JGE SHORT SKIP2
NEG Y_INC ; Negate Them
NEG DeltaY
SKIP2:
MOV AX, DeltaY
CMP DeltaX, AX ; DeltaX > DeltaY?
JLE SHORT ELSE1
MOV CX, DeltaX ; Loop DeltaX Times
INC CX
THEN:
DEC CX
MOV BYTE PTR [DI], 1 ; Set Color
MOV AX, DeltaY ; Set Error
ADD Error, AX
MOV AX, Error
CMP AX, DeltaX ; Error>DeltaX
JLE SHORT AGAIN
SUB AX, DeltaX ; Error -= DeltaX
MOV Error, AX
ADD DI, Y_INC ; DI += Y_INC
AGAIN:
ADD DI, X_INC ; DI += X_INC
TEST CX, CX ; Loop Back
JNZ SHORT THEN
JMP SHORT DONE_LINE
ELSE1:
MOV CX, DeltaY ; Loop DeltaY Times
INC CX
ELSE_LOOP:
DEC CX
MOV BYTE PTR [DI], 1 ; Set Color
MOV AX, DeltaX ; Set Error
ADD Error, AX
MOV AX, Error
CMP AX, 0 ; Error>0
JLE SHORT AGAIN2
SUB AX, DeltaY ; Error -= DeltaY
MOV Error, AX
ADD DI, X_INC ; DI += X_INC
AGAIN2:
ADD DI, Y_INC ; DI += Y_INC
TEST CX, CX ; Loop Back
JNZ SHORT ELSE_LOOP
DONE_LINE:
POPA
RET
ENDP LINE
;-=-=-=-=-=-=-=-=-=-=-
; Rotates All Points
; Around X Axis
;-=-=-=-=-=-=-=-=-=-=-
ROTATEX PROC
PUSHA ; Save Registers
MOV SI, Offset Y ; Get Y And Z Varibles
MOV DI, Offset Z
MOV ECX, 8 ; Do All 8 Points
ROTX:
FLD DWORD PTR [SI] ; Y = Y*COS-Z*SIN
FMUL COSAngle
FSTP Temp1
FLD DWORD PTR [DI]
FMUL SINAngle
FSTP Temp2
FLD Temp1
FSUB Temp2
FSTP Temp1 ; Temporay Storage
FLD DWORD PTR [DI] ; Z = Y*SIN+Z*COS
FMUL COSAngle
FSTP Temp2
FLD DWORD PTR [SI]
FMUL SINAngle
FADD Temp2
FSTP DWORD PTR [DI] ; Store Z
FLD Temp1 ; Store Y
FSTP DWORD PTR [SI]
ADD SI, 4 ; Next Point
ADD DI, 4
LOOP SHORT ROTX ; Loop Back
POPA ; Restore Registers
RET
ENDP ROTATEX
;=-=-=-=-=-=-=-=-=-=-=-
; Rotates All Points
; Around Y Axis
;-=-=-=-=-=-=-=-=-=-=-=
ROTATEY PROC
PUSHA ; Save Registers
MOV SI, Offset X ; Get X And Z Varibles
MOV DI, Offset Z
MOV ECX, 8 ; Do All 8 Points
ROTY:
FLD DWORD PTR [SI] ; X = X*COS-Z*SIN
FMUL COSAngle
FSTP Temp1
FLD DWORD PTR [DI]
FMUL SINAngle
FSTP Temp2
FLD Temp1
FSUB Temp2
FSTP Temp1 ; Temporay Storage
FLD DWORD PTR [DI] ; Z = X*SIN+Z*COS
FMUL COSAngle
FSTP Temp2
FLD DWORD PTR [SI]
FMUL SINAngle
FADD Temp2
FSTP DWORD PTR [DI] ; Store Z
FLD Temp1 ; Store X
FSTP DWORD PTR [SI]
ADD SI, 4 ; Next Point
ADD DI, 4
LOOP SHORT ROTY ; Loop Back
POPA ; Restore Registers
RET
ENDP ROTATEY
;-=-=-=-=-=-=-=-=-=-=-=-
; Rotates All Points
; Around Z Axis
;=-=-=-=-=-=-=-=-=-=-=-=
ROTATEZ PROC
PUSHA ; Save Registers
MOV SI, Offset X ; Get X And Y Varibles
MOV DI, Offset Y
MOV ECX, 8 ; Do All 8 Points
ROTZ:
FLD DWORD PTR [SI] ; X = X*COS-Y*SIN
FMUL COSAngle
FSTP Temp1
FLD DWORD PTR [DI]
FMUL SINAngle
FSTP Temp2
FLD Temp1
FSUB Temp2
FSTP Temp1 ; Temporay Storage
FLD DWORD PTR [DI] ; Y = X*SIN+Y*COS
FMUL COSAngle
FSTP Temp2
FLD DWORD PTR [SI]
FMUL SINAngle
FADD Temp2
FSTP DWORD PTR [DI] ; Store Y
FLD Temp1 ; Store X
FSTP DWORD PTR [SI]
ADD SI, 4 ; Next Point
ADD DI, 4
LOOP SHORT ROTZ ; Loop Back
POPA ; Restore Registers
RET
ENDP ROTATEZ
;-=-=-=-=-=-=-=-=-=-=-=-
; Projects 3D to 2D
; In TempX, TempY
;-=-=-=-=-=-=-=-=-=-=-=-
PROJECT1 PROC
PUSHA ; Save Regsiters
XOR DX, DX
XOR AH, AH ; Set AX To Index*4
MOV BL, 4
MUL BL ; To Get Correct Offset
MOV Off, AX
MOV SI, OFFSET X
ADD SI, Off
; TempX =
FLD DWORD PTR [SI] ; X*VIEW/Z + Half Width
FMUL VIEW
FSTP TEMP1
MOV SI, OFFSET Z
ADD SI, Off
FLD DWORD PTR [SI]
FADD WORLDZ
FSTP TEMP2
FLD TEMP1
FDIV TEMP2
FADD HALFW
FISTP TEMP1 ; Store in TempX
MOV AX, Word Ptr Temp1
MOV TempX, AX
MOV SI, OFFSET Y ; TempY =
ADD SI, Off ; Half Height - Y*VIEW/Z
FLD DWORD PTR [SI]
FMUL VIEW
FSTP TEMP1
MOV SI, OFFSET Z
ADD SI, Off
FLD DWORD PTR [SI]
FADD WORLDZ
FSTP TEMP2
FLD TEMP1
FDIV TEMP2
FSTP TEMP1
FLD HALFH
FSUB TEMP1
FISTP TEMP1
MOV AX, Word Ptr Temp1
MOV TempY, AX
POPA ; Restore Registers
RET
ENDP PROJECT1
;-=-=-=-=-=-=-=-=-=-=-=-
; Projects 3D to 2D
; In TempX2, TempY2
;-=-=-=-=-=-=-=-=-=-=-=-
PROJECT2 PROC
PUSHA ; Save Regsiters
XOR DX, DX
XOR AH, AH ; Set AX To Index*4
MOV BL, 4
MUL BL ; To Get Correct Offset
MOV Off, AX
MOV SI, OFFSET X
ADD SI, Off
; TempX =
FLD DWORD PTR [SI] ; X*VIEW/Z + Half Width
FMUL VIEW
FSTP TEMP1
MOV SI, OFFSET Z
ADD SI, Off
FLD DWORD PTR [SI]
FADD WORLDZ
FSTP TEMP2
FLD TEMP1
FDIV TEMP2
FADD HALFW
FISTP TEMP1 ; Store in TempX2
MOV AX, Word Ptr Temp1
MOV TempX2, AX
MOV SI, OFFSET Y ; TempY =
ADD SI, Off ; Half Height - Y*VIEW/Z
FLD DWORD PTR [SI]
FMUL VIEW
FSTP TEMP1
MOV SI, OFFSET Z
ADD SI, Off
FLD DWORD PTR [SI]
FADD WORLDZ
FSTP TEMP2
FLD TEMP1
FDIV TEMP2
FSTP TEMP1
FLD HALFH
FSUB TEMP1
FISTP TEMP1
MOV AX, Word Ptr Temp1
MOV TempY2, AX
POPA ; Restore Registers
RET
ENDP PROJECT2
.DATA
; The Vertices
X dd 35.0, -35.0, -35.0, 35.0, 35.0, 35.0, -35.0, -35.0
Y dd 35.0, 35.0, -35.0, -35.0, 35.0, -35.0, -35.0, 35.0
Z dd 35.0, 35.0, 35.0, 35.0, -35.0, -35.0, -35.0, -35.0
; The Sides of the Cube
Face1 db 0, 1, 2, 3
Face2 db 4, 5, 6, 7
Face3 db 0, 4, 7, 1
Face4 db 3, 5, 6, 2
Face5 db 0, 3, 5, 4
Face6 db 1, 2, 6, 7
; To Change The Angle, Just Punch
; COS(x) and SIN(x)
; Then put the Numbers Down Here
; Angle = 1
; The COS(1) Angle Used
COSAngle dd 0.9998476952
; The SIN(1) Angle Used
SINAngle dd 0.0174524064
; The Rotation Status
RX db 0
RY db 0
RZ db 0
; Scaling Factor
ScaleFactor dd 1.2
; Screen Variables & View Distance
HALFW dd 160.0
HALFH dd 100.0
VIEW dd 256.0
WORLDZ dd 300.0
; Temporary Storage For Floats
Temp1 dd ?
Temp2 dd ?
Off dw ?
; The Variables Used As Screen Coordinates
TempX dw ?
TempY dw ?
TempX2 dw ?
TempY2 dw ?
; Line Algorithm Variables
DeltaX dw ?
DeltaY dw ?
Y_INC dw ?
X_INC dw ?
Error dw ?
; The Double Buffer
Buffer db 64000 DUP(?)
END START
Hi kale here is a dumb ex. of MoveEntityKale wrote: How would you distingush between camera numbers, entity numbers, etc... If they all shared one command?
Code: Select all
Graphics3D 640,480
SetBuffer BackBuffer()
camera_1=CreateCamera()
light=CreateLight()
RotateEntity light,90,0,0
; Create cube
cube_1=CreateCube()
PositionEntity cube_1,10,0,5
While Not KeyDown( 1 )
MoveEntity camera_1 ,0.1 ,0, 0
MoveEntity cube_1 ,0 ,0, 0.10
RenderWorld
Flip
Wend
End
Henrik
Do you know how a real physic environment works ? Very few coders could ever do a descent one, that's why physic SDK like ODE or HAVOK (used by HalfLife 2) exists and put in the standard command set is a must have now and will be done very quickly. If you're interested, take a look to: http://opende.sourceforge.net/ode-latest-userguide.htmlcYanide wrote:also shouldnt physics etc be left to the coders? (dont like the idea of pb turning into a kinda click n play thing like the above makes it sound)
This is a general problem in PB, and one that you won't have in 90% of all other programming languages - it comes from being forced to choose your handles manually.Kale wrote:How would you distinguish between camera numbers, entity numbers, etc... If they all shared one command?I think he was referring to a similar command for all entities (even camera). like:
Code:
MoveEntity #Camera,X,Y,Z
Imagine if commands like CreateEntity, CreateLight and CreateWhatever would RETURN a handle, instead of requiring you to CHOOSE one - this is how it works in virtually every other programming language. Now you would simply do this:
hMyCamera = CreateCamera(...)
hMyEntity = CreateEntity(...)
now your camera handle and your entity handles could be 1 and 2, or 123 and 456 - it would no longer matter what numeric values your handles have, and this is the way it SHOULD be, because:
THE NUMBERS YOU CHOOSE HAVE NO MEANING.
That's right - making you choose your handles manually simply doesn't make any sense, because the numbers don't MEAN anything - they don't carry ANY information whatsoever.
Apart from that, having to choose your own handles creates major problems for developers trying to work together on larger projects. For example, if I was writing the car routines for a racing game, and someone else was writing, say, the spectators around the racing track, and we would both start off with entity handle 1 ... we now have a major problem when we try to merge these two pieces of code - one of us will simply have to renumber all our entities.
And yes, this could be solved by having a "FirstEntityNumber" constant in both of our sources from the start, and choosing numbers like FirstEntityNumber+1, FirstEntityNumber+2 etc for our entities, but now imagine if the number of entities is UNKNOWN; say, if the number of spectators is dependent on the size of the racing track, for example ... what will you do then? leave out a gap of unused numbers, and hope that it's large enough? manage entity numbers in a linked list? whatever you do, you're going to need a serious workaround for something that should have been implemented properly from the start.
Finally, imagine if I actually need to create/delete spectators dynamically, like let's say they leave the racing track once in a while, and new ones come in. Now you're in a heap of trouble - this is not easy to implement.
As I've pointed out before, this is a serious design flaw, and unfortunately it's present everywhere in PB.
I wish someone (Fred

PS: I apologize for this slightly off-topic reply, I didn't realize I would get this far off
