3D Image Gallery

Posted By: Theil

3D Image Gallery - 04/14/10 02:54

Hi there, thanks for reading, what I want to make is a 3D image gallery, where if you put the mouse pointer to the right side of it, it will start to roll to the left so you can select an image to view, the problem is that I don't know where to start, I don't have any level loaded because it's a 2d program and I don't want to load a level because everytime I load one level, the fps decreases, what should I do?

here's an animation of what I want to do



I hope you can help me.
Posted By: Pappenheimer

Re: 3D Image Gallery - 04/14/10 09:01

I can't believe that level_load(NULL); decreases the fps.
With 3DGS a 3D room (level) actually is the easiest way to achieve what you want.

Although, you could create so called view entities, and move them this way, they don't need a level, as far as I know. Don't know whether you can use ent_morphskin with them. ent_morphskin would come in handy when you want to switch pictures.
The easiest way is to create a model in MED with two flat surfaces, placed in the distance of the radius of your circle of pictures to the model's origin, and load it as a view entity.

EDIT:

Found the chapter about view entities:

http://www.conitec.net/beta/aentities-intro.htm
Posted By: Theil

Re: 3D Image Gallery - 04/14/10 18:02

Hey thanks, that worked pretty well for me, I wasn't using a NULL level, now it works perfect, I also made every photo as a view entity with an entity on the center to orbit around it, here's the code:

reference_point.pan += 5*time_step;

photo_1.x = reference_point.x + 25 * sin(reference_point.pan);

photo_1.y = reference_point.y - 25 * cos(reference_point.pan);

photo_2.x = reference_point.x + 25 * sin(reference_point.pan + 36);

photo_2.y = reference_point.y - 25 * cos(reference_point.pan + 36);


Now I have one last question, I'm really bad with vectors and so, and I don't know how to do this but I want it to tilt a little like the picture I posted above, right now it looks like this:


one last thing is that every photo is facing the front view, the result I would like to achieve is like the one on the picture above.

I'm really thankful for your help, I need this as fast as I can because it's a prototype for the next week, sorry if I'm a little bit annoying but I'm still learning lite-C, BTW this forum is awesome, every time I log in, there's always an answer grin.
Posted By: Lukas

Re: 3D Image Gallery - 04/14/10 21:05

This should work:

vec_to_angle (pictureentity.pan, pictureentity.x);

If the rotation center isn't 0,0,0 you have to use the difference between the center position and your entity position. Also, you might have to invert the pan angle after doing this in case it ends up being facing the wrong direction.
Posted By: Theil

Re: 3D Image Gallery - 04/14/10 22:33

Hey thank you very much, that worked like a charm, this is what I did:

VECTOR temp;

vec_set(temp, photo_1.x);
vec_sub(temp,reference_point.x);
vec_to_angle(photo_1.pan, temp);

and that's it, works perfect, now the only thing left is the tilt, I don't really know how to do it, maybe some trigonometry calculation for it? I'm not good a trigonometry, and I found a few examples on trigonometry but not applied to game development.

Again thanks, awesome community the one that A7 has.:)
Posted By: Theil

Re: 3D Image Gallery - 04/15/10 08:36

I was messing around with the tilt and could not get anything, I think it has to do with the Z axis I don't know. I'd appreciate some help, I'm asking some help here because I don't really know what to do thanks.
Posted By: Pappenheimer

Re: 3D Image Gallery - 04/15/10 08:42

I would simply set the camera a bit above the circle of picture, and tilt it slightly.
Posted By: Theil

Re: 3D Image Gallery - 04/15/10 09:50

That doesn't work for me because they're view entities defined with ENTITY* instruction, and I already tried to define them with ent_create, but the photo is not showing even if I use set(photo_1,SHOW). Thanks for the quick replay.
Posted By: TSG_Torsten

Re: 3D Image Gallery - 04/15/10 10:02

Are you loading JPG-Images?
Because they're very memory-consuming, may you should also take a look how much memory your application needs, since this can also lead to slowdowns.

