"Locking" down the lights

Aug 2, 2011 at 2:31 PM

Hi Guys,

Kinda a tough question, because of the lack of knowledge (on my part)...

I have a game which i am making, using the Farseer physics engine, its rolling out pretty good, i have the camera moving following the player etc.

I am now trying to integrate the Krypton lighting engine into the game, i have got the lights showing up etc, looks amazing...

The problem is with the Matrix View, and the ability to "lock" the lights down into the excising world which i have created...

So what i am seeing now is the lights & hulls show up, but when my character moves the lights move with him, they arnt locked into the games world...

Now i can guess that this is most likely not a Krypton issue rather the way i and using my initial Matrix and implementing it with the krypton one.

Can you guys give me any advise on how to "lock" the lights down, so that the positioning data from my other game parts can be the same as the positioning data for the lights and hulls?

Thanks for any advice you can share.

Mal

Coordinator
Aug 4, 2011 at 10:55 PM

Mal,

Turns out, krypton isn't smart enough to figure out where the lights should be in relation to your scene. For this reason, we've provided the Matrix property on Krypton to allow you to set the WVP Matrix yourself.

The lights are each in world space, so you will need to supply a matrix that will transform the from worldspace to screen space.

There is a default matrix provided (I believe), that will show the lights in screen space, but that is obviously not enough for what you want to do.

Let me know if you need more detail. :)

- Chris

Aug 6, 2011 at 12:24 PM

Xixonia,

Cheers for the reply, yea thats the problem exactly. What i need to learn how to do is stitch the 2 matrix's into 1.

I was hoping that it was as easy as setting the position of the light to an object and it would follow it around lol.

Can you give me any advice on how i go about getting the krypton matrix or engine to work with the Farseer physics engine? any advice would be sweet.

This is what i have in the Update section of my Game Class:

Vector2 cameraMovement1 = new Vector2(-64, -64);
Vector2 cameraMovement2 = (PlayerLocation * cameraMovement1);

_view = Matrix.CreateTranslation(new Vector3(cameraMovement2 + _screenCenter, 0f));
//_view is for the Farseer engine
view = Matrix.CreateTranslation(new Vector3(0, 0, 0f)); //view is what the default Krypton Matrix -> View

I am finding it hard to stitch them together at this level, i have tried many different combinations here... i get movement of the lights but my gut tells me that this is not the right place to be doing this, and rather its a core Krypton engine issue that i need to convert...

Really... i don't need a super advanced lighting engine so many i don't need to use Krypton... i would prefer to cause its pretty like :P

 

Again thanks for any advise you can share!

Mal

Coordinator
Aug 6, 2011 at 3:41 PM

Are you using DebugViewXNA ?

Coordinator
Aug 6, 2011 at 3:45 PM

I've seen this in some forums:

 

Matrix proj = Matrix.CreateOrthographicOffCenter(0f, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0f, 0f, 1f);
Matrix view = camera.GetViewMatrix(Vector2.One);
physicsDebug.RenderDebugData(ref proj, ref view);

 

Keep in mind that Krypton only has *one* matrix (World View Projection). You must combine the World, View and Projection matrices used for the rest of your game, and give that to Krypton.

Let me know if you've done this, and if the lights disappear (which they might, but you'll just need to change the cull mode).

Aug 6, 2011 at 4:08 PM

Xixonia,

You are a legend! I will try this tomorrow and post my results here.

Thanks!

Nov 8, 2011 at 1:51 PM

Hi Xixonia,

I have been away (had my second child!!) i tried several different ways of implementing the above code and i cant get my head around why i cannot get the lights to lock down to the Farseer engine?!

I have seen on the internet that other people are doing it, do you have any exp with the Farseer engine and implementing Krypton?

 

I guess i dont have my head around what a Matrix is or how to combine the Farseer one so that objects moving with in the farseer engine can share x,y cords with the Kryton engine... Maybe i am thinking about this the wrong way...

Cheers for any help / advice.

AJ

 


Coordinator
Nov 25, 2011 at 5:02 PM

I don't have any experience with the Farseer engine, but I presume that it has nothing to do with a view or projection matrix. By nature, it's not doing any global transformations. While each body in farseer obviously has it's own matrix (albeit simplified I'm sure), it doesn't have any concept of how the scene is rendered.

There should be three things involved:

  1. Light Engine
  2. Physics Engine
  3. Camera

So, the physics engine takes care of things in world space... it doesn't scale to the screen, etc...

The light engine uses the matrix you provide (or a default matrix if none is provided).

The camera should have information about how the scene needs to be transformed from world coordinates to screen coordinates. This is where the problem lies.

Krypton needs the matrix from the camera to be able to transform the same way the camera will transform. So, whatever matrix you're using to transform the scene and render the physical objects needs to ALSO be passed to krypton.

Coordinator
Dec 12, 2011 at 5:12 PM

MalakiG,

Were you able to get this worked out? I would be happy to go over some code with you and find out what the problem is. :)

Also, if you could post an image of the problem, that wouldd be wonderful.

Dec 13, 2011 at 12:53 AM

Hi Xixonia,

Yea i will be asking for your help, i started making the changes go all excited when i saw some results but its not quite right!! I am under the pump atm with work and family, but ill see if i can zip up some of my code and show you what i am trying to achive!

Cheers for the msg too!

Apr 15, 2012 at 12:29 PM

Hi Xixonia,

 

Just a quick update... i know its been a while :) I managed to sort the integration between XNA draw, Farseer engine and Krypton!

I basically started again, and learned more about what XNA Martix is... i am still not 100% on it but i finally have it all working together!

Cheers for your help, i am sure i will be asking you more in the coming weeks.

:) Mal

Apr 16, 2012 at 2:34 PM
Edited Apr 17, 2012 at 12:50 AM

Hi Xixonia,

As promised here is a question... Are you able to tell a light to ignore certain lights?

Mal

EDIT: I realized I said light ignore light.... (facepalm) i meant light ignore hull sorz. I expanded the question below.

Coordinator
Apr 16, 2012 at 9:00 PM

Mal,

Can you expand upon what you mean?

Apr 17, 2012 at 12:49 AM

Xixonia,

Ok I have a Body (rectangle) in the Farseer engine and I automatically have a hull with the same size attach it self to that box and mimic its movement and rotation. I then thought that i might want that object to have a light source too, so i attached a light too at the same position and it obviously is hidden "under" or "in" the hull. So I was wondering can I say that this particular light ignores this hull but every other light still sees this hull.

I understand if its not possible and can work around this but i was just wondering.

Cheers,

Mal

Coordinator
Apr 20, 2012 at 12:03 AM

Mal,

That functionality is currently not built in to Krypton. However, it would be a great feature to add in the future.

Coordinator
Apr 20, 2012 at 12:03 AM

Mal,

That functionality is currently not built in to Krypton. However, it would be a great feature to add in the future.

Apr 20, 2012 at 7:07 AM

Xixonia,

Cool no worries, its not absolute that it work for my current idea / build.

I do have another issue that i want to ask you about but its quite hard to explain, i will try create a youtube video and link you to it and hopefully you can give me some insite.

 

Cheers again,

Mal

Apr 20, 2012 at 8:41 AM
Edited Apr 20, 2012 at 8:43 AM

Xixonia,

Ok here is my video with a question. What I have is a Farseer body and I have a Krymson Hull same size and shape following it via:

this.rectangleHull.Position = new Vector2(this.rectangleBodyHull.Position.X, -this.rectangleBodyHull.Position.Y);
this.rectangleHull.Angle = -this.rectangleBodyHull.Rotation;

Whats happening as you will see in this video:

http://youtu.be/iDKl_S2NBoE

Is that the Hull has a delay (elastic kinda) to the farseer body when I move the farseer body. The XNA texture little square updates exactly with the Body its just the hull that's on a delay. My thinking here is that the updates for Krymson are slower than Farseer or I am drawing them not in the right order... I just want your opinion and whats a possible solution.

Thanks for any assistance.

Mal

MASSIVE EDIT: As I posted this, I figured the issue out!! so easy, in the draw I was only calling the position updates after the matrix was called, so everything was 1 frame behind. Helps is you just read through the original testbed files again :)