2 Questions

Started by
3 comments, last by Axesor 18 years, 4 months ago
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
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward
Advertisement
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 :) ).
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
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward
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!
That's what I was thinking. Thanks!
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward

This topic is closed to new replies.

Advertisement