Опять налажал с текстурами. И аллокатор изображений опять поломался. Из хорошего: в r4 можно ходить по полю

This commit is contained in:
Андреев Григорий 2025-12-30 18:54:47 +03:00
parent 85ea80f916
commit 238a3653e8
13 changed files with 141 additions and 151 deletions

View File

@ -11,6 +11,7 @@ Callbacks(..), aliceMainloop, newAlice, aliceSetSkyColor, aliceNewLucyFace,
aliceLucyFaceOfSize, lucyFaceAddGlyphs, aliceClearText, aliceAddText,
aliceAddGenericMeshHand, aliceGenericMeshResizeInstanceArr, aliceGenericMeshSetInst,
aliceAddShinyMeshHand, aliceShinyMeshResizeInstanceArr, aliceShinyMeshSetInst, aliceGetCamBack,
aliceGetCamRight, aliceGetCamUp, aliceSetFOV,
aliceGetCamPos, aliceSetCamPos, aliceSetPointLightCount, aliceSetPointLight,
aliceIsPressed
) where
@ -22,7 +23,6 @@ import Data.Int (Int8, Int16, Int32, Int64)
import Foreign.Ptr (Ptr, FunPtr, nullPtr, plusPtr, castPtr)
import Foreign.Marshal.Alloc (alloca)
import Foreign.Storable (Storable(..))
import Data.IORef (newIORef, readIORef, writeIORef, modifyIORef)
import qualified Data.Text
import Data.Text.Encoding (encodeUtf8)
import Data.ByteString (useAsCStringLen)
@ -97,17 +97,6 @@ aliceMainloop alice cb = alloca $ \ptr -> do
poke ptr cb
allieAliceMainloop alice ptr
--aliceClearScreenTextLabel :: AliceAnotherFrameCap s -> IO ()
--aliceClearScreenTextLabel (AliceAnotherFrameCap alice) = allieAliceClearScreenText alice
--aliceAddScreenTextLabel :: AliceAnotherFrameCap s -> String -> IO ()
--aliceAddScreenTextLabel (AliceAnotherFrameCap alice) str = useAsCStringLen
-- (encodeUtf8 $ Data.Text.pack $ str) $ \(cstr, len) ->
-- allieAliceAddScreenTextLabel alice (castPtr cstr) (fromIntegral len)
--allieRunAlice :: Callbacks ->
useAsUtf8StringLen :: String -> (Ptr Word8 -> Word64 -> IO a) -> IO a
useAsUtf8StringLen str cb = useAsCStringLen (encodeUtf8 $ Data.Text.pack $ str) $ \(cstr, len) -> cb (castPtr cstr) (fromIntegral len)
@ -180,7 +169,20 @@ aliceGetCamBack alice = alloca $ \ptr -> do
allie_alice_get_cam_back alice ptr
peek ptr
-- todo: add right and up
foreign import ccall "allie_alice_get_cam_right" allie_alice_get_cam_right :: Alice -> Ptr Vec3 -> IO ()
aliceGetCamRight :: Alice -> IO Vec3
aliceGetCamRight alice = alloca $ \ptr -> do
allie_alice_get_cam_right alice ptr
peek ptr
foreign import ccall "allie_alice_get_cam_up" allie_alice_get_cam_up :: Alice -> Ptr Vec3 -> IO ()
aliceGetCamUp :: Alice -> IO Vec3
aliceGetCamUp alice = alloca $ \ptr -> do
allie_alice_get_cam_up alice ptr
peek ptr
foreign import ccall "allie_alice_get_cam_pos" allie_alice_get_cam_pos :: Alice -> Ptr Vec3 -> IO ()
@ -194,6 +196,9 @@ foreign import ccall "allie_alice_set_cam_pos" allie_alice_set_cam_pos :: Alice
aliceSetCamPos :: Alice -> Vec3 -> IO ()
aliceSetCamPos alice (Vec3 x y z) = allie_alice_set_cam_pos alice x y z
-- Easy mapping
foreign import ccall "allie_alice_set_fov" aliceSetFOV :: Alice -> Float -> IO ()
-- Maps well
foreign import ccall "allie_alice_set_point_light_count" aliceSetPointLightCount :: Alice -> Int -> IO ()

View File

