[???] View-Frustum

Posted By: maslone1

[???] View-Frustum - 07/28/11 21:02

Hi


I have a question about the view-frustum.

with " my.clipfactor = 999999; " the entity never clips away.
but is this true?

999999 is for shure the distance from the camera to
the end of the view-frustum.
So if a opbject has a distance > than 999999 it clips also away again... am i right?

And another problem:
if i use "my.clipfactor" with a value > than 9,
the object is invisible....
Is there a rule in how to use my.clipfactor?


Posted By: maslone1

Re: [???] View-Frustum - 07/30/11 07:11

OK.

Nobody answered, so i've tested it out by myself.

The answere: a clipfactor of 999'999 is the maximum.

I've tried to use a higher value, but if i use for instanve 999'999'999
every object clips away from the beginning.


SO this is my question now:
Is there any way to use a higher value for the view-frustum?
Posted By: WretchedSid

Re: [???] View-Frustum - 07/30/11 07:31

You are limited by the the data type of the clipfactor which is var, so 1048576 is the maximum.
Posted By: maslone1

Re: [???] View-Frustum - 07/30/11 07:44

I see.

You're right JustSid

SO is there any chance to change the data-type for the view-frustum in lite-c?
For instance to long or double?
Posted By: maslone1

Re: [???] View-Frustum - 07/30/11 08:39

Usual i would use the cast-operation.

But what is the right name of the variable for the view-frustum
so i can use the cast-operation?

??? int view-frustum = xxxx ???
Posted By: WretchedSid

Re: [???] View-Frustum - 07/30/11 10:48

Nope, you can't change it to double. You can cast a double to var using explicit type casting but then you had a var and not a double meaning that you are still limited by the range of a var.

Btw, just for your interest, a double is in Lite-C a 32 bit floating point variable, not a double precision floating point.
Posted By: Superku

Re: [???] View-Frustum - 07/30/11 11:23

Quote:
So if a opbject has a distance > than 999999 it clips also away again... am i right?

No, that's not completely true. Take for example an object that has a size of 100 quants (size = radius of a sphere around the origin of the entity that completely surrounds it). Imagine, the entity is on the right-hand side of the view but not on the screen. If the origin of the entity is closer than 100 quants to the right plane of the view frustum, it will be rendered.
The entity variable clipfactor multiplies the size of the entity and uses that value in the visiblity check mentioned above (distance to plane closer than 100*clipfactor?).

Quote:
SO is there any chance to change the data-type for the view-frustum in lite-c?
[...]
But what is the right name of the variable for the view-frustum
so i can use the cast-operation?


What variable are you talking about, clipfactor (or camera.clip_far)? clipfactor is only defined for entities:

Code:
typedef struct ENTITY {
	C_LINK link;
	char	*type;		// entity file name
	var	x,y,z;		// position of the entity
...
	void*	body;			// physX actor
	var	clipfactor;		// visual clipping factor
} ENTITY;



You see, as JustSid already mentioned, the data type is var and cannot be changed.


I assume you are looking for something different, maybe a sky entity (that's a view entity with SKY or SCENE flag)?
Posted By: maslone1

Re: [???] View-Frustum - 07/30/11 18:00

i was looking for the var camera.clip_far.

But OK,... i already found it in the VIEW struct.
I already changed the type of clip_far from var to int in the atypes.h file.
Now it works, ....but for now with another little bug.
I'll try to fix the "new" bug....

thanks again!

Posted By: WretchedSid

Re: [???] View-Frustum - 07/30/11 18:01

The header file is completely informational (for you and Mr. Compiler)! Changing the struct there will have no difference at runtime!
Posted By: maslone1

Re: [???] View-Frustum - 07/30/11 19:02

interesting... my falt again. there must be another reason for the higher value i am able to use (ca. 2'095'000)

i've changed the type to "long". there are some changes in the handle of values.
But you're right again JustSid. The maximum value does not change frown

But now it is interesting for me, why i can use a camera.clip_far value of
2 x 1048577.999 (ca. 2'095'000)

the value should just work from -1048577.999 to +1048577.999

but ok. i accept the fact it is not changeable frown
I do not understand, why the view-frustum must have the typ var???
For small worlds, and indoor games it is fine. But for big worlds it would be nice to change the typ to int or long.
Posted By: WretchedSid

Re: [???] View-Frustum - 07/30/11 19:27

The reason why it looks like you could cram larger values into the variable is dead simple and lies in the roots of C. C is statically typed meaning that all type information is only available at compile time so the compiler can pick the right commands to work with the data. At runtime the type data isn't needed and the code just runs the same commands no matter what you give it as input.

Consider this function:
Code:
void foo(int bar)
{
   printf("Hey, the passed parameter is a int and it is: %i", bar);
}



Now we call the function, lets say like this: foo(23);
You can imagine what it prints, right?

Now consider this here:
Code:
STRING *baz = "HAHA, suck that";
...
foo((int)baz);



The compiler won't complain because you explicitly told it that you know that an int is expected, you gave no int but everything is perfectly right (there are various legit reasons to allow this). Anyway, it won't magically print your string but interpret the pointer to the string you passed it as an int resulting in the printf printing the address of that pointer...


So, back to what you did: You changed that data type to int, now the compiler sees that there is an int expected where previously you had a var. To get this clear, this doesn't change the struct at all as the engine is already compiled to expect var! The header is just their so the compiler knows what you mean with eg. camera->clip_factor, so that it knows at which memory address it can get the data. If you change it, you alter the commands your program runs, not the one the already compiled engine runs.
So now that you changed this to an int, the compiler will do implicit typecasting. So if you pass a var or a size_t whereas the data type is an int, it will typecast it for you (this works only in some cases where the signdes doesn't change and the data types have the same size). Anyway, you will now see an int and you can print an int, but the engine still uses var so it interprets the value other than you do.

Hope this clarifies the whole issue so far.
Posted By: maslone1

Re: [???] View-Frustum - 07/30/11 19:36

Perfect explain!
Thank you!

But it is still interesting for me to be able to use a value of ca. -2'097'000 to +2'097'000 in tne camera.clip_far (var unchanged).

I hope you have time to explain this too for me
(i like your explains, very clear, just direct facts, easy to understand)

Posted By: WretchedSid

Re: [???] View-Frustum - 07/30/11 20:05

Originally Posted By: maslone1

(i like your explains, very clear, just direct facts, easy to understand)

Thanks laugh

The problem is, you can't change the var type. Its has a fixed size (4 bytes) and thus is limited by them. As you can't change the data type, you can't fix it this way but what you could do is to scale everything down. Your models, your levels, everything, by the factor that you need to get the results you want with the range of a var.
Posted By: maslone1

Re: [???] View-Frustum - 07/30/11 20:40

Thanks again.

So back to the basics. I've already startet to create a conzept to handle the big objects. Sadly,.... now i have to write it smirk wink


So thanx again JustSid

CU
Marcel
© 2024 lite-C Forums