# PanicRave

Member

25

177 Neutral

• Rank
Member
1. ## scrolling 2D isometric camera with a mouse

that will keep me busy for a little while! thanks!
2. ## scrolling 2D isometric camera with a mouse

Hey all, i've been messin with a little isometric engine. It's been over a decade since I wrote one although i'm very familiar with standard tilemaps. I was following a tutorial which has gone well but i've hit a little bit of a hump - the writers solution to an isometric environment is to do everything as you would for a standard (Cartesian ?) tile map, literally everything, and then at the very end when rendering you convert the Cartesian positions to isometric co-ordinates.   eg, calculate your standard tile positions for the tile about to draw: tile_x = tx * tilewidth; tile_y = ty * tileheight;  then do your usual camera offsets for smooth scrolling etc tile_x += camera.x % tilewidth; etc etc and when you're all done convert to iso: iso_x = tile_x - tile_y; iso_y = (tile_x + tile_y) / 2;   This works fine when your camera is following an object IN the isometric world. IE if your camera follows a character and you press right arrow to move player right then your character will walk diagonally down and right and the world would scroll as you expect.   But I want a free camera controlled by the mouse - its a strategy game and there is "no player" in the game world. I want if you click and drag you scroll the map. BUT because everything is done Cartesian and then converted iso if you click and drag to the left intending to scroll the world right it instead scrolls diagonally down and right which is NOT where you are dragging and it feels awful.   Any ideas how can i take the position of the camera and calculate a) the tile offsets so the correct part of the map draws and b) the pixel offset for smooth scrolling in a way that feels natural? I'm beginning to think this converting everything at the end for render isnt the best idea ever :/
3. ## Expand 2D texture in 3rd dimension to create a model

if you are working with pixel art (especially with a limited pallet) then you can be a bit more intelligent about how you build your models to save on triangles. Obviously any transparent pixels simply do not add to the mesh at all. Then you could use some sort of algo (perhaps a modified flood fill?) to find groups of pixels the same colour next to each other that can be represented by a rectangle without containing any other colour pixels. Then if you have say 4 black pixels left to right in a line you can do the whole lot with two black triangles instead of 8.   There could be other fun things to mess with too.. like if you used a colour to represent transparent pixels (traditionally magenta 255,0,255) instead of alpha then you could let the artist use the alpha channel to describe depth and extrude each pixel a different amount based on alpha :o
4. ## smoothing the shoreline of my continent

Thank you all for your input! I have solved this using a variant of Krypt0n's suggestion, i'll share it here incase its helpful to anyone in the future.   First i'll try to better describe the problem for DaveSF and any others I confused:   We have a world map. It is always an island surrounded by ocean. For this example assume that the world map is a 2D array that simply stores a value saying whether this cell of the map is an Ocean tile or if it is a Land tile. I then create a 3D mesh (which is a 1D array of vertex positions) from this WorldMap array to represent the the world as a 3D object.   This is all fine, but due to the grid like nature of the 2D array and the fact each cell in that array represents a spacing of 1.0 world units it means wherever the boundary between land and ocean occurs it is made up only of square, straight lines and does not look very natural. I have done a silly sketch:     Any cell with O is ocean and any cell with L is land. The pencil line represents the natural border between the two, the X's represent the vertices that connect the two cells (not completely accurate in my case but you get the point) and then the curved pen line is a more natural looking, more desirable border between the two that would help the island look nice and should be completely achievable as after the 3d mesh has been generated the real world co-ordinates of the vertices can be moved as we please, they are not really restricted to a grid.   In order to solve this simply I've written a method that travels over the map and finds ocean cells. It then looks in four compass directions around that ocean cell to find land and stores the position of the land it finds in a list. After it has finished the search it generates a new position for the ocean vertex as an adverage of all connected land positions.   Here is the code i've written to do this: public void SmoothShoreline(WorldMapCell[,] WorldMap) { //for each cell of the world for (int cx = 0; cx < WorldWidth; cx++) { for (int cy = 0; cy < WorldHeight; cy++) { //if this cell is "ocean".. if (WorldMap[cx, cy].TileType == WorldTileID.Ocean) { int u = 0, v = 0; List<Vector3> CoastalVertices = new List<Vector3>(); //for each direction around the starting cell for (int d = 0; d < 4; d++) { //get direction coordinates.. if (d == (int)Directions.West) { u = cx - 1; v = cy; } if (d == (int)Directions.North) { u = cx; v = cy - 1; } if (d == (int)Directions.East) { u = cx + 1; v = cy; } if (d == (int)Directions.South) { u = cx; v = cy + 1; } //check valid map cell (simple bounds checking).. if (IsMapLocationSafe(u, v)) { //if valid and this cell is coastal (or land, whatever).. if (WorldMap[u, v].TileType == WorldTileID.Coast) { //store the coordinates of the vertex belonging to this cell CoastalVertices.Add(Vertices[u + v * WorldWidth].Position); } } } //final (new) position of our ocean vertice will be adverage of all the land cells around it, so.. Vector3 FinalPos = new Vector3(); //combine all the stored coastal/land cell positions.. for (int Vert = 0; Vert < CoastalVertices.Count; Vert++) { FinalPos += CoastalVertices[Vert]; } //divide by the total number of positions to get an adverage.. FinalPos /= CoastalVertices.Count; //set the final vertex position. Vertices[cx + cy * WorldWidth].Position = FinalPos; } } } } It is not completely perfect, i'm sure there is a much more fancy way that would get a 100% result - but it looks pretty good and I am quite happy with it for now :)
5. ## smoothing the shoreline of my continent

for the record: I have thought about cheating this by just blurring the edge render (which happens on a separate render target which is all combined at the end) - the problem is not every edge gets lit up all the time and the camera is free moving AND you can zoom in to very close which would cause the squareness to show anyway
6. ## smoothing the shoreline of my continent

So, at the moment any cell that is "ocean" i've just alpha'd out so it's not visible at all. Here is a screenshot although the final look is far from finished!   http://heavenlysoftware.co.uk/storage/EdgeDetect2.jpg   You can see the edge detection looks like it's in bad need of anti-aliasing - but the fact is thats just what the edges of the island is like.  I figure I can fix this as i said in the first post by normalizing/smoothing the vertices that belong to both a ocean and coastal tile.. but although I have enough knowledge to know that it's a "thing" I really do not know how to do it!   If I ever render ocean on this I want it to be very simplistic and minimal - maybe in the form of faint lines representing waves slowly animating around the coastal regions. I don't think it would be sufficient to mask the quad like structure when it comes to the edge of the island :(
7. ## smoothing the shoreline of my continent

something like that CAN work but... I'm not entirely sure I'm going to render any ocean. If I do choose to, it will be very simplistic. The final effect of this terrain is a sort of world map looking like a hologram/computer projection on a screen rather than a "you are actually looking at a continent from the sky". It has more in common with a map drawn on paper I guess
8. ## smoothing the shoreline of my continent

So some of you know i've been working on procedural island generation. I'm really happy with my results right now and have just one last thing I want to perform and i'm not entirely sure how.   My continent is generated inside a 2D array, just like a tile map. I then generate a 3d mesh that matches width/height of grid where each cell is two triangles/quad with a width and depth of 1.0 units.  Where the shore line meets the coast is obviously very blocky whereas the rest of the island actually looks quite smooth despite the rigid quad layout.   What I want to do is find all vertices that share a cell flagged "ocean" and a cell flagged "coast" and sort of.. normalize them a bit? or somehow work out ordered points for a line they form and create some sort of bezier from that and pull the verts closer to that final line maybe? I'm not sure how to even begin doing any of that.   Any advice? :)
9. ## finding the height of a pixel in model space (HLSL)

I think i'm misunderstanding something or just being inept: in the struct for my vertex shader output i've added:   float3 PixelWorldPos : TEXCOORD5;   (i'm using other texcoords for multi texturing/blending)   in my vertex shader in the first line i;ve written:   output.PixelWorldPos = mul(input.Position, World);   to try and get the world position. I've read somewhere that when passed to a pixel shader it should interpolate to give the pixel position and not just the vertex position.   in my pixel shader I have: if (input.PixelWorldPos.y % 64 == 0) { output.Colour.rgba = 1.0f; } else { and in the else it draws the pixel normally.   But all this ever does is render the entire object normally EXCEPT the very bottom line (for want of better term) which is all white. but only the very bottom. I have tried replacing 64 with 32, 8 and 2 - all have exactly the same result :/
10. ## finding the height of a pixel in model space (HLSL)

Thanks for the reply! I did not know about that semantic and its very useful to know! in this situation however I feel it wont work for the effect i want - I would like these scanlines to go from the bottom of the model to its top so that if say I had a triangle and I viewed it from the side like /\ I would see lines going from base to tip - but if i viewed it from the top down I dont want the lines to now go from the left side to the right side for example but still be orientated in model space. I don't know if im explaining clearly though!       Have you tried the same technique in the pixel shader by passing the model's world position along with the transformed position? I.e., test model_position.y? Note: the test will have to be in world units, not screen units.     I have just got home from work and will play with this now :)
11. ## finding the height of a pixel in model space (HLSL)

thanks for the reply! in this case i want the scanlines to appear on the model and change with orientation - the overall effect when i've done everything i wanted should be a sort of hologram projection of the model.   I wanted to start with drawing it with this scan line effect. i've been programming a very long time but mostly in 2D. if I wanted to do this effect in 2D I would get the Y of the pixel im looking at and say if i wanted every other line to darken out i'd if (p.Y % 2 == 1) { draw darker } else {draw normally}   I figured I could apply this same sort of technique in 3D if i could figure out how high up the model this pixel was? but bumbling through HLSL as i am i have no idea how to get that information :/
12. ## finding the height of a pixel in model space (HLSL)

Hi all,   I would like to create a HLSL shader that renders a 3d model with the appearance of scanlines. I figure to achieve this I will darken out "lines" in the model by drawing pxiels darkened based on how high the pixel is. I thought I might also periodically have one bright line start at the bottom of the model and travel up to the top - it would be much the same method as darkening alternating lines but I guess i'd pass time or some other value into shader to offset it by.   My issue is I don't really know how to calculate that Y offset to pass to the pixel shader - im pretty sure it can be worked out in the vertex shader somehow? :)   Sorry if its a silly question, I'm still fairly new to graphics programming!
13. ## creating rivers in my procedural terrain

Thanks for the response!   Unless im thinking wrongly (head still = tile maps) then even if i upped the resolution of my height map each river tile would still be a "square" which would have negative consequences. IE: a river trying to move diagonally would not be great. If a river increased in width then its choices would be 1 cell, 2 cell, 3 cell etc and if a river moved from being 1 cell thick to 2 cells thick (say another river joined it increasing the water flow) then the river would quite suddenly become twice the size and not be centered (because restricted by grid pattern, requires at least 3 cells to keep river center with 1 cell flow)   So I guess subdividing is the answer... i'll have to go on a google search for how to perform it. I have my array of vertices[] and indices[] and am pretty confident I understand how I built them but head goes a little funny when i think about adding one extra vertex to what was actually an array of just triangles and then deciding what index belongs to what etc.. gonna have to be a lot of reading!
14. ## creating rivers in my procedural terrain

I wasn't sure if this would count as game/general programming or graphics so apologies if this is the wrong place.   I have been working on procedurally generated islands for a few weeks and am really happy with the results. The next phase is the only bit left that has me scratching my head: creating/rendering rivers.   "Generating" the rivers and deciding where they go is not the problem here. I used an idea from Amit Patel who has a blog which covers this sort of stuff and the middle of my island is always the highest part, to generate rivers I just pick random spots above a certain height then follow the "steepest" path down to the coast. But how to phsyically create these things I have no idea about and my google searching is finding any amount of theory on generation but not phsyical creation :/   I figure I need to carve a river bed in the terrain and then create a new mesh which i can render as water?   The terrain is 3d and made of quads (or 2x tri's i guess). My algo's generate a height map of sorts and then I run over it and generate the mesh. It would be sort of simple before generating the mesh to lower the height in every cell flagged as river and THEN generate the terrain - but this would restrict river bed widths to being multiples of the cell sizes which I want to avoid. Amit's suggestion is that you store a water volume property and every time water flows through a cell you increase it by 1, then the river width is the square root of the volume for that cell.   So i'm thinking subdivision - i've never done it before (this really is one of my first dives into hand made 3d, usually I use 2d tile maps!) and cant figure out how you decide what to subdivide and where the new verts go and then generating the river mesh..   I'm sure i'm over thinking this. How should I be tackling this?   Thanks!
15. ## c++ port of lidgren?

If a wrapper is suitable then it would be ideal as id only have one library to keep up to date! But I was concerned about the portability of wrapping managed code - for example if me or someone else is writing a native android app in c++ would they be able to use my api? I've done unmanaged to managed wrappers before but it seems weird the other way around! Lol