@ -1,4 +1,5 @@
module Geom(Vec2(..), Vec3(..), Vec4(..), Mat4(..), Addable(..), Multipliable(..), mat4Transit) where
module Geom(Vec2(..), Vec3(..), Vec4(..), Mat4(..), Addable(..), Multipliable(..), mat4Transit, mat4rot3d,
HasLength, normalize) where
import Foreign.Storable(Storable(..))
import Foreign.Ptr (Ptr, castPtr, plusPtr)
@ -43,10 +44,24 @@ instance Multipliable Vec4 Float Vec4 where
data Mat4 = Mat4 !Vec4 !Vec4 !Vec4 !Vec4
instance Multipliable Mat4 Vec4 Vec4 where
(Mat4 vx vy vz vw) ^*^ (Vec4 ax ay az aw) = (vx ^*^ ax ^+^ vy ^*^ ay ^+^ vz ^*^ az ^+^ vw ^*^ aw)
instance Multipliable Mat4 Mat4 Mat4 where
m ^*^ (Mat4 bx by bz bw) = Mat4 (m ^*^ bx) (m ^*^ by) (m ^*^ bz) (m ^*^ bw)
mat4Transit :: Vec3 -> Mat4
mat4Transit (Vec3 x y z) = Mat4 (Vec4 1 0 0 0) (Vec4 0 1 0 0) (Vec4 0 0 1 0) (Vec4 x y z 1)
mat4rot3d :: Vec3 -> Float -> Mat4
mat4rot3d (Vec3 rx ry rz) a = let cosa = cos(a) in let sina = sin(a) in
Mat4
(Vec4 (rx * rx * (1 - cosa) + cosa) (rx * ry * (1 - cosa) + sina * rz) (rx * rz * (1 - cosa) - sina * ry) 0)
(Vec4 (rx * ry * (1 - cosa) - sina * rz) (ry * ry * (1 - cosa) + cosa) (ry * rz * (1 - cosa) + sina * rx) 0)
(Vec4 (rx * rz * (1 - cosa) + sina * ry) (ry * rz * (1 - cosa) - sina * rx) (rz * rz * (1 - cosa) + cosa) 0)
(Vec4 0 0 0 1)
instance Storable Vec2 where
sizeOf _ = 2 * sizeOf (undefined :: Float)
@ -112,4 +127,13 @@ instance Storable Mat4 where
poke (castPtr ptr) v1
poke (ptr `plusPtr` vec4Size) v2
poke (ptr `plusPtr` (2 * vec4Size)) v3
poke (ptr `plusPtr` (3 * vec4Size)) v4
poke (ptr `plusPtr` (3 * vec4Size)) v4
class HasLength a where
vlength :: a -> Float
normalize :: (Multipliable a Float a, HasLength a) => a -> a
normalize v = v ^*^ (1 / (vlength v))
instance HasLength Vec2 where
vlength (Vec2 a b) = sqrt (a * a + b * b)

View File

@ -1395,83 +1395,6 @@ void recreate_swapchain(Alice *alice) {
alice->swfb = new_swfb;
}
// todo: delete it
/* It is just a stupid example */
void update_state(Alice* alice) {
float fl = AliceWaylandApp_get_elapsed_time(&alice->wl);
// todo: ok, maybe I don't want an example. I am good enough
// if (alice->wl.first_0x80_keys[XKB_KEY_w])
// CamControlInfo_forward(&alice->scene.cam, fl);
// if (alice->wl.first_0x80_keys[XKB_KEY_s])
// CamControlInfo_backward(&alice->scene.cam, fl);
// if (alice->wl.first_0x80_keys[XKB_KEY_a])
// CamControlInfo_left(&alice->scene.cam, fl);
// if (alice->wl.first_0x80_keys[XKB_KEY_d])
// CamControlInfo_right(&alice->scene.cam, fl);
// if (alice->wl.first_0x80_keys[XKB_KEY_q])
// CamControlInfo_down(&alice->scene.cam, fl);
// if (alice->wl.first_0x80_keys[XKB_KEY_e])
// CamControlInfo_up(&alice->scene.cam, fl);
//
// if (alice->wl.first_0x80_keys[XKB_KEY_bracketright]) {
// for (size_t i = 0; i < alice->scene.smeshnyavka_3.len; i++) {
// ObjectInfo* oi = &alice->scene.smeshnyavka_3.buf[i];
// vec3 p1 = alice->scene.cam.pos;
// vec3 r = vec3_normalize(vec3_minus_vec3(p1, oi->pos));
// oi->rotation = mat3_mul_mat3(marie_3d_rot_mat3(r, fl * 0.7f), oi->rotation);
// Scene_update_smeshnyavka_3(&alice->scene, i);
// }
// }
// if (alice->wl.first_0x80_keys[XKB_KEY_bracketleft]) {
// for (size_t i = 0; i < alice->scene.smeshnyavka_1.len; i++) {
// ObjectInfo* oi = &alice->scene.smeshnyavka_1.buf[i];
// oi->rotation = mat3_mul_mat3(marie_3d_rot_mat3((vec3){0, 0, 1}, fl * 0.4f), oi->rotation);
// Scene_update_smeshnyavka_1(&alice->scene, i);
// }
// }
// if (alice->wl.first_0x80_keys[XKB_KEY_minus]) {
// for (size_t i = 0; i < alice->scene.smeshnyavka_3.len; i++) {
// ObjectInfo* oi = &alice->scene.smeshnyavka_3.buf[i];
// vec3 p1 = alice->scene.cam.pos;
// float dist = vec3_length(vec3_minus_vec3(p1, oi->pos));
// float fac = 80/dist;
// oi->scale *= (1 - 0.01f * fl * fac);
// Scene_update_smeshnyavka_3(&alice->scene, i);
// }
// }
// if (alice->wl.first_0x80_keys[XKB_KEY_equal]) {
// for (size_t i = 0; i < alice->scene.smeshnyavka_3.len; i++) {
// ObjectInfo* oi = &alice->scene.smeshnyavka_3.buf[i];
// vec3 p1 = alice->scene.cam.pos;
// float dist = vec3_length(vec3_minus_vec3(p1, oi->pos));
// float fac = 80/dist;
// oi->scale *= (1 + 0.01f * fl * fac);
// Scene_update_smeshnyavka_3(&alice->scene, i);
// }
// }
//
// {
// GenericModelOnSceneMem* model = VecGenericModelOnSceneMem_mat(&alice->scene.generic_models, 0);
// assert(model->instance_attr.count >= 1);
// if (alice->wl.first_0x80_keys[XKB_KEY_j]) {
// alice->scene.smeshnyavka_1.buf[0].pos.x -= fl;
// Scene_update_smeshnyavka_1(&alice->scene, 0);
// }
// if (alice->wl.first_0x80_keys[XKB_KEY_k]) {
// alice->scene.smeshnyavka_1.buf[0].pos.z -= fl;
// Scene_update_smeshnyavka_1(&alice->scene, 0);
// }
// if (alice->wl.first_0x80_keys[XKB_KEY_l]) {
// alice->scene.smeshnyavka_1.buf[0].pos.z += fl;
// Scene_update_smeshnyavka_1(&alice->scene, 0);
// }
// if (alice->wl.first_0x80_keys[XKB_KEY_semicolon]) {
// alice->scene.smeshnyavka_1.buf[0].pos.x += fl;
// Scene_update_smeshnyavka_1(&alice->scene, 0);
// }
// }
}
/* It creates image views, descriptor sets, framebuffers. But not for generic models.
* If we ever gonna do defragmentation, this step would have to be repeated */
void alice_create_mem_dependant_vk_obj(Alice* alice){
@ -2046,7 +1969,8 @@ Alice* Alice_new(){
alice->dev_local_images = MargaretImgAllocator_new(alice->device, alice->physical_device,
mem_type_id_device_local, 16);
// todo: aAAAAND. We have some bug related to allocating stuff on block. This is very bad
// todo: hope will fix this night. Because this is VERY BAD
alice->jane = Jane_alice_create(alice->device);
/* Luckily, swapchain image allocation is not managed by me */
@ -2236,26 +2160,6 @@ void allie_alice_shiny_mesh_resize_instance_arr(Alice* alice, ListNodeAliceShiny
AliceShinyMeshHand_resize_instance_arr(alice, &mesh_hand->el, new_count);
}
// void allie_alice_generic_mesh_set_inst(
// ListNodeAliceGenericMeshHand* mesh_hand, U64 index,
// float xx, float xy, float xz, float xw, float yx, float yy, float yz, float yw,
// float zx, float zy, float zz, float zw, float wx, float wy, float wz, float ww){
// AliceGenericMeshHand_set_inst(&mesh_hand->el, index, (GenericMeshInstanceInc){.model_t = {
// .x = {xx, xy, xz, xw}, .y = {yx, yy, yz, yw}, .z = {zx, zy, zz, zw}, .w = {wx, wy, wz, ww},
// }});
// }
//
// void allie_alice_shiny_mesh_set_inst(
// ListNodeAliceGenericMeshHand* mesh_hand, U64 index,
// float xx, float xy, float xz, float xw, float yx, float yy, float yz, float yw,
// float zx, float zy, float zz, float zw, float wx, float wy, float wz, float ww,
// float clr_off_x, float clr_off_y, float clr_off_z, float clr_off_w,
// float clr_on_x, float clr_on_y, float clr_on_z, float clr_on_w){
// AliceShinyMeshHand_set_inst(&mesh_hand->el, index, (ShinyMeshInstanceInc){.model_t = {
// }, .color_on = {}});
//
// }
void allie_alice_generic_mesh_set_inst(
ListNodeAliceGenericMeshHand* mesh_hand, U64 index, const GenericMeshInstanceInc* inst){
AliceGenericMeshHand_set_inst(&mesh_hand->el, index, *inst);
@ -2287,7 +2191,7 @@ void allie_alice_set_cam_pos(Alice* alice, float x, float y, float z){
}
void allie_alice_set_fov(Alice* alice, float fov){
alice->cam_info.cam.fov = fov;
alice->cam_info.cam.fov = MIN_float(MAX_float(fov, 0.001), M_PIf - 0.01);
}
void allie_alice_set_point_light_count(Alice* alice, int new_count){

View File

@ -685,6 +685,14 @@ MarieTriangle restore_triangle_from_mesh_topology(const VecGenericMeshVertexInc*
};
}
void r4_generate_flat_normal_map(VecU8 save_path){
TextureDataR8G8B8A8 normal = TextureDataR8G8B8A8_new(1, 1);
*TextureDataR8G8B8A8_mat(&normal, 0, 0) = compress_normal_vec_into_norm_texel((vec3){0, 1, 0});
TextureDataR8G8B8A8_write_to_png_nofail(&normal, VecU8_to_span(&save_path));
VecU8_drop(save_path);
TextureDataR8G8B8A8_drop(normal);
}
/* r is radius, w is length of cylinder. Will write everything into files for us */
void r4_asset_gen_generic_mesh_cylinder(float s_resol, float r, float w, U32 k,
VecU8 path_to_mesh, VecU8 path_to_template_tex, VecU8 path_to_normal_tex){
@ -791,13 +799,8 @@ void r4_asset_gen_generic_mesh_cylinder(float s_resol, float r, float w, U32 k,
VecU8_drop(path_to_template_tex);
TextureDataR8G8B8A8_drop(template);
/* Here I generate normal tex trivially. */
TextureDataR8G8B8A8 normal = TextureDataR8G8B8A8_new(1, 1);
*TextureDataR8G8B8A8_mat(&normal, 0, 0) = compress_normal_vec_into_norm_texel((vec3){0, 1, 0});
/* Right now it's just a pixel... */
TextureDataR8G8B8A8_write_to_png_nofail(&normal, VecU8_to_span(&path_to_normal_tex));
VecU8_drop(path_to_normal_tex);
TextureDataR8G8B8A8_drop(normal);
r4_generate_flat_normal_map(path_to_normal_tex);
}
void r4_asset_gen_generic_mesh_quad(float width, float length, VecU8 path_to_save){
@ -887,10 +890,11 @@ int gen_assets_for_r4() {
alice_write_shiny_mesh_to_file(generate_shiny_cube(0.3f), vcstr("l2/models/cube.AliceShinyMesh"));
alice_write_shiny_mesh_to_file(generate_shiny_lamp(0.3f, 0.13f, 0.19f), vcstr("l2/models/lamp.AliceShinyMesh"));
r4_asset_gen_generic_mesh_quad(10, 10, vcstr("l2/models/quad.AliceGenericMesh"));
r4_asset_gen_generic_mesh_cylinder(200, 0.4f, 0.06f, 5, vcstr("l2/models/puck.AliceGenericMesh"),
r4_asset_gen_generic_mesh_cylinder(200, 0.4f, 0.17f, 30, vcstr("l2/models/puck.AliceGenericMesh"),
vcstr("l2/textures/puck_TEMPLATE.png"), vcstr("l2/textures/puck_NORMAL.png"));
r4_asset_gen_generic_mesh_cylinder(80, 0.13f, 1.5f, 4, vcstr("l2/models/stick.AliceGenericMesh"),
r4_asset_gen_generic_mesh_cylinder(100, 0.04f, 1.5f, 4, vcstr("l2/models/stick.AliceGenericMesh"),
vcstr("l2/textures/stick_TEMPLATE.png"), vcstr("l2/textures/stick_NORMAL.png"));
r4_generate_flat_normal_map(vcstr("l2/textures/flat_NORMAL.png"));
return 0;
}

View File

@ -241,11 +241,11 @@ void MargaretBufAllocator_free(MargaretBufAllocator* self, MargaretSubbuf alloca
bool eret = BufRBTree_MapU64ToU64_erase(&allocation.block->occupants, allocation.start);
assert(eret);
MargaretBufAllocator_debug(self);
// MargaretBufAllocator_debug(self);
}
NODISCARD MargaretSubbuf MargaretBufAllocator_alloc(MargaretBufAllocator* self, U64 req_size){
MargaretBufAllocator_debug(self);
// MargaretBufAllocator_debug(self);
req_size = margaret_bump_buffer_size_to_alignment(req_size, self->alignment_exp);
VkPhysicalDeviceMaintenance3Properties maintenance3_properties = {
@ -270,11 +270,11 @@ NODISCARD MargaretSubbuf MargaretBufAllocator_alloc(MargaretBufAllocator* self,
new_block->occupation_counter = req_size;
bool iret = BufRBTree_MapU64ToU64_insert(&new_block->occupants, 0, req_size);
assert(iret);
MargaretBufAllocator_debug(self);
// MargaretBufAllocator_debug(self);
return (MargaretSubbuf){.block = &self->blocks.first->el, 0, req_size};
}
MargaretBufAllocator__put_buf_to_a_gap(self, free_gap.some, req_size);
MargaretBufAllocator_debug(self);
// MargaretBufAllocator_debug(self);
return (MargaretSubbuf){.block = free_gap.some.block, .start = free_gap.some.start, req_size};
}
@ -305,7 +305,7 @@ NODISCARD MargaretSubbuf MargaretBufAllocator_expand(
if (allocation->start + bigger_size > right_free_space.start + right_free_space.len){
return MargaretBufAllocator_alloc(self, bigger_size);
}
MargaretBufAllocator_debug(self);
// MargaretBufAllocator_debug(self);
MargaretBufAllocator__erase_gap(self, allocation->block, right_free_space.start, right_free_space.len);
MargaretBufAllocator__insert_gap(self, allocation->block,
allocation->start + bigger_size,
@ -315,7 +315,7 @@ NODISCARD MargaretSubbuf MargaretBufAllocator_expand(
U64 my_it = BufRBTree_MapU64ToU64_find(&allocation->block->occupants, allocation->start);
assert(my_it > 0 && my_it <= allocation->block->occupants.el.len);
allocation->block->occupants.el.buf[my_it - 1].value = bigger_size;
MargaretBufAllocator_debug(self);
// MargaretBufAllocator_debug(self);
return (MargaretSubbuf){0};
}
@ -342,9 +342,9 @@ void MargaretBufAllocator_expand_or_move_old_host_visible(
memcpy(MargaretSubbuf_get_mapped(&maybe_bigger), MargaretSubbuf_get_mapped(allocation), allocation->len);
MargaretBufAllocator_free(self, *allocation);
*allocation = maybe_bigger;
MargaretBufAllocator_debug(self);
// MargaretBufAllocator_debug(self);
}
MargaretBufAllocator_debug(self);
// MargaretBufAllocator_debug(self);
}
/* It tries to expand buffer, but if it fails, it creates a freshly-new buffer. It

View File

@ -333,6 +333,7 @@ void MargaretImgAllocator__insert_gap(MargaretImgAllocator* self, U64 block_id,
void MargaretImgAllocator__add_block(MargaretImgAllocator* self, U64 capacity){
VkDeviceMemory memory;
printf("DEBUG MargaretImgAllocator: allocating block of size %lu\n", capacity);
check(vkAllocateMemory(self->device, &(VkMemoryAllocateInfo){
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.allocationSize = capacity, .memoryTypeIndex = self->memory_type_id
@ -486,10 +487,13 @@ NODISCARD MargaretImgAllocation MargaretImgAllocator__alloc(
MargaretMemFreeSpaceManager_search(&self->mem_free_space, alignment_exp, mem_requirements.size);
if (free_gap.variant == Option_None) {
// todo: there is clearly a bug that prevents free segments from appearing. I have to find it later
assert(self->blocks.len > 0);
U64 pitch = self->blocks.buf[self->blocks.len - 1].capacity;
// Old blocks remain intact
U64 new_capacity = MAX_U64(mem_requirements.size, MIN_U64(2 * pitch, maintenance3_properties.maxMemoryAllocationSize));
// todo: return back when done. Doing dumb things. I have a bug that prevents things from making sense
// U64 new_capacity = MAX_U64(mem_requirements.size, MIN_U64(2 * pitch, maintenance3_properties.maxMemoryAllocationSize));
U64 new_capacity = MAX_U64(mem_requirements.size, MIN_U64(pitch, maintenance3_properties.maxMemoryAllocationSize));
MargaretImgAllocator__add_block(self, new_capacity);
U64 bid = self->blocks.len - 1;
MargaretImgAllocator__insert_gap(self, bid, mem_requirements.size, new_capacity - mem_requirements.size);

View File

@ -1,6 +1,9 @@
import Allie
import Geom
import Control.Monad (forM_)
import Control.Monad (forM_, when)
import Data.Char (ord)
import Data.IORef (newIORef, readIORef, writeIORef, modifyIORef)
goodColorOfCube :: (Integral a) => a -> Vec3
goodColorOfCube i = ((Vec3 100 0 0) ^*^ t) ^+^ ((Vec3 0 50 90) ^*^ (1 - t)) where t = ((fromIntegral i :: Float) / 4)
@ -8,10 +11,26 @@ goodColorOfCube i = ((Vec3 100 0 0) ^*^ t) ^+^ ((Vec3 0 50 90) ^*^ (1 - t)) wher
goodLightPos :: (Integral a) => a -> Vec3
goodLightPos i = ((Vec3 0 2 1) ^*^ t) ^+^ ((Vec3 5 1 1) ^*^ (1 - t)) where t = ((fromIntegral i :: Float) / 4)
projectDirOntoPlane :: Vec3 -> Vec2
projectDirOntoPlane (Vec3 x y z) = normalize (Vec2 x z)
heroHeight :: Float
heroHeight = 1.89
heroCamPos :: Vec2 -> Vec3
heroCamPos (Vec2 x z) = Vec3 x heroHeight z
puckLevitationHeight :: Float
puckLevitationHeight = 0.4 + 0.2
puckSpots :: [Vec2]
puckSpots = [(Vec2 (-10) (-10)), (Vec2 (-15) (-15)) , (Vec2 (-18) (-18)), (Vec2 (-18) (-25)), (Vec2 (-18) (-30))]
main :: IO()
main = do
alice <- newAlice
aliceSetSkyColor alice (Vec4 0.9 0 0.6 1)
aliceSetCamPos alice (Vec3 0 heroHeight 0)
face <- aliceNewLucyFace alice "src/l3/fonts/DMSerifText-Regular.ttf"
faceOf40 <- aliceLucyFaceOfSize face 40
lucyFaceAddGlyphs faceOf40 32 (126 - 32 + 1)
@ -20,37 +39,67 @@ main = do
weirdStructure <- aliceAddGenericMeshHand alice "gen/l2/models/log_10_2_6.AliceGenericMesh"
"src/l3/textures/log_10_2_6_diffuse.png" "gen/l2/textures/log_10_2_6_NORMAL.png" "src/l3/textures/log_10_2_6_specular.png"
aliceGenericMeshResizeInstanceArr alice weirdStructure 1
aliceGenericMeshSetInst weirdStructure 0 (AliceGenericMeshInstance (mat4Transit (Vec3 (-3.0) (-2.0) (-5.0))))
aliceGenericMeshSetInst weirdStructure 0 (AliceGenericMeshInstance (mat4Transit (Vec3 (-3.0) (0.0) (-5.0))))
floorTile <- aliceAddGenericMeshHand alice "gen/l2/models/quad.AliceGenericMesh"
"src/l3/textures/asphalt_diffuse.png" "gen/l2/textures/flat_NORMAL.png" "src/l3/textures/funny_floor_specular.png"
aliceGenericMeshResizeInstanceArr alice floorTile 49
puck <- aliceAddGenericMeshHand alice "gen/l2/models/puck.AliceGenericMesh"
"src/l3/textures/puck_diffuse.png" "gen/l2/textures/puck_NORMAL.png" "src/l3/textures/puck_specular.png"
forM_ [0..6] $ \x -> forM_ [0..6] $ \z ->
aliceGenericMeshSetInst floorTile (z * 7 + x) (AliceGenericMeshInstance
(mat4Transit (Vec3 ((fromIntegral x) * 10 - 35) 0 ((fromIntegral z) * 10 - 35))))
cube <- aliceAddShinyMeshHand alice "gen/l2/models/cube.AliceShinyMesh"
aliceShinyMeshResizeInstanceArr alice cube 5
aliceSetPointLightCount alice 5
forM_ [0..4] $ \i -> do
aliceShinyMeshSetInst cube i (AliceShinyMeshInstance (mat4Transit (goodLightPos i)) (Vec3 1 1 1) (goodColorOfCube i))
aliceShinyMeshSetInst cube i (AliceShinyMeshInstance (mat4Transit (goodLightPos i)) (Vec3 0.0 0.0 0.0) (goodColorOfCube i))
aliceSetPointLight alice (fromIntegral i) (AlicePointLight (goodLightPos i) (goodColorOfCube i))
-- state <- newIORef 67
aliceGenericMeshResizeInstanceArr alice puck (fromIntegral $ length puckSpots)
forM_ (zip[0..] puckSpots) $ \(i, (Vec2 x z)) -> aliceGenericMeshSetInst puck (fromIntegral i) (AliceGenericMeshInstance
(mat4Transit (Vec3 x puckLevitationHeight z )))
heroPos <- newIORef (Vec2 0 0)
-- Create the Callbacks structure.
let callbacks = Callbacks myonKeyboardKey myonAnotherFrame where
myonKeyboardKey keysym keyAction = do
-- old <- readIORef state
-- writeIORef state (old + 1)
putStrLn ("Got a keypress")
myonAnotherFrame fl = do
oldPos <- aliceGetCamPos alice
goForward <- aliceIsPressed alice 0x77
if goForward
then do
backDir <- aliceGetCamBack alice
aliceSetCamPos alice (oldPos ^+^ (backDir ^*^ (-fl * 10)))
else return ()
backDir <- aliceGetCamBack alice
let projBack = projectDirOntoPlane backDir
rightDir <- aliceGetCamRight alice
let projRight = projectDirOntoPlane rightDir
goForward <- aliceIsPressed alice (fromIntegral $ ord 'w')
when goForward $ do
curHeroPos <- readIORef heroPos
let nextHeroPos = (curHeroPos ^+^ (projBack ^*^ (fl * (-10))))
writeIORef heroPos nextHeroPos
aliceSetCamPos alice $ heroCamPos nextHeroPos
goBackward <- aliceIsPressed alice (fromIntegral $ ord 's')
when goBackward $ do
curHeroPos <- readIORef heroPos
let nextHeroPos = (curHeroPos ^+^ (projBack ^*^ (fl * (10))))
writeIORef heroPos nextHeroPos
aliceSetCamPos alice $ heroCamPos nextHeroPos
goLeft <- aliceIsPressed alice (fromIntegral $ ord 'a')
when goLeft $ do
curHeroPos <- readIORef heroPos
let nextHeroPos = (curHeroPos ^+^ (projRight ^*^ (fl * (-10))))
writeIORef heroPos nextHeroPos
aliceSetCamPos alice $ heroCamPos nextHeroPos
goRight <- aliceIsPressed alice (fromIntegral $ ord 'd')
when goRight $ do
curHeroPos <- readIORef heroPos
let nextHeroPos = (curHeroPos ^+^ (projRight ^*^ (fl * (10))))
writeIORef heroPos nextHeroPos
aliceSetCamPos alice $ heroCamPos nextHeroPos
--cur <- readIORef state
--aliceClearScreenTextLabel alicePerm
--aliceAddScreenTextLabel alicePerm ("Current value is = " ++ show cur)
-- Allocate space for the struct, poke it, and pass to C.
aliceMainloop alice callbacks

View File

Before

Width:  |  Height:  |  Size: 2.5 MiB

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

View File

@ -50,6 +50,6 @@ void main(){
for (int i = 0; i < spotlight_count; i++) {
Pipeline0Spotlight lamp = spotlight_arr[i];
}
vec3 color = color_off * diffuse_illumination + 0.5 * specular_illumination + color_on;
vec3 color = color_off * diffuse_illumination + (0.05 + 0.45 * length(color_off)) * specular_illumination + color_on;
fin_color = vec4(color, 1);
}