// Project: PlacementED
// Created: 19-08-01
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "PlacementED" )
SetWindowSize( 1280, 720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1280, 720 ) // doesn't have to match the window
SetOrientationAllowed( 0, 0, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
global ped_camo // for camera-oject
global ped_oList as ped_Object_Type[] // PED Object-List --> is used in the Editor-Thingly, is not flexible at this moment
/********************/
PED_SetUp()
PED_CreateOnTheFlyObjects() // creates objects in code for testing
do
PED_UpdateCamo()
object_hit = PED_getObjectHit(object_hit)
if (object_hit > 0 ) and (GetRawMouseLeftState())
Print("Click-Drag")
if object_hit >-1
SetObjectPosition(object_hit,GetObjectRayCastX(0) ,GetObjectRayCastY(0), GetObjectZ(object_hit))
// here has some work to be done
// something with GetObjectRayCastNumHits() also the selected object has to raycast to its surrounding like ground, other objects and so on.
// raycasts for 6 directions needed. Since the X,Y,Z are at this moment in the center of the object, this has to be calculated also
// so [][] a cube could collide with a cube and would stay next to it.
endif
endif
Print(PED_GetObjectName(object_hit))
Print( Str(ScreenFPS(),2) )
Sync()
loop
Function PED_CreateOnTheFlyObjects() // or they could be loaded from files
PED_AddObject("PED_Ground","Ground", MakeColor(100,100,100),MakeColor(200,200,200), 0,-.01,0,20)
PED_AddObject("PED_Cube","Pink-Cube",MakeColor(200,100,200),MakeColor(250,150,250),10,2,10,4)
PED_AddObject("PED_Cube","Blue-Cube",MakeColor(100,100,200),MakeColor(150,150,250),-5,1.5,-5,3)
PED_AddObject("PED_Cube","GREenBoXX",MakeColor( 50,230, 50),MakeColor( 50,250, 50),-5,1, 3,2)
EndFunction
//------------------------------------- Editor thingly ----------------------------------------------------------
// Types:
/********************/
Type ped_Object_Type
ID as Integer
Name$ as String
objID as Integer // 3D Object ID of the Instance
texID as Integer[7] // Diffuse, Normal and so on, for SetObjectImage()
// --> properties from the Object itself don't have to be here like CastShadow, because with the ObjectID, we could get the Value for that
// There is no GetObjectImage, so for that we need to save the texture/image IDs for that specific object
ParentObjID as Integer // this 3D Object was created from this ObjectID
// because we can't get all values from an Object-Instance, we could need like creating another Instance with CloneObject, we need also that ID
ObjectType as String // Which Script or Behavior will start if ... Player or other Object is NextTo this Object and so on ...
// as Integer, but maybe later
// Health
// Foodstep-Sound
// IsSolid?
// CanItMove?
// How-Much-Size-In-A-Bag (for RPG or so)
// CanItStack? ...
// Preview-Image ...
// TextWrittenOnObject
// ColorOfTheObject ...
// IsLight?
EndType
Type ped_Object_Source // a parent -> Default-Object, could be Standard-FPE (PreFabs)
ped_default as integer
EndType
//---------------------------------------------
Function PED_GetObjectName(object_hit)
ArrayID = PED_Search_Object(object_hit)
Name$ = ""
if ArrayID>-1 // Problem here, I have to check everytime, if the List is not empty before
Name$ = ped_oList[PED_Search_Object(object_hit)].Name$
endif
EndFunction Name$
Function PED_GetObjectPEDID(objID) // not the best naming here
ArrayID = PED_Search_Object (objID)
EndFunction ArrayID
Function PED_Search_Object(objID as integer)
ArrayID = -1
If ped_oList.length>-1
For i=0 to ped_oList.length
if ped_oList[i].objID = objID//
ArrayID = i
endif
Next
EndIf
EndFunction ArrayID
Function PED_getObjectHit(object_hit)
//object_hit = 0
pointer_X = GetRawMouseX()
pointer_Y = GetRawMouseY() // no Multitouch or Multiplayer at this moment
// get the x, y and z unit vectors based on the pointer position
unit_x# = Get3DVectorXFromScreen(pointer_x,pointer_y)
unit_y# = Get3DVectorYFromScreen(pointer_x,pointer_y)
unit_z# = Get3DVectorZFromScreen(pointer_x,pointer_y)
// calculate the start of the ray cast, which is the unit vector + the camera position
start_x# = unit_x# + GetObjectWorldX(ped_camo)
start_y# = unit_y# + GetObjectWorldY(ped_camo)
start_z# = unit_z# + GetObjectWorldZ(ped_camo)
// calculate the end of the vector, which is the unit vector multiplied by the length of the ray cast and then add the camera position to it
// if camera is far away, ray has to be longer
end_x# = 1800*unit_x# + GetObjectWorldX(ped_camo)
end_y# = 1800*unit_y# + GetObjectWorldY(ped_camo)
end_z# = 1800*unit_z# + GetObjectWorldZ(ped_camo)
// determine which object has been hit
if object_hit <> 0
SetObjectColorEmissive(object_hit,0,0,0)
endif
object_hit = ObjectRayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
if object_hit <> 0
SetObjectColorEmissive(object_hit,30,125,15)
else
endif
EndFunction object_hit
Function PED_UpdateCamo()
SetCameraPosition(1,GetObjectX(ped_camo),GetObjectY(ped_camo),GetObjectZ(ped_camo))
SetCameraRotationQuat(1,GetObjectQuatW(ped_camo),GetObjectQuatX(ped_camo),GetObjectQuatY(ped_camo),GetObjectQuatZ(ped_camo))
EndFunction
Function PED_place()
EndFunction
Function PED_SetUp()
ped_camo = CreateObjectBox(1,1,1)
SetObjectPosition(ped_camo,GetCameraX(1),GetCameraY(1),GetCameraZ(1))
SetObjectRotationQuat(ped_camo,GetCameraQuatW(1),GetCameraQuatX(1),GetCameraQuatY(1),GetCameraQuatZ(1))
EndFunction
Function PED_AddObject(PED_TypeName$ as string, Name$ as string, color1 as integer, color2 as integer, x as float, y as float, z as float, size as float)
//
temp_ped_Object as ped_Object_Type
temp_ped_Object.Name$ = Name$
//
If PED_TypeName$ = "PED_Cube" // BOX
temp_ped_Object.ObjectType = "PED_Cube"
tempImg = CreateRenderImage(128,128,0,1)
SetRenderToImage(tempImg,0)
DrawBox(0,0,GetVirtualWidth(),GetVirtualHeight(),color1,color1,color1,color1,1)
DrawBox(50,50,GetVirtualWidth()-50,GetVirtualHeight()-50,color2,color2,color2,color2,1)
SetRenderToScreen()
objID = CreateObjectBox(size,size,size)
SetObjectImage(objID,tempImg,0)
SetObjectPosition(objID, x,y,z)
temp_ped_Object.objID = objID
temp_ped_Object.texID[0] = tempImg
temp_ped_Object.ParentObjID = objID // at this moment this is not an instance, so the ParentObject is the same as the "Instance"
ped_oList.insert(temp_ped_Object)
ElseIf PED_TypeName$ = "PED_Ground"
ped_light = Color1
ped_dark = Color2
ped_img_default = CreateRenderImage(512,512,0,1) // change quality if texture is only 64 x 64
SetRenderToImage(ped_img_default,0)
xl# = 1.0+GetVirtualWidth()/5.0
yl# = 1.0+GetVirtualHeight()/5.0
For i2=0 to 4
For i=0 to 4
DrawBox(0+xl#*i,0+yl#*i2,0+xl#*i+xl#-7,0+yl#*i2+yl#-7,ped_light,ped_dark,ped_dark,ped_light,1)
Next
Next
SetRenderToScreen()
ped_obj_ground = CreateObjectPlane(size,size)
SetObjectImage(ped_obj_ground,ped_img_default,0)
SetImageWrapU(ped_img_default,1)
SetImageWrapV(ped_img_default,1)
SetObjectUVScale(ped_obj_ground,0,4,4)
SetObjectRotation(ped_obj_ground,90,0,0)
SetObjectPosition(ped_obj_ground,x,y,z)
temp_ped_Object.objID = ped_obj_ground
temp_ped_Object.texID[0] = ped_img_default
temp_ped_Object.ParentObjID = objID // at this moment this is not an instance, so the ParentObject is the same as the "Instance"
temp_ped_Object.ObjectType = "PED_Ground" // PLANE
ped_oList.insert(temp_ped_Object)
EndIf
EndFunction
I found my mistakes with the false image reference. Also created a global array for the objects.
But sliding the objects is not "perfect" now. But you can select the object and get infos about it.