Sign in to follow this  
Axesor

2 Questions

Recommended Posts

Axesor    100
1.- Random. I add <time.h> and srand(time(NULL)) at the start of my program. I want to place smll cubes for stars randomly. I can't get it to work even if I (float) or float it. What do I do? 2.- I want to make a circle have texture of a ball but I want only 1 side to have a certain texture. I would also like to bend this object. Any ideas? ~Axesor

Share this post


Link to post
Share on other sites
bpoint    464
1. The rand() function returns an integer from 0 to RAND_MAX [usually 65535], which will give fairly large values, probably causing the cubes to be placed outside your viewport. A good function to use for float randoms is:

float randf(void)
{
return (float)rand() / (float)RAND_MAX;
}


This will return a float value from 0.0f -> 1.0f, then you can scale it by whatever amount you need.

2. There are many ways to texture map an object. If you split the circle into half, you can render two different textures. Another method is to use a pixel shader to render different textures with respect to lighting (nVidia has a good sample of this with an Earth model using daytime and nighttime textures being rendered simultaneously).

As for bending, there are a lot of different kinds of "bending". Are you looking to actually modify vertex data so it bends around another object? If so, you'll probably want to look into deforming. If you just want to do simple mesh distortion, applying a shearing model matrix transform might work. You'll have to be more specific (a picture drawn in paint doesn't hurt :) ).

Share this post


Link to post
Share on other sites
Axesor    100
Thanks for the random function! I just couldn't undertsand how to float it.
About the "bending", Say I have a laser. I want the beam to be short and dumpy, then I want it to get longer and stop, example: StarWars lightsaber.
~Thanks,
Axesor

Share this post


Link to post
Share on other sites
bpoint    464
Hmm... it sounds like you could just get away with a simple scaling matrix applied to a quad. While it might not give you the effect you're looking for, it should give you a basic idea to start with.

When you render your laser, simply use a quad with four vertices bound around (0.0f, 0.0f, 0.0f) -> (1.0f, 0.0f, 1.0f) applying glScalef to modify its structure. To alter the length, simply alter the Z scale... values less than 1.0f will make it smaller, while values more than 1.0f will make it larger. Likewise, to alter the width, change the X scale.

For your effect, start out with small values of Z (less than 1.0f) and medium values of X (around 3.0f), then make Z larger (up to about 15.0f, maybe?) while you shrink X down to 0.5f or so.

It's tough to describe, but this is a fairly primitive form of creating an effect. You could also either use a modelling package, and create laser model with animation, or make some kind of effect engine which would allow to you setup these parameters and have the application generate them at runtime.

Good luck!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this