Author Topic: Minecraft Funktionen - SAMMELTHREAD :)  (Read 4046 times)

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5034
  • O Rly?
    • View Profile



Hier könnt ihr alle Funktionen posten, die für einen Minecraft Clon von Bedeutung sein könnten!
Ob es nun für das Rendering oder eine einfache Routine ist.
Etvl. ergibt sich ja was gutes und ein oder zwei Projekte entstehen dadurch...

Ein richtiges 3D-Game würde GLBasic mal gut tun ;)

« Last Edit: 2012-Apr-17 by Schranz0r »
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5034
  • O Rly?
    • View Profile
Gut dann fang ich mal an!

- Facepick/Objectpick
- Kleiner visueller Debug

Code: (glbasic) [Select]
// --------------------------------- //
// Project: Linepick
// Start: Sunday, April 15, 2012
// IDE Version: 10.283


// SETCURRENTDIR("Media") // go to media files
SYSTEMPOINTER TRUE

CreateSurface()

LOCAL mx,my,b1,b2



WHILE TRUE
MOUSESTATE mx,my,b1,b2
X_MAKE3D 1,1000,45
X_CAMERA 0,10,50, 0,0,0

X_DRAWOBJ 1,0

IF PickObject(mx,my, 1,0)
DebugCollisionFace(1)
ENDIF

SHOWSCREEN
WEND
END



FUNCTION CreateSurface:
X_OBJSTART 1
X_OBJADDVERTEX 10,10,0, 0,0, RGB(0xff, 0xff, 0xff)
X_OBJADDVERTEX 10,-10,0, 0,0, RGB(0xff, 0xff, 0xff)
X_OBJADDVERTEX -10,10,0, 0,0, RGB(0xff, 0xff, 0xff)
X_OBJADDVERTEX -10,-10,0, 0,0, RGB(0xff, 0xff, 0xff)
X_OBJEND
ENDFUNCTION

FUNCTION PickObject:mousex, mousey, obj_id, frame=0 
LOCAL wx,wy,wz,wx2,wy2,wz2

X_SCREEN2WORLD mousex,mousey,0, wx,wy,wz
X_SCREEN2WORLD mousex,mousey,1, wx2,wy2,wz2

IF X_COLLISIONRAY(obj_id, frame, wx, wy, wz, (wx2-wx), (wy2-wy), (wz2-wz)) <> 0
RETURN TRUE
ENDIF

RETURN FALSE
ENDFUNCTION

FUNCTION DebugCollisionFace: obj_id

LOCAL face_id = X_GETCOLLISIONFACE()
LOCAL triangle[]
X_GETFACE obj_id, 0, face_id,triangle[]

FOR i = 0 TO 2
IF i = 2

X_LINE triangle[i][0], triangle[i][1], triangle[i][2],triangle[0][0], triangle[0][1], triangle[0][2],2, RGB(0xff, 0x00, 0x00)

ELSE

X_LINE triangle[i][0], triangle[i][1], triangle[i][2],triangle[i+1][0], triangle[i+1][1], triangle[i+1][2],2, RGB(0xff, 0x00, 0x00)

ENDIF

X_DOT triangle[i][0], triangle[i][1], triangle[i][2], 10,RGB(0x00, 0x00, 0xff)

NEXT 

ENDFUNCTION

[attachment deleted by admin]
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5034
  • O Rly?
    • View Profile
Re: Minecraft Funktionen - SAMMELTHREAD :)
« Reply #2 on: 2012-Apr-17 »
Movement in 3D ist nicht so einfach zu realisieren vorallen nicht in GLB :)
Hier ein Basicmovement für Platformspiele in 3D.

Sollte man das noch in Funktionen packen, was denkt ihr?

Code: (glbasic) [Select]
InitMovement()

LOCAL ScreenX%=800, ScreenY%=600
SETSCREEN ScreenX,ScreenY,0

WHILE TRUE
SETMOUSE ScreenX/2, ScreenY/2
X_MAKE3D 1,1000,45
SetCamera()
DoMovement()

FOR i = 0 TO 10

X_DRAWAXES 0,0,i*100

NEXT

SHOWSCREEN
WEND
END


FUNCTION InitMovement:
GLOBAL phi_xy#=0, phi_xz#=90.0, Cam_x#=0, Cam_y#=0, Cam_z#=100, Cam_Speed#=1.8
ENDFUNCTION

FUNCTION SetCamera:
// Cam on x,y,z
X_CAMERA Cam_x,Cam_y,Cam_z, Cam_x+COS(phi_xz),Cam_y+SIN(-phi_xy),Cam_z+SIN(phi_xz)
ENDFUNCTION

FUNCTION DoMovement:
// pick the mouseaxis
LOCAL MA0 = MOUSEAXIS(0)
LOCAL MA1 = MOUSEAXIS(1)

//rotate smoothe
IF MA0 <> 0
INC phi_xz,MA0/10
ENDIF
IF MA1 <> 0
INC phi_xy,MA1/10
ENDIF

// only 360°
IF phi_xz > 359 THEN phi_xz = 0
IF phi_xz < 0 THEN phi_xz = 359

// Limit the up/down
IF phi_xy < -89.9 THEN phi_xy = -89.9
IF phi_xy > 89.9  THEN phi_xy = 89.9

IF KEY(42) // if shift pressed then run :)
Cam_Speed = 1.8
ELSE
Cam_Speed = 1 // set back to normal
ENDIF

IF KEY(17) // forward
INC Cam_z,SIN(phi_xz)*Cam_Speed
INC Cam_x,COS(phi_xz)*Cam_Speed
ENDIF
IF KEY(31) // back
DEC Cam_z,SIN(phi_xz)*Cam_Speed
DEC Cam_x,COS(phi_xz)*Cam_Speed
ENDIF
IF KEY(30) // left
INC Cam_z,SIN(phi_xz-90)*(Cam_Speed/2)
INC Cam_x,COS(phi_xz-90)*(Cam_Speed/2)
ENDIF
IF KEY(32) // right
INC Cam_z,SIN(phi_xz+90)*(Cam_Speed/2)
INC Cam_x,COS(phi_xz+90)*(Cam_Speed/2)
ENDIF
ENDFUNCTION



[attachment deleted by admin]
« Last Edit: 2012-Apr-17 by Schranz0r »
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: Minecraft Funktionen - SAMMELTHREAD :)
« Reply #3 on: 2012-Apr-17 »
Mach doch mal nen T3dCamera - Type draus. :) Das wäre super!

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5034
  • O Rly?
    • View Profile
Re: Minecraft Funktionen - SAMMELTHREAD :)
« Reply #4 on: 2012-Apr-17 »
damit man mehrere Cams benutzen kann?

EDIt:

Ich installier mir schnell Skype  :D
« Last Edit: 2012-Apr-17 by Schranz0r »
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: Minecraft Funktionen - SAMMELTHREAD :)
« Reply #5 on: 2012-Apr-17 »
Eigentlich meinte ich, damit man sauber alle Funktionen und Variablen in einem Type hat.
Dann brauchste nur noch sagen "Kamera, bewege dich und drehe dich" und bums, passiert es. :D

Und man braucht keine "Angst" haben, dass man Variablen im eigenen Code verwendet, den die Cam benutzt.

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: Minecraft Funktionen - SAMMELTHREAD :)
« Reply #6 on: 2012-Apr-17 »
Falls ihr nicht alles neu schreiben wollt, ich habe da noch etwas alten Code rumliegen, habe ich mal zum einfachen bewegen von 3D Objekten geschrieben (Mathe ist im wesentlichen aus dem 3DES kopiert). Siehe ESlight_old.zip

Später habe ich das ganze dann zu einem richtigen, kleinen EntitySystem erweitert. Siehe ESlite.zip

Das erste ist einfach und kurz und sollte genau das enthalten, was ihr braucht - jedoch ist es ein sehr alter Stand, der längst gefixte Fehler enthält und bei dem ich nicht genau weiß, auf welchem Stand er überhaupt ist... Das zweite ist dagegen deutlich ausgereifter, aber als kleines EntitySystem eben auch deutlich umfangreicher, als ihr es vielleicht braucht. Außerdem ist auch das noch ganz stark WIP.
Aber vielleicht nützt es euch ja etwas und ihr könnt einfacher euer eigenes erstellen?

[attachment deleted by admin]
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5034
  • O Rly?
    • View Profile
Re: Minecraft Funktionen - SAMMELTHREAD :)
« Reply #7 on: 2012-Apr-17 »
Hmm danke, aber ich machs lieber step by step
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5034
  • O Rly?
    • View Profile
Re: Minecraft Funktionen - SAMMELTHREAD :)
« Reply #8 on: 2012-Sep-01 »
Chunks mit kleinen problem, übler Flaschenhals in der Objekterstellungsroutine...

mainfile
Code: (glbasic) [Select]
// --------------------------------- //
// Project: Faces and Cubes
// Start: Saturday, September 01, 2012
//
// by Schranz0r
//
// www.glbasic.com
//
// IDE Version: 10.283



// All corners for a cube

// FRONT:

// 1-------3
//  | |
//  | |
//  | |
//  | |
// 2-------4

// BACK:

// 5-------7
//  | |
//  | |
//  | |
//  | |
// 6-------8

GLOBAL V1 AS TVector
V1.SET(.5,.5,-.5)
GLOBAL V2 AS TVector
V2.SET(.5,-.5,-.5)
GLOBAL V3 AS TVector
V3.SET(-.5,.5,-.5)
GLOBAL V4 AS TVector
V4.SET(-.5,-.5,-.5)

GLOBAL V5 AS TVector
V5.SET(.5,.5,.5)
GLOBAL V6 AS TVector
V6.SET(.5,-.5,.5)
GLOBAL V7 AS TVector
V7.SET(-.5,.5,.5)
GLOBAL V8 AS TVector
V8.SET(-.5,-.5,.5)


// Create the surfaces with the vectors
GLOBAL SURFACE_FRONT AS TSurface
SURFACE_FRONT.SET(V1,V2,V3,V4)
GLOBAL SURFACE_BACK AS TSurface
SURFACE_BACK.SET(V5,V6,V7,V8)
GLOBAL SURFACE_LEFT AS TSurface
SURFACE_LEFT.SET(V5,V6,V1,V2)
GLOBAL SURFACE_RIGHT AS TSurface
SURFACE_RIGHT.SET(V3,V4,V7,V8)
GLOBAL SURFACE_TOP AS TSurface
SURFACE_TOP.SET(V5,V1,V7,V3)
GLOBAL SURFACE_BOTTOM AS TSurface
SURFACE_BOTTOM.SET(V6,V2,V8,V4)


// create a testchunk
GLOBAL TESTCHUNK AS TChunk
TESTCHUNK.Test_Chunk() // set something in the chunk
TESTCHUNK.Set_Surfaces() // place the surfaces to create the empty shell!
TESTCHUNK.CREATE_CHUNK_OBJ() // create the object so we can render it

// var for a simple rotation
LOCAL phi
WHILE TRUE
// simple 3D-Stuff :D
X_MAKE3D 0.0001, 1000, 45
X_CAMERA 0,30,-30, 0,0,0

// increase the rotation
INC phi, .5

// for orientation we draw a axes
X_DRAWAXES 0,0,0

// rotate
X_ROTATION phi, 1,1,1

//draw our testchunk
X_DRAWOBJ TESTCHUNK.chunk_ID, 0

// flip that crap to the screen :D
SHOWSCREEN
WEND
END


surface.gbas
Code: (glbasic) [Select]
// --------------------------------- //
// Project: Faces and Cubes
// Start: Saturday, September 01, 2012
// IDE Version: 10.283


// Vector Type
TYPE TVector
x#;y#;z# // 3D Position
FUNCTION SET: x#, y#, z# // set position
self.x = x
self.y = y
self.z = z
ENDFUNCTION
ENDTYPE


// Surface Type
TYPE TSurface
vec[4] AS TVector // 4 vectors in a surface
FUNCTION SET: v1 AS TVector, v2 AS TVector, v3 AS TVector, v4 AS TVector // set surface
self.vec[0] = v1
self.vec[1] = v2
self.vec[2] = v3
self.vec[3] = v4
ENDFUNCTION
ENDTYPE

// Pewwww.... the Chunk-Crap!
// from now on i hate chunks!
TYPE TChunk
chunksize_x%=20; chunksize_y%=20; chunksize_z%=20 // chunksize x,y,z to keep the dynamic
faces[] AS TSurface // "open" array to store all surfaces we need in this chunk
chunk%[] // the chunkarray, here we have normal integers! Example: 0,1,0,1,1,1,2,3...
chunk_ID% // the modelID of the chunk to create the object and draw it
FUNCTION Test_Chunk: // lets test the CHUNK!
REDIM self.chunk[self.chunksize_x+2][self.chunksize_y+2][self.chunksize_z+2] // Resize the array, and make it 2,2,2 bigger (1 left, 1 right, 1 top, 1 bottom, 1 front, 1 back) thats easier for us to handle

FOR x = 1 TO self.chunksize_x // all 6 sides must be empty! Thats why 1 to chunksize !
FOR y = 1 TO self.chunksize_x
FOR z = 1 TO self.chunksize_x
self.chunk[x][y][z] = RND(1) // fill in some "stones"(what ever...) :D
NEXT
NEXT
NEXT

ENDFUNCTION

FUNCTION Set_Surfaces:

FOR x = 1 TO self.chunksize_x // the 6 sides are empty, so we don't care! (1 to chunksize)
FOR y = 1 TO self.chunksize_y
FOR z = 1 TO self.chunksize_z
IF self.chunk[x][y][z] = 1 // is this block not empty, we have a "stone"-Block
IF self.chunk[x][y+1][z] = 0  //check up
DIMPUSH self.faces[], SURFACE_TOP
self.SET_FACE_OFFSET(LEN(self.faces[])-1,x-self.chunksize_x/2,y-self.chunksize_y/2,z-self.chunksize_z/2) // set the offset of the surface, and center the chunk!
ENDIF
IF self.chunk[x][y-1][z] = 0  //check down
DIMPUSH self.faces[], SURFACE_BOTTOM
self.SET_FACE_OFFSET(LEN(self.faces[])-1,x-self.chunksize_x/2,y-self.chunksize_y/2,z-self.chunksize_z/2) // same shit again
ENDIF
IF self.chunk[x+1][y][z] = 0  //check left
DIMPUSH self.faces[], SURFACE_LEFT
self.SET_FACE_OFFSET(LEN(self.faces[])-1,x-self.chunksize_x/2,y-self.chunksize_y/2,z-self.chunksize_z/2) // and again
ENDIF
IF self.chunk[x-1][y][z] = 0  //check right
DIMPUSH self.faces[], SURFACE_RIGHT
self.SET_FACE_OFFSET(LEN(self.faces[])-1,x-self.chunksize_x/2,y-self.chunksize_y/2,z-self.chunksize_z/2) // and again
ENDIF
IF self.chunk[x][y][z-1] = 0  //check before
DIMPUSH self.faces[], SURFACE_FRONT
self.SET_FACE_OFFSET(LEN(self.faces[])-1,x-self.chunksize_x/2,y-self.chunksize_y/2,z-self.chunksize_z/2) // ahhhh i'm tired
ENDIF
IF self.chunk[x][y][z+1] = 0  //check behind
DIMPUSH self.faces[], SURFACE_BACK
self.SET_FACE_OFFSET(LEN(self.faces[])-1,x-self.chunksize_x/2,y-self.chunksize_y/2,z-self.chunksize_z/2) // HA! now its done! we check all six sides if there a empty("AIR"/nothing) Block
ENDIF // and set a surface in this direction to create the "empty shell"
ENDIF
NEXT
NEXT
NEXT

ENDFUNCTION

FUNCTION SET_FACE_OFFSET: surfacenum, x%, y%, z% // offset the surface and tweak it -0.5 to set it into the "real" center... maybe we remove the centershit... if we dont need it?!
FOR i = 0 TO 3
INC self.faces[surfacenum].vec[i].x, x-.5
INC self.faces[surfacenum].vec[i].y, y-.5
INC self.faces[surfacenum].vec[i].z, z-.5
NEXT
ENDFUNCTION

// here we have a HUGE!!!!! bottleneck!!!!!!!!
FUNCTION CREATE_CHUNK_OBJ: // with this function we create the 3D-Object
self.chunk_ID = GENX_OBJ() // get a free object-ID
X_OBJSTART self.chunk_ID // start the magic
FOREACH t IN self.faces[] // loop all the surfaces
X_OBJNEWGROUP // every surface we need a new group
FOR i = 0 TO 3 // 4 corners per surface
X_OBJADDVERTEX t.vec[i].x, t.vec[i].y, t.vec[i].z, 0,0, RGB(0xc0, 0xc0, 0xc0)+RND(40) //set the Vertex
NEXT

NEXT
X_OBJEND // end of the magic
ENDFUNCTION

ENDTYPE



I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard