I tried to generate some simple hair:
Very pretty, yes? But I have some trouble with this line:
SetObjectRotation (hairObj[hairPiece], rndFloat(0.0,200.0) , rndFloat(0.0,200.0), rndFloat(0.0,200.0)) // YXZ
I want the hair pieces to spread out upwards, covering the top of the head. But I can't get the numbers right.
// Project: test-hair
// Created: 2018-10-08
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "test-hair" )
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
SetVsync(1)
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
#constant FALSE 0
#constant TRUE 1
// The changing position of the main camera
Global screenCameraPositionX as float = 0.0
Global screenCameraPositionY as float = 1.7
Global screenCameraPositionZ as float = 0.0
// The changing rotation angles of the main camera
Global mouselookZ as float = 0.0
Global mouselookY as float = 0.0
// The last mouse position
Global mouseLastpX as float
Global mouseLastpY as float
floor = createObjectPlane (5.0, 5.0)
setObjectPosition (floor, 0.0, 0.0, 0.0)
setObjectRotation (floor, 90.0, 0.0, 0.0)
head = createObjectSphere(0.5, 12,12)
setObjectPosition (head, 0.0, 1.80, 2.0)
hairObj as integer[200]
hairPiece as integer
hairLength as float
hairAngle as float
for hairPiece = 0 to hairObj.length
hairLength = rndFloat (0.0, 0.20) + 0.20
hairObj[hairPiece] = CreateObjectCone(hairLength, 0.20, 3)
SetObjectPosition(hairObj[hairPiece], 0.0, 1.80, 2.0)
SetObjectRotation (hairObj[hairPiece], rndFloat(0.0,200.0) , rndFloat(0.0,200.0), rndFloat(0.0,200.0)) // YXZ
MoveObjectLocalY( hairObj[hairPiece], 0.2 + hairLength*0.5)
next
do
test_mouselook()
Sync()
loop
function rndFloat (numberA as float, numberB as float)
result as float
result = random(numberA*1000, numberB*1000)
result = result/1000
endfunction result
function test_mouselook()
// This function ads mouselook and WASD movement. (and Q/E to levitate)
// Hold down left mouse to rotate the camera
// Mouselook
mouseMoveX as float // The travel distance of the mouse
mouseMoveY as float
mousemoveX = GetRawMouseX()-mouseLastpX
mousemoveY = GetRawMouseY()-mouseLastpY
mouseLastpX = GetRawMouseX()
mouseLastpY = GetRawMouseY()
if GetRawMouseLeftState() = 1
mouselookZ = mouselookZ + (mousemoveX*0.5)
mouselookY = mouselookY + (mousemoveY*0.5)
endif
SetCameraRotation( 1, mouselookY, mouselookZ, 0.0)
// WASD movement
SetCameraPosition( 1, screenCameraPositionX, screenCameraPositionY, screenCameraPositionZ)
if GetRawKeyState(87) = TRUE then MoveCameraLocalZ( 1, 0.01 ) //W
if GetRawKeyState(83) = TRUE then MoveCameraLocalZ( 1, -0.01 ) //S
if GetRawKeyState(65) = TRUE then MoveCameraLocalX( 1, -0.01 ) //A
if GetRawKeyState(68) = TRUE then MoveCameraLocalX( 1, 0.01 ) //D
if GetRawKeyState(81) = TRUE then MoveCameraLocalY( 1, 0.01 ) //Q
if GetRawKeyState(69) = TRUE then MoveCameraLocalY( 1, -0.01 ) //E
screenCameraPositionZ = GetCameraZ( 1 ) // Updates the stored screen postion
screenCameraPositionX = GetCameraX( 1 ) // Updates the stored screen postion
screenCameraPositionY = GetCameraY( 1 ) // Updates the stored screen postion
endfunction