First Person Lighting

Hi there! I’m very new to jmonkey so this may be a simple question, but I have no idea how to provide the player (first person) with a flashlight to explore their environment.If anyone has an explanation, or some example code that would be really helpful!

I believe a SpotLight is what you’re looking for. See here. You can get a flashlight result by placing the light at


and make it point foreward with


and run that in the update loop. Or something simmilar or completely different, depending on your setup.


I see this one so often. Don’t do it. It’s a bunch of work that just replicates the simpler and more intuitive:

…and if that’s for some reason not intuitive, it at least teaches something that should be intuitive.

1 Like

Well sorry if I thought that calling a method specifically made to give you that vector would be faster than applying a quaternion to a vector. Perhaps you should add a note in the docs: //Only exists because reasons, do not use.

Well, look at it this way… one approach (mult with an axis) is using the primary thing that Quaternions exist for. It’s the single most often called thing on all of quaternions by a huge long margin. It’s basically the only reason that quaternions exist in the engine in the first place.

Where as the other (getting the column of a rotation matrix) is a weird magic method that makes no sense unless you understand the deeper relationship between quaternion and matrix and that the third column in a rotation matrix happens to be the rotated Z-axis.

So even without considering performance you have a straight forward natural way that teaches you something useful if it wasn’t already deeply embedded in your day-to-day patterns. The other is magic voodoo that is only useful for being magic voodoo.

Now let’s consider performance. One approach uses the single most common use of quaternions in the engine, likely called hundreds of time a frame. The other must essentially manufacture from thin air the parts of a rotation matrix that it needs just to return the third column. At best, it’s probably performing the exact same calculation as quat.mult(Vector3f.UNIT_Z). At worst, it’s doing much much more work than that.

getRotationColumn() exists out of some sense of completeness. And it was used erroneously in some tutorials and now we pay the price.

Goes replacing every single call to that method in his entire game.

There is probably no reason to do that. But when providing examples, it’s best to use the more intuitive version, I think… or the version that should be more intuitive.

Edit: as it turns out,
Quaternion.mult(Vector3f) is 60 multiplies and 21 adds while Quaternion().getRotationColumn() is 25 mults and 7 adds.

…though it’s unclear how they will be optimized at compile/runtime since the first version does a lot redundant multiplies. Personally, I’d still opt for the one that isn’t voodoo magic but you probably don’t need to rush and replace all of your calls, either.

(And clearly we could optimized mult() further if we wanted… and in fact, I think someone may have already posted a patch along those lines some time back.)

You gotta be kidding me. Times like this make me wish I had version control…

o_O You don’t have version control?!?!?

Again, there is no particularly good reason to switch back, either.

P.S.: local version control using something like SVN takes all of 2 minutes to setup.

Well I never got around to setting it up, and haven’t had a reason to since I make backups regularly and would just restore certain parts if I messed up something beyond repair. Until today that is.
And git is meh.

Yeah, so don’t use it. SVN is way easier to use.

You’ve been doing ugly manual source control up until now. You put in lots of extra work to do it and get nothing out of it other than being able to wholesale rollback to previous versions. A real version control system will take that work off your back and give you a bunch of stuff back… like more incremental ‘back ups’, ability to do diffs, ability to easily revert single files, and so on.

SVN or GIT or any of those will let you do that. But for just that, I think that SVN is easier because it doesn’t hit you over the head with branches at every turn. You also get to commit in one step instead of two, etc… and efficiently store binaries, and so on.

Programming without VC sounds like a good approach to add thrill to the boring task of writing lines :wink:

1 Like

Yeah, it’s precisely like riding a motorcycle in nothing but your underwear because putting on clothes would take too much time. Very exciting.

…only in this case, you also carry your clothes around with you so you can change into them as soon as you get off the bike to go into a store or something.

Do you run Windows or Linux? (I’ve setup SVN on both before.)

My life in a nutshell.

Wandows, but don’t worry I’ll figure it out. I actually did mess around with tortoise some time ago for idkwhat.

At a quick glance, this tutorial looks pretty good… even if you just want to use the IDE’s built-in SVN, this tute has the server and repo init stuff in it:

Edit: personally I use the command line so my experience falls off at some point in this conversation. :slight_smile:

Probably at the point when I say I use Eclipse haha

AFAIK also Paul is a “Eclipse guy”.
Eclipse, Netbeans, IntelliJ, all of them offer a integrated way to deal with VS.

IMHO it is a 10 click process in my ide for: installing git, creating a git repository, commiting everything and uploading the stuff to github. (7 of the click are only necessary if you don’t have git installed)

If you need it private, bitbucket offers free private plans for small teams.

Nope. I’m an “IDEs are the devil” guy. :slight_smile: I’m about to drop even use of the SDK one of these days as I find myself repeatedly wanting to burn it with fire.

Now i want a comparsion including motorcycles pointing out the decrease of productivity when not using an ide :wink:

1 Like