R0J0hound's Forum Posts

  • Look in the capx I posted. In the curve function there are 3 control points x0,y0, x1,y1, and x2,y2.

    The first action that sets them sets them from the function parameters. The second actions that set x1,y1 correct the math so that control point is on the curve.

    I haven’t tried the new canvas function, but you should be able to do multiple objects without layers. Just juggle the visibility of things when drawing to the canvas with a blend mode.

  • The curve can be done with qarp(). It's a quadratic bezier curve. A little extra math was used to make the middle control point on the curve.

    Then it's just a matter of making a curve per edge. I guess there's many ways to go about it. This example uses one.

    dropbox.com/s/9wwrln9f6tkxn0y/curve_box.capx

    Basically it's just creating a bunch of points along the curve, then used stretched sprites for lines. Anyways you probably could use the canvas to draw it filled. Just add the points to the polygon instead of creating sprites.

  • I got around some wifi, so here is a working example:

    dropbox.com/s/0cygc1w5noarffs/3dball.capx

    Something to play with at least.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here are some notes on how I’d go about it, and most of the math worked out. Hopefully I’ve provided sufficient explanations.

    The 3D physics of the ball is probably the easiest. We already have xy and we can do z with a instance variable. Just add three other instance variables to keep track of velocities: vx,vy,vz. Also we can use a variable g for gravity.

    Then the motion can be done with:

    g=300

    Add g*dt to vz

    Set x to x+vx*dt

    Set y to y+vy*dt

    Set z to z+vz*dt

    The result is parabolic motion on the z axis. You can make it bounce off the ground with:

    Z>0

    — set z to -abs(z)

    You can control where the ball will land by setting the initial velocities.

    t = distance(x,y, goalx, goaly)/speed

    Vx = (goalx-x) /t

    Vy = (goaly-y) /t

    Vy = -g*t

    To see the z motion we need to rotate everything around in 3D somehow. You can do that on the same objects, but it’s probably simpler to just position new objects from the old ones. It turns out a 3D rotation is basically the same as a 2d one.

    Rotate on the YZ plane:

    a = the amount to rotate

    y, z = the point to rotate

    cy, cz = the center of rotation

    NewY = (y-cy)*cos(a)-(z-cz)*sin(a)+cy

    NewZ = (y-cy)*sin(a)+(z-cz)*cos(a)+cz

    We can then add perspective fairly easily. It’s basically just dividing x and y by z.

    Perspective:

    X,y,z = the position

    Cx, cy = the center of perspective

    Fov = field of vision. 300 is a decent default.

    Eye = camera distance from scene.

    NewX = (x-cx)*fov/(z+eye) +cx

    NewY = (y-cy)*fov/(z+eye) +cy

    Scale = 1*fov/(z+eye)

    Perspective is wonky when behind or too close. Increase eye till everything is in front.

  • Yes, they’d probably be the same draw call. No idea the performance difference.

    I’d guess using one tilemap is optimal, but if it makes what you’re doing simpler with 5 then I’d say go for it.

  • Yes in c2, at least usually.

    They both have the same texture so they’d both be in the same batch I’d imagine. A batch is just a list of quads sent to the gpu in one go and told to draw.

  • Hello,

    I haven’t opened your project file but here are some thoughts:

    For the right click issue:

    I’d remove the wait actions. They just complicate when stuff runs.

    When you right click, the two right click events are run in order from the top down. So the first sets stuff up so the second can run. Maybe using one right click event and else in sub events would be a workable solution.

    On right click

    — slot empty ?

    —— place object in slot

    — else

    — — add one to item count in slot

    For your second issue it’s basically you want to pick two instances at the same time. There are two strategies for that.

    One is to pick them one at a time, save the info you want to some variables and then pick the other. IIDs are useful here sometimes. So that would look like:

    Variable firstObjColor=0

    Some event

    — pick a object

    —— set firstObjColor to object.color

    — pick a different object

    — object.color = firstObjColor

    —— console log: can craft

    Or if you want to use an iid to make picking the first object later easier:

    Variable firstObj=0

    Some event

    — pick first obj

    —— set firstObj to obj.iid

    — pick other object

    — obj.color = obj(firstObj).color

    —— log colors match

    Anyways the other way to handle picking two instances of the same object type is to make a family with just that type. So if the object is “sprite”, make a family, add sprite, and call it “otherSprite”

    Then you could do this:

    Sprite.x = 100

    OtherSprite.x=200

    — do something

  • 20*log10(t)

    Where t is any number from 0 to 1 will do it.

  • -infinity

    And yes, you can use that as the expression. There’s probably a low enough negative number you can use too if you like.

  • tunepunk

    I agree it would be more user friendly like that. It's just not a priority atm.

    Nepeo

    Glad you thought it interesting to port over.

    Jquery was just an easy way to get the js file loading with one line from the eventsheet in C2. So I kind of like it in that context. Project file loading works fine here, so I guess that's a C3 thing. I'm only concerned with web export though.

    It's probably the least hacky way to do 3d in C2 I've found so far. While it does use the same gl context to do the rendering, the only hacky thing is it takes over some object's drawgl as a entry point. Nothing really specific to Construct's renderer other than telling it to finish what it's doing with glw.endbatch(). The Fbo was only added to work around the gl context being created without a depth buffer.

    I don't mind brittle. Using js directly makes it very brittle with typos and stuff. Also the internal apis used are mostly documented in the sdk, but besides that it's not like C2's internals will change at this point, I'm not even using the latest release.

    All a plugin would add for me is making this work when using export with minifying. Otherwise it just makes developing more time consuming and tedious for me. Personal preference, really. I'm not really interested in making a plugin anyway. This is basically just me getting more fluent in webgl, and integrating it into C2 in some way.

  • You can get it to work with scrolling by setting the position relative to scrollx, scrolly

    So the monkey head could be 320-scrollx, 240-scrolly.

    Changing it to draw witching the object bounds per object is doable. Mostly shifting code around and adding more code to size it within those bounds. It kind of restricts what it can do. Less work to use, more work behind the scenes kind of thing. Probably something to try another day. I’m losing steam on changing how this one works for now.

    It’s at a point where it has sufficient flexibility I can try some other ideas out. Albeit by making things a bit more complex to use.

  • Yeah, it’s pretty much from scratch.

    The zorder used is from the sprite whose drawing function is hijacked. I think the js function that does the hijacking is called overrideObjectDrawgl or something. You just pass a uid and the name of a c2 function to be called when drawing. It can be thought of as a 3D layer in place of that sprite.

    You’d have to hijack another sprite to do a separate layer.

  • Here's the example:

    * You can load multiple textures and multiple obj files.

    * The object files need to have UVs. It will fail without them.

    * Look at the capx for a usage example.

    dropbox.com/s/71krjzb1heqp8qa/rojo3dwip.capx

    To make it work in C3's C2 runtime, you'll need to change cr_getC2Runtime to cr_getC3Runtime, and c2_callFunction to c3_callFunction i'm pretty sure. You'll need to change them in rojo3d.js and in the start of layout event. Also, jquery is needed for this to work. I haven't looked into what to change for the new runtime to work with this.

  • You can access specific objects by their iid in expressions like so:

    Sprite(0).x gets the first sprite’s x

    Sprite(1).x gets the x from the second sprite.

    So say you have four instances you can access their x’s with

    Sprite(0).x

    Sprite(1).x

    Sprite(2).x

    Sprite(3).x

    Not only that but the number wraps around so you can use 4 to access the first one again.

    So what that expression is doing is it uses the variable t to specify a location between instances.

    For example with a t of 1.33

    It takes instance 1 and instance 2 and uses lerp to find the location a third of the way from instance 1 and 2.

  • Sorry for the late reply.

    This example is probably not the best approach to do what you want. It renders to to a separate canvas which is then copied to a texture on c2’s canvas, and that is used instead of an objects texture. Multiple different objects would just mean doing that multiple times for each model.

    The pro is it lets you draw it in order with other construct objects.

    The con is copying textures can be slow when you do it a lot.

    The construct version specific stuff would be getting the object by uid and changing its texture. That and the calling of event functions from js. For the c2 runtime in c3 it should be enough to just change all occurances of c2 to c3. That, and you need to make sure jquery is included as you’ve already figured out.

    For the new runtime you’ll need to consult the ask manual to see the new ways to do things.

    A plugin would basically do the same thing. You could then hide a lot of the behind the scenes stuff if done right.

    In all reality I’d say the best way to be able to make a simple 3D plugin would be:

    1. Make some simpler plugins to get familiar with what’s involved.

    2. Do some simple webgl programs outside of construct. It’s a pain but it’s much simpler there. Making it work inside construct just adds complexity.

    3. Next flesh out how you’d do what you want to do. You can’t really remove stuff from plugins without breaking projects. I’ve found it’s easier and faster to flesh out ideas and try stuff with a hybrid approach of running js with the browser plugin. A drawback of this is js errors are a bit more obscure.

    4. At this point you have a good idea of how you want to do things so you can start doing the plugin. There are some design issues though. You are more limited with the things you can do as opposed to js, so you may need to get creative.

    3-4ish. I guess at some point you’ll have to test compatibility with different browsers and such. Idk if there are many things to handle.

    Anyways there are probably other ways, this is just some of my observations.

    I’m probably toward the tail end of 3 with a better example. It is doing what I want, and it’s much simpler to use multiple meshes or textures.

    It won’t ever become a plugin, I find them too limiting and hard to maintain. I also need to test with webgl1, and see what breaks.

    It’s only going to be a c2 capx, with no plans to ever be c3. I don’t have internet on my computer most of the time and c3 doesn’t add anything for me. I can try to shove all the construct2 specific stuff in one spot to make updating for c3 easier but it may not be feasible.

    I’m going to try to do a game or demo with it first before posting it to iron out any activating design issues.