R0J0hound's Forum Posts

  • tunepunk

    I had some fun trying my hand at implementing some of that stuff. My events are mostly clean and as readable as possible, although it's at the point where a lot of it needs to be refactored and cleaned up. It is mostly organized so maybe you'll find it useful.

    https://dl.dropboxusercontent.com/u/542 ... rizer.capx

    What it does is fairly straight forward.

    1

    The object file is loaded so we have a list of 3d points and a list of faces which list indices of the points.

    2

    The points are moved around, or in the capx rotated around in 3d.

    Rotation

    The rotation math to rotate on the xy plane is this:

    newx = x*cos(ang)-y*sin(ang)

    newy = y*cos(ang)+x*sin(ang)

    It's basically the same for xz or yz rotations. Just change the x,y variables.

    Changing the amount of rotation every frame can be used for animation.

    Translation

    Next after rotating the points around we need to move the points away from 0,0,0 which is the viewer position. So for example we want the object center to be five units in front of the viewer you could do this:

    newz = z+5

    This is important to do before the perspective transform because things get distorted near 0 and we shouldn't be able to see points with z<0 or behind the camera.

    Perspective

    Perspective is really simple, it's just multiplying x,y by a scale number and dividing by z:

    perspectiveX= x*scale/z

    perspectiveY= y*scale/z

    final transformation to screen position

    This is basically changing the center from 0,0 to the center of the screen.

    screenx = x+320

    screeny = y+240

    3

    Now that the points are transformed we next want to draw points and lines and perhaps polygons. There are a few ways that come to mind.

    Using sprites

    Sprites could be created at the transformed xy position and lines could be done by stretching sprites from one point to another. Polygons could be done with some madness with triangle sprites but that's not straightforward.

    Using the canvas plugin

    You can plot points, draw lines and draw polygons fairly easy. The antialiased lines may not be what you want. Also the paster plugin can be used for textured polygons but that's a different topic.

    Using a tilemap

    The tilemap can be thought of as an array and it removes the step needed to convert the array to something visual. One color is simple but if you look at the capx it shows a way to do a spectrum of colors, well 4096 to be exact. It takes red,green and blue components in the range of 0 to 15 and converts it to a tile number.

    Line drawing

    This is done by lerping from the one point to the other and drawing the inbetween points. Look the "plot line" function in the capx, it's fairly simple.

    polygon drawing

    This took me a bit to wrap my head around. I tried two methods to draw triangles.

    The first one is fairly simple to understand. First you find the bounding box that contains the all three points of the triangle, then you loop over every pixel in that bounding box and see if that pixel is inside the polygon. Unfortunately the math looks a bit hairy.

    The second method is a scanline method which is faster. It involves sorting the three points by y and then lerping along the edges to get the x positions at every y. It has less hairy math but isn't the simplest to understand either.

    Performance on the monkey model is about 4-6 fps and I don't think a whole lot of extra performance for this can be squeezed out of the events. This sort of thing is always pretty slow which is why the rasterization is usually all done by the gpu. It can be made faster if most of it was done in javascript, and the events were only used to issue commands. 60fps should be possible with the events ported directly over, but js isn't pleasant to work with imo.

  • This isn't a bug, it's a feature request.

  • Im sure someone uses databases with c2, although I never have myself. You could look at the plugin list to see if there's something to help with that or maybe search the tutorials to see if someone explains how to do it.

  • Variables are used a lot for just about anything, it just depends if you need them. I don't quite understand the second part of your question. Do you have a game that needs a database?

  • You can find more info about that sort of thing by an Internet search of "software rasterizer." The aticle you linked only gives a general overview from what I see.

    You said you came up with a way to display the array as pixels so I'll leave that subject for now.

    The simplest thing to draw is points. Basically you just have a list of 3d points that project to 2d like the link in the second post and just set the nearest pixel to the color.

    Lines can be done by stepping from one projected point to another with something like "bresenham's line algorithm."

    Animation is done by clearing the array and doing something like a 3d rotation on the points before projecting them to 2d. So just clear, move points, project to 2d, and repeat. It's hard to make it fast though.

    The obj file format is a text format so it'll be easier to parse than something else. Tokenat() can be used to do this. Basically look at one line at a time and see what the line starts with. If it starts with "v" it's followed by 3 numbers seperated by spaces that is a 3D point. If it starts with "f" it's a face and it's followed by indexes of the points that make up the points. Lines can be found from pairs of points of the face. That's the basics of it. There is other info you can parse if you need it.

    Here's a tutorial that goes in depth on how to make a software rasterizer that may be useful:

    https://github.com/ssloy/tinyrenderer/w ... -Bresenham’s-Line-Drawing-Algorithm

  • Here's something similar.

    https://dl.dropboxusercontent.com/u/542 ... dproj.capx

    The rotation bit could be useful to look at.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Aizark

    All my plugins are free to use.

  • A lot of things are done every tick and saving an expression to a variable is negligible in my opinion.

  • It depends on the external JavaScript. If you're making a plugin you can make a condition to query the input state or make a trigger that's called from an event listener or callback. It's mainly specific to the JavaScript you use.

  • I didn't implement save/load at all for this plugin so that's where the issue comes from. I don't have any plans to support that feature.

  • I see it looks like the acceleration is instant with your test, mine was pretty fast but it wasn't instant. It can be made to have smooth acceleration I just need to fiddle with it a bit more I think. I'll see if I can look at your capx and fiddle with my examples this weekend sometime.

  • Yeah, the physics behavior doesn't provide the features to do it.

    One idea that would work, and that I'm interested in, is to just deal with a physics library directly with JavaScript. The only disadvantage is it would be completely seperate from the behavior's and how they nicely mesh with c2's features. So everything would have to be done with events. A plugin would be better but that takes a lot more time to make and polish. I'll probably try the idea this weekend and see what comes of it.

  • It's the change in velocity. In simple cases like hitting the wall at 60mph the car would go from 60 to 0 so the speed would be the change in speed. Still you'll need to store the velocity before colliding because after the hit the the velocity will be 0 (if it doesn't bounce).

  • Mayfly

    Opps, wrong file. I fixed the link.