FANDOM


TranslationsEdit

RotationsEdit

So your problem is basically that your object is offset. That means you need to apply a translation by some vector. How to find out which vector you need? When you do a 2d rotation, there's something which is great, it's the centre of rotation. That point DOESN'T MOVE, which means that if you're doing a rotation and a point doesn't move, you know it's the centre of rotation. In your case, it's not the right one (the centre of rotation is "position" by default, and you want it to be "center"). So what do we do? If we call "new centre" the point around which you want the rotation to be made, you simply have to apply a translation of vector (new centre after rotation minus new centre before rotation). Now, Project Spark works in 3d, which means that rotations are around an axis of rotation, not a single point. Any point on that axis is fixed while rotating. So you can choose any point from the axis you want, call it "new centre", and apply the translation.
The problem is that you need to find out what is the new centre, before and after the rotation, in order to calculate the vector of translation. But once you've found the formula, it's pretty simple. You have to use that kode:
WHEN DO [previous new centre] [equals] {the formula}
WHEN DO [forward] [equals] [vector rotate] [forward] [your angle] [axis] [your axis] // you may want to have [up] instead of [forward], if the axis of rotation is [forward]
WHEN [new centre] [equals] {the formula}
WHEN DO [position] [increment by] [new centre] [minus] [previous new centre]
That kode is generic, so as long as you can find out the formula (or a formula, since like I said there are several points you can choose from, as long as it's on the axis you want) to get new centre and previous new centre, you're fine.

But now, your question was more precise than that, and actually the fact that you want the "center" to be part of the axis of rotation is simplifying the kode a little. Indeed, PS allows you to change the value of "center" directly, so instead of adding the vector (center minus previous center), you can directly set center to previous center. So that gives in your case:
WHEN DO [previous center] [equals] [center]
WHEN DO [up] [equals] [vector rotate] [up] [1] [axis] [backward] // it just so happens that [roll] uses the forward axis (well, in the backward direction), so like I said earlier I've replaced [forward] with [up]
WHEN DO [center] [equals] [previous center]

One last thing, why am I not using [roll]? It's because of a slight difference, which is very annoying when changing the axis of rotation with that translation trick. It is the following: "roll" does not actually change anything about the prop when the line is read, but it is only changed AFTER the whole brain has been read (more precisely, at the end of the frame, or maybe at the beginning of the next frame). That means that [center], or any other local vectors like [forward], aren't updated after the use of roll/pitch/yaw. So I strongly recommend to manually rotate forward (or up) to get the local vectors to update immediately, and thus having the ability to use the kode that looks for the change in position of the centre of rotation due to the rotation and applies the translation accordingly.

ReflectionsEdit

Here is a kode that reflects a raycast, using the Math formula:
http://i.imgur.com/ZedOvDv.jpg

http://i.imgur.com/eqQcUTJ.jpg


There is a "projected onto" tile, so the code above can be simplified.
However, I actually prefer to use a vector rotation, which I think is more intuitive for people who haven't studied the orthogonal symmetry, and I added some drawings to explain how it works:
http://i1060.photobucket.com/albums/t456/MindcraftMax/Reflection%20explanation_zps3aslduj0.jpg So the code in KodeShare for both solutions:

http://kodeshare.com/PLC33M


HomothetiesEdit

Note: All the basic transformations that are discussed above are affine transformations.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.