To your question:
If you're using view entities, I think tilt won't work (but I'm not sure about that). Why you don't span them as regular entities and setting the tilt?
If you use ent_create, make sure you create them at a xyz-position which is visible in the camera. You can press the "0" button in debug mode and move around the camera to see where your entities are created.

Regards
TSGames
Posted By: Theil

Re: 3D Image Gallery - 04/15/10 10:13

I don't get to see anything, does it has to do with layers?, anyway I don't have any jpeg and the fps now is working just fine with level_load(NULL); the photos are 3d planes with a texture in it and I can get to tilt the planes, but I'm not getting the result as the picture shown above because it just moves the tilt of the photo, I want it to look as if the camera has some tilt in it, could the background image block the view of the camera? if the answer is yes, maybe that's what happening but I still don't know how to fix this.
Posted By: MrGuest

Re: 3D Image Gallery - 04/15/10 13:33

hey,

I thought to myself you should be able to achieve this is less than 100 lines of code, so set myself the challenge laugh
Code:
#include <acknex.h>
#include <default.c>

#define PRAGMA_PATH "pics"

#include "debug.c"

ENTITY* ent_pic[8];
var var_offset = 0;

void main(){
	
	wait(1);
	level_load(NULL);
	
	STRING* str_temp = str_create("");
	VECTOR vec_temp;
	vec_temp.z = 0;
	
	int i;
	for(i = 0; i < 8; i++){
		
		str_cpy(str_temp, "pic");
		str_cat_num(str_temp, "%.0f.jpg", i);
		
		vec_temp.x = sin(i * 45) * 200;
		vec_temp.y = cos(i * 45) * 200;
		
		debug_str2("STR", str_temp);
		ent_pic[i] = ent_create(str_temp, vec_temp, NULL);
		
		vec_to_angle(ent_pic[i].pan, vec_temp);
	}
	
	//position camera
	vec_set(camera.x, vector(-520, 0, 260));
	
	vec_set(vec_temp, nullvector); 
	vec_sub(vec_temp, camera.x);
	vec_to_angle(camera.pan, vec_temp); // now MY looks at YOU
	
	vec_temp.z = 0;
	while(1){
		if(mouse_moving){
			
			var_offset += mickey.x;
			for(i = 0; i < 8; i++){
				
				vec_temp.x = sin((i * 45) + var_offset) * 200;
				vec_temp.y = cos((i * 45) + var_offset) * 200;
				vec_set(ent_pic[i].x, vec_temp);
				
				vec_to_angle(ent_pic[i].pan, vec_temp);
			}
		}
		wait(1);
	}
}



your pictures should be called pic0.jpg thro pic8.jpg

hope this helps

(58 lines including whitespace grin )
Posted By: Theil

Re: 3D Image Gallery - 04/16/10 02:57

works pretty well thanks really grin
Posted By: MadMark

Re: 3D Image Gallery - 04/25/10 17:30

Very cool, MrGuest. How would I alter this code so that the camera remains stationary, but the pictures rotate around the circle based on the mouse position?

Mark
Posted By: MrGuest

Re: 3D Image Gallery - 04/26/10 12:57

errr, don't set the camera position, and add mickey.x to the camera.pan?

Code:
#include <acknex.h>
#include <default.c>

#define PRAGMA_PATH "pics"

#include "debug.c"

ENTITY* ent_pic[8];
var var_offset = 0;

var var_campos = 0;

void campos_change(){
	
	var_campos = 1 - var_campos;
	
	switch(var_campos){
		
		case 0:
			vec_set(camera.x, nullvector);
			vec_set(camera.pan, nullvector);
		break;
		
		case 1:
			vec_set(camera.x, vector(-520, 0, 260));
			vec_set(vec_temp, nullvector);
			vec_sub(vec_temp, camera.x);
			vec_to_angle(camera.pan, vec_temp); // now MY looks at YOU
		break;
	}
}

void main(){
	
	wait(1);
	
	on_tab = campos_change;
	
	level_load(NULL);
	
	STRING* str_temp = str_create("");
	VECTOR vec_temp;
	vec_temp.z = 0;
	
	int i;
	for(i = 0; i < 8; i++){
		
		str_cpy(str_temp, "pic");
		str_cat_num(str_temp, "%.0f.jpg", i);
		
		vec_temp.x = sin(i * 45) * 200;
		vec_temp.y = cos(i * 45) * 200;
		
		debug_str2("STR", str_temp);
		ent_pic[i] = ent_create(str_temp, vec_temp, NULL);
		
		vec_to_angle(ent_pic[i].pan, vec_temp);
	}
	
	while(1){
		if(mouse_moving){
			
			switch(var_campos){
				
				case 0:
					
					camera.pan += mickey.x;
				break;
				
				case 1:
					
					var_offset += mickey.x;
					for(i = 0; i < 8; i++){
						
						vec_temp.x = sin((i * 45) + var_offset) * 200;
						vec_temp.y = cos((i * 45) + var_offset) * 200;
						vec_set(ent_pic[i].x, vec_temp);
						
						vec_to_angle(ent_pic[i].pan, vec_temp);
					}
				break;
			}
		}
		wait(1);
	}
}

press tab to toggle views
© 2024 lite-C Forums