Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, TipmyPip, VoroneTZ, Quad, 1 invisible), 688 guests, and 11 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Retrive dynamic lights placed in WED #302970
12/24/09 02:18
12/24/09 02:18
Joined: Jun 2004
Posts: 655
to your left
BoH_Havoc Offline OP
User
BoH_Havoc  Offline OP
User

Joined: Jun 2004
Posts: 655
to your left
Is there any way to retrive ALL dynamic lights which were placed in WED? I can't find anything in the manual about this.
I need to create an array of all dynamic lights in the level for my deferred shader. Retriving lights which were created by script is no problem, but the WED ones are giving me headaches.


Any ideas? laugh



Shade-C EVO Lite-C Shader Framework
Re: Retrive dynamic lights placed in WED [Re: BoH_Havoc] #303019
12/24/09 15:55
12/24/09 15:55
Joined: Oct 2004
Posts: 900
Lgh
rojart Offline
User
rojart  Offline
User

Joined: Oct 2004
Posts: 900
Lgh
Hi, the new feature ent_nextlight should to work, but have not tested yet.

Note:
"The ent_nextlight function now stores light info in the hit struct, and can also detect WED-placed lights."

"Returns
ENTITY* - Pointer to the light emitting entity, or A7.82 level_ent for a level-placed dynamic light or the sun, or NULL when no more light was in range."


Regards, Robert

Quote
Everything should be made as simple as possible, but not one bit simpler.
by Albert Einstein

PhysX Preview of Cloth, Fluid and Soft Body

A8.47.1P
Re: Retrive dynamic lights placed in WED [Re: rojart] #303044
12/24/09 20:05
12/24/09 20:05
Joined: Jun 2004
Posts: 655
to your left
BoH_Havoc Offline OP
User
BoH_Havoc  Offline OP
User

Joined: Jun 2004
Posts: 655
to your left
Yes i also thought about using ent_nextlight, but

Quote:
num - Number of the light (1..7), with 1 the closest and 7 the furthest light in range.


the function only returns the 7 nearest lights. If this wouldn't be fixed to 1->7 but 1->unlimited then this would be great fantastic and EXACTLY what i need.



Shade-C EVO Lite-C Shader Framework
Re: Retrive dynamic lights placed in WED [Re: BoH_Havoc] #303054
12/24/09 21:56
12/24/09 21:56
Joined: Aug 2008
Posts: 133
Sweden, Stockholm
E
Enduriel Offline
Member
Enduriel  Offline
Member
E

Joined: Aug 2008
Posts: 133
Sweden, Stockholm
hmm, I think I got a solution. Not sure yet.

What if you used ent_next and kept looping through every single entity in the level, and then calling that ent_nextlight with the entity retrieved from the previous funciton. You could also then maybe somehow do a check if the retrieved light is already on the list, if yes; skip it, else, add it.

Not sure though, just something that came to my mind.

Re: Retrive dynamic lights placed in WED [Re: Enduriel] #303070
12/25/09 00:04
12/25/09 00:04
Joined: Jun 2004
Posts: 655
to your left
BoH_Havoc Offline OP
User
BoH_Havoc  Offline OP
User

Joined: Jun 2004
Posts: 655
to your left
Nice idea laugh

But if there is only one model in the level and more than 7 lights, this won't work, as you can only get the 7 nearest lights of a model. So if there are 26 lights, i would only get 7 out of these 26 frown


Shade-C EVO Lite-C Shader Framework
Re: Retrive dynamic lights placed in WED [Re: BoH_Havoc] #303071
12/25/09 00:05
12/25/09 00:05
Joined: Aug 2008
Posts: 133
Sweden, Stockholm
E
Enduriel Offline
Member
Enduriel  Offline
Member
E

Joined: Aug 2008
Posts: 133
Sweden, Stockholm
ow yeah right =/ damn, I guess JCL needs to add a function to retrieve all the lights then to support deferred rendering tongue

EDIT: but hmm, I wonder if ent_next returns lights placed by WED. Cause afaik only ENTITY* can cast lights through the LIGHT flag if it's set, and I guess that the lights that are placed by WED are entities created by the engine when it's initialized. So maybe you should try ent_next and see if it returns an ENTITY* on an empty level with only WED placed lights, if it does, I bet it has the LIGHT flag set which let's you know it's a light

Last edited by Enduriel; 12/25/09 00:10.
Re: Retrive dynamic lights placed in WED [Re: Enduriel] #303079
12/25/09 00:43
12/25/09 00:43
Joined: Jun 2004
Posts: 655
to your left
BoH_Havoc Offline OP
User
BoH_Havoc  Offline OP
User

Joined: Jun 2004
Posts: 655
to your left
Just tried it.

ent_next seems to only return entities/models. Level Geometry (i.e. level_ent) and WED lights are not returned. >.<

oh well, guess that would have been to easy wink


Shade-C EVO Lite-C Shader Framework
Re: Retrive dynamic lights placed in WED [Re: BoH_Havoc] #303080
12/25/09 01:02
12/25/09 01:02
Joined: Aug 2008
Posts: 133
Sweden, Stockholm
E
Enduriel Offline
Member
Enduriel  Offline
Member
E

Joined: Aug 2008
Posts: 133
Sweden, Stockholm
Haha, well up to JCL from now on =}

Re: Retrive dynamic lights placed in WED [Re: Enduriel] #303081
12/25/09 01:39
12/25/09 01:39
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
hmm well I might be off here but I know a mechanism to read the .wmb file, and search through the data lists, and extract info about dynamic lights like position, colour, range.


Last edited by DJBMASTER; 12/25/09 04:17.
Re: Retrive dynamic lights placed in WED [Re: DJBMASTER] #303097
12/25/09 08:50
12/25/09 08:50
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Ok, here's a way to get all the dynamic lights in a level. It might be a little messy, as this is my first time using dynamic memory allocation functions (I'm a C# guy), haha...
Code:
/////////////////////////
// Includes /////////////
/////////////////////////

#include <acknex.h>
#include <default.c>
#include <stdio.h>

/////////////////////////
// Variables ////////////
/////////////////////////

DynamicLight* lights; // Array of dynamic lights.
int dynamic_light_counter = 0; // Amount of dynamic lights in our array.

/////////////////////////
// Structs //////////////
/////////////////////////

typedef struct
{
float x,y,z; 	
float red,green,blue;	
float range;	
} 
DynamicLight; // A simple struct to hold the properties of a dynamic light.

/////////////////////////
// Functions ////////////
/////////////////////////

// This function reads the internal structure of a .WMB file, and searches only for dynamic lights. It then creates a new DynamicLight struct
// with the light's properties and adds it to the global array (lights).

void GetDynamicLights(char* filename)
{
  FILE* file = fopen(level,"rb");
  fseek(file,124,SEEK_SET);

  var i = 0; int offset = 0, length = 0, num_of_objects = 0, object_type = 0;

  fread(&offset, sizeof(int), 1, file);
  fread(&length, sizeof(int), 1, file);
  fseek(file,offset,SEEK_SET);

  fread(&num_of_objects, sizeof(int), 1, file);
  
  int* offset_list = (int*)malloc (num_of_objects*sizeof(int));
  for(i = 0; i < num_of_objects; i++)
  {
		fread(&(offset_list[i]), sizeof(int), 1, file);
  }

  for(i=0; i < num_of_objects; i++)
  {
	  fseek(file,offset+offset_list[i],SEEK_SET);
	  fread(&object_type, sizeof(int), 1, file);

	  if(object_type == 2) // light
	  {
      fseek(file,offset+offset_list[i]+32,SEEK_SET);
		int flags = 0;
	
		fread(&flags, sizeof(long), 1, file);

		if(flags == 2)
		{
		fseek(file,offset+offset_list[i]+4,SEEK_SET);

		float x = 0.0, y = 0.0, z = 0.0;
		float red =0.0, blue =0.0, green = 0.0;
		float range = 0.0;
		
		fread(&x, sizeof(float), 1, file);
		fread(&y, sizeof(float), 1, file);
		fread(&z, sizeof(float), 1, file);
		fread(&red, sizeof(float), 1, file);
		fread(&green, sizeof(float), 1, file);
		fread(&blue, sizeof(float), 1, file);
		fread(&range, sizeof(float), 1, file);
		
		DynamicLight* new_light = (DynamicLight*)malloc(sizeof(DynamicLight));
		memset(new_light,0,sizeof(DynamicLight));
		new_light->x = x;
		new_light->y = y;
		new_light->z = z;
		new_light->red = (red*255)/100;
		new_light->green = (green*255)/100;
		new_light->blue = (blue*255)/100;
		new_light->range = range;
		
		lights = (DynamicLight*) realloc (lights, (dynamic_light_counter+1) * sizeof(DynamicLight));
		memcpy(&lights[dynamic_light_counter],new_light,sizeof(DynamicLight));
		dynamic_light_counter++;
		}
	  }
  }

  free (offset_list);
  fclose(file);
     
}

void main()
{
	GetDynamicLights("mylevel.wmb"); // Populate array of dynamic lights.
}



I've tested it and it works pretty well. Hope it helps.

DJB.

Last edited by DJBMASTER; 12/25/09 08:53.
Page 1 of 2 1 2

Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1