new terrain editor for vr
made it my self but had a lot of help from the chap on the face book agk page
this is tested and works you need the vr pluings from agk and a vr kit (vive ,oculus,windows mixed reality kit)
a height map 32 or 16 bit not 8 bit
size 1024/1024
o ya and a texture for you map i use a grass png from goooooooglllllleeeeee
enjoy
VR TERRAIN EDITOR
// Project: memblocks terrains
// Created: 2019-04-23
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "memblocks terrains" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
//Load the AGKVR plugin
#import_plugin AGKVR
//Init App
//Hand Model ID numbers
GLOBAL RightHandModel as integer = 100
GLOBAL LeftHandModel as integer = 101
GLOBAL HandModelImg as integer = 100
//Generate Mipmaps for nicer looking textures
SetGenerateMipmaps( 1 )
//Create Skybox
SetSkyBoxHorizonColor( 200, 200, 255 )
SetSkyBoxHorizonSize( 10, 2 )
SetSkyBoxSkyColor( 50, 50, 255)
SetSkyBoxSunColor( 255,255,255 )
SetSkyBoxVisible( 1 )
SetSkyBoxSunSize( 1, 3.0 )
SetSkyBoxSunVisible( 1 )
//Load Hand Models
//---------------------------
//Right Hand
LoadObjectWithChildren(RightHandModel,"RHand.FBX")
SetObjectScale(RightHandModel,1.15,1.15,1.15)
SetObjectPosition(RightHandModel,0.0,0.0,-0.07)
SetObjectRotation(RightHandModel,0.0,180.0,90.0)
FixObjectPivot(RightHandModel)
SetObjectAnimationSpeed(RightHandModel,20)
LoadImage(HandModelImg,"Hand.png")
SetObjectImage(RightHandModel,HandModelImg,0)
SetObjectVisible(RightHandModel,0)
SetObjectCollisionMode(RightHandModel,0)
//Left Hand
LoadObjectWithChildren(LeftHandModel,"LHand.FBX")
SetObjectScale(LeftHandModel,1.15,1.15,1.15)
SetObjectPosition(LeftHandModel,0.0,0.0,-0.07)
SetObjectRotation(LeftHandModel,0.0,180.0,270.0)
FixObjectPivot(LeftHandModel)
SetObjectAnimationSpeed(LeftHandModel,20)
SetObjectImage(LeftHandModel,HandModelImg,0)
SetObjectVisible(LeftHandModel,0)
SetObjectCollisionMode(LeftHandModel,0)
//Call function to load world models
//Set the Camera Range in AGKVR
//It is necessary to use this command for setting the camera's range instead of the standard AGK SetCameraRange command
AGKVR.SetCameraRange( 0.01, 1000.0 )
//Initialiaze AGKVR
//------------------------------------------------
// The parameters are the Right and Left Eye image ID's that will be used to render to the HMD
InitError As Integer
RightEyeImg As Integer = 500
LeftEyeImg As Integer = 501
InitError = AGKVR.Init( RightEyeImg, LeftEyeImg )
// InitError = 0: SUCCESS!
// InitError = 1: Unable to init VR runtime
// InitError = 2: Compositor initialization failed.
//This command will lock the player's heading direction
//to follow the turn angle of the HMD. This would be common in FPS games, where
//you want the forward moving direction's turn angle to change based on where the
//player is looking. LockPlayerTurn is ON(1) by default
AGKVR.LockPlayerTurn( 1 )
//This command will lock the player's heading direction (forward on the Z axis)
//to follow the pitch angle of the HMD. This would be useful in a freeflight style game
//where you want the forward moving direction's pitch angle to change based on where the
//player is looking. LockPlayerPitch is OFF(0) by default
AGKVR.LockPlayerPitch( 0 )
type vertexs
x as float []
z as float []
y as float []
endtype
global vector as vertexs
global memblock
global TerrainObjectID
global width
global lenth
test=loadimage("\media\00.png")
width=GetImageWidth(test)
lenth=GetImageHeight(test)
deleteimage(test)
terrain_x=width
terrain_y=lenth
TerrainObjectID=CreateObjectFromHeightMap("\media\00.png",terrain_x,50,terrain_y,0,1) // load hieghtmap 32 bit
memblock=CreateMemblockFromObjectMesh(TerrainObjectID,1)
count=GetMemblockInt(memblock,0)
for i=0 to Count
vector.x.insert(GetMeshMemblockVertexX(memblock,i))
vector.y.insert(GetMeshMemblockVertexY(memblock,i))
vector.z.insert(GetMeshMemblockVertexZ(memblock,i))
next
SetObjectMeshFromMemblock(TerrainObjectID,1,memblock)
loadimage(2,"\media\textures\1_4.png")
SetObjectImage(TerrainObjectID,2,0)
PLANE=CreateObjectPlane(WIDTH,LENTH)
MoveObjectLocalZ(PLANE,LENTH/2)
MoveObjectLocalX(PLANE,WIDTH/2)
MoveObjectLocalY(PLANE,25)
RotateObjectLocalX(PLANE,90)
POINT=CreateObjectCylinder(1000,0.01,32)
TEST1=CreateObjectSphere(0.1,32,32)
FixObjectToObject(TEST1,POINT)
MoveObjectLocalY(TEST1,500)
TEST2=CreateObjectSphere(0.1,32,32)
FixObjectToObject(TEST2,POINT)
MoveObjectLocalY(TEST2,-500)
FixObjectToObject(POINT,RightHandModel)
RotateObjectLocalX(POINT,-20)
MoveObjectLocalY(POINT,-500)
SetObjectCollisionMode(POINT,0)
SetObjectCollisionMode(TEST1,0)
SetObjectCollisionMode(TEST2,0)
AGKVR.SetPlayerPosition( 512, 35, 512 )
X=100
Q=1000-X ///900
X=900
Z=1000-X //100
do
VR()
X1#=GetObjectWorldX(TEST1)
Y1#=GetObjectWorldY(TEST1)
Z1#=GetObjectWorldZ(TEST1)
X2#=GetObjectWorldX(TEST2)
Y2#=GetObjectWorldY(TEST2)
Z2#=GetObjectWorldZ(TEST2)
HIT= ObjectRayCast( 0, X1#, y1#, z1#, x2#, y2#, z2# )
GET_X=ROUND(GetObjectRayCastX(0))
GET_Y=ROUND(GetObjectRayCastY(0))
GET_Z=ROUND(GetObjectRayCastZ(0))
pointerState=GetRawMouseleftState()
pointerState1=GetRawMouserightState()
if AGKVR.RightController_Trigger() >0.5
ZNEW=LENTH-GET_Z
px = GET_X
py = ZNEW
IF PX>1 AND PX<lenth-25
IF PY>1 AND PY<width-25
for py1=py to py+25
for px1=px to px+25
y=py1
x=px1
i=y*width+x
vector.y[i]=vector.y[i]+1
SetMeshMemblockVertexPosition(memblock,i,vector.x[i],vector.y[i],vector.z[i]) //set height
next
next
SetObjectMeshFromMemblock(TerrainObjectID,1,memblock)
ENDIF
ENDIF
eNDIF
if pointerState1 = 1
px = GetPointerX()
py = GetPointerY()
IF PX>1 AND PX<lenth-25
IF PY>1 AND PY<width-25
for py1=py to py+25
for px1=px to px+25
y=py1
x=px1
i=y*width+x
vector.y[i]=vector.y[i]-10
SetMeshMemblockVertexPosition(memblock,i,vector.x[i],vector.y[i],vector.z[i]) //set height
next
next
SetObjectMeshFromMemblock(TerrainObjectID,1,memblock)
ENDIF
ENDIF
eNDIF
Sync()
loop
FUNCTION VR()
//Get AGKVR's Player container's current Position, which will be used later for collision purposes:
PlayerPosX as float
PlayerPosY as float
PlayerPosZ as float
PlayerPosX = AGKVR.GetPlayerX(): `
PlayerPosY = AGKVR.GetPlayerY()
PlayerPosZ = AGKVR.GetPlayerZ()
//Control Player Turn Angle with Left Controller Joystick
valx as float
valz as float
valx = AGKVR.LeftController_JoyX( )
AGKVR.RotatePlayerLocalY( valx*5 )
//Control Player Movement based on Right Controller Joystick
valx = AGKVR.RightController_JoyX( )
valz = AGKVR.RightController_JoyY( )
AGKVR.MovePlayerLocalZ( valz*5 )
AGKVR.MovePlayerLocalX( valx*5 )
//Move with the Keyboard
if GetRawKeyState(87) = 1
AGKVR.MovePlayerLocalZ( 0.1 )
endif
if GetRawKeyState(83) = 1
AGKVR.MovePlayerLocalZ( -0.1 )
endif
if GetRawKeyState(65) = 1
AGKVR.MovePlayerLocalX( -0.1 )
endif
if GetRawKeyState(68) = 1
AGKVR.MovePlayerLocalX( 0.1 )
endif
//Control Hand animation based on Trigger feedback
Rvalue as float
Lvalue as float
Rvalue = AGKVR.RightController_Trigger( )
Lvalue = AGKVR.LeftController_Trigger( )
SetObjectAnimationFrame(RightHandModel, GetObjectAnimationName( RightHandModel, 1 ), GetObjectAnimationDuration(RightHandModel,GetObjectAnimationName( RightHandModel, 1 ))*Rvalue,0)
SetObjectAnimationFrame(LeftHandModel, GetObjectAnimationName( LeftHandModel, 1 ), GetObjectAnimationDuration(LeftHandModel,GetObjectAnimationName( LeftHandModel, 1 ))*Lvalue,0)
//Now that the player's position and orientation has been modified,
//the UpdatePlayer command is called to update all the components of
//AGKVR's player framework
AGKVR.UpdatePlayer( )
//Position Hand Objects
if AGKVR.RightControllerFound( ) = 1
SetObjectPosition( RightHandModel, AGKVR.GetRightHandX(), AGKVR.GetRightHandY(), AGKVR.GetRightHandZ())
SetObjectRotation( RightHandModel, AGKVR.GetRightHandAngleX(), AGKVR.GetRightHandAngleY(), AGKVR.GetRightHandAngleZ())
SetObjectVisible( RightHandModel, 1 )
else
SetObjectVisible( RightHandModel, 0 )
endif
if AGKVR.LeftControllerFound( ) = 1
SetObjectPosition( LeftHandModel, AGKVR.GetLeftHandX(), AGKVR.GetLeftHandY(), AGKVR.GetLeftHandZ())
SetObjectRotation( LeftHandModel, AGKVR.GetLeftHandAngleX(), AGKVR.GetLeftHandAngleY(), AGKVR.GetLeftHandAngleZ())
SetObjectVisible( LeftHandModel, 1 )
else
SetObjectVisible( LeftHandModel, 0 )
endif
//This command renders to the HMD.
AGKVR.Render( )
//The camera's position and rotation will determine what is displayed on the monitor, not the HMD
SetCameraPosition( 1, AGKVR.GetHMDX(), AGKVR.GetHMDY(), AGKVR.GetHMDZ())
SetCameraRotation( 1, AGKVR.GetHMDAngleX(), AGKVR.GetHMDAngleY(), AGKVR.GetHMDAngleZ())
//Display some controller feedbacks on the monitor
if AGKVR.RightController_Grip() = 1
Print( "Right Grip Pressed" )
endif
if AGKVR.LeftController_Grip() = 1
Print( "Left Grip Pressed" )
endif
if AGKVR.LeftController_Button1() = 1
Print( "Left Button 1 Pressed" )
endif
if AGKVR.RightController_Button1() = 1
Print( "Right Button 1 Pressed" )
endif
if AGKVR.LeftController_Button2() = 1
Print( "Left Button 2 Pressed" )
endif
if AGKVR.RightController_Button2() = 1
Print( "Right Button 2 Pressed" )
endif
//Sync to update the monitor display (the HMD display is updated through AGKVR's Render Command
//so this Sync is not necessary to for rendering to the HMD)
ENDFUNCTION