Jump to content

  • Log In with Google      Sign In   
  • Create Account


WiredCat

Member Since 09 Apr 2011
Offline Last Active Today, 02:25 PM
**---

#4990316 Save openGL objects to file

Posted by WiredCat on 15 October 2012 - 03:01 AM

I have changed your code :


I have changed your code :

#include "iostream.h" //sometimes need '#include "#stdio.h" ' or stdlib ;]

struct THeader{
int vertlen; //amount of vertices you want to save
};
struct t3dpoint {
float x;
float y;
float z;
};

THeader header;
t3dpoint * verts;


bool fullscreen = false;
bool mouseDown = false;
float xrot = 0.0f;
float yrot = 0.0f;
float xdiff = 0.0f;
float ydiff = 0.0f;
t3dpoint vertin(float x, float y, float z)
{
t3dpoint k;
k.x = x;
k.y = y;
k.z = z;
return k;
}
void CreateModelArray()
{
verts = new t3dpoint[24];

header.vertlen = 24;
verts[0] = vertin(-0.5f, -0.5f,  0.5f);
verts[1] = vertin( 0.5f, -0.5f,  0.5f);
	verts[2] = vertin( 0.5f,  0.5f,  0.5f);
	verts[3] = vertin(-0.5f,  0.5f,  0.5f);
	// BACK
	verts[4] = vertin(-0.5f, -0.5f, -0.5f);
	verts[5] = vertin(-0.5f,  0.5f, -0.5f);
	verts[6] = vertin( 0.5f,  0.5f, -0.5f);
	verts[7] = vertin( 0.5f, -0.5f, -0.5f);

	// LEFT
	verts[8] = vertin(-0.5f, -0.5f,  0.5f);
	verts[9] = vertin(-0.5f,  0.5f,  0.5f);
	verts[10] = vertin(-0.5f,  0.5f, -0.5f);
	verts[11] = vertin(-0.5f, -0.5f, -0.5f);
	// RIGHT
	verts[12] = vertin( 0.5f, -0.5f, -0.5f);
	verts[13] = vertin( 0.5f,  0.5f, -0.5f);
	verts[14] = vertin( 0.5f,  0.5f,  0.5f);
	verts[15] = vertin( 0.5f, -0.5f,  0.5f);

	// TOP
	verts[16] = vertin(-0.5f,  0.5f,  0.5f);
	verts[17] = vertin( 0.5f,  0.5f,  0.5f);
	verts[18] = vertin( 0.5f,  0.5f, -0.5f);
	verts[19] = vertin(-0.5f,  0.5f, -0.5f);
	// BOTTOM
	verts[20] = vertin(-0.5f, -0.5f,  0.5f);
	verts[21] = vertin(-0.5f, -0.5f, -0.5f);
	verts[22] = vertin( 0.5f, -0.5f, -0.5f);
	verts[23] = vertin( 0.5f, -0.5f,  0.5f);
}
void drawBox()
{
int i;
	glColor3f(1.0f, 0.0f, 0.0f);
	glBegin(GL_QUADS);
for (i=0; i<24;i++)
glVertex3f(verts[i].x,verts[i].y,verts[i].z);


	glEnd();
}
bool init()
{
	glClearColor(0.93f, 0.93f, 0.93f, 0.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glClearDepth(1.0f);
	return true;
}
void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	gluLookAt(
		0.0f, 0.0f, 3.0f,
		0.0f, 0.0f, 0.0f,
		0.0f, 1.0f, 0.0f);
	glRotatef(xrot, 1.0f, 0.0f, 0.0f);
	glRotatef(yrot, 0.0f, 1.0f, 0.0f);
	drawBox();
	glFlush();
	glutSwapBuffers();
}
void resize(int w, int h)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glViewport(0, 0, w, h);
	gluPerspective(45.0f, 1.0f * w / h, 1.0f, 100.0f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
void idle()
{
	if (!mouseDown)
	{
		xrot += 0.3f;
		yrot += 0.4f;
	}
	glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
	switch(key)
	{
	case 27 :
		exit(1); break;
	}
}
void specialKeyboard(int key, int x, int y)
{
	if (key == GLUT_KEY_F1)
	{
		fullscreen = !fullscreen;
		if (fullscreen)
			glutFullScreen();
		else
		{
			glutReshapeWindow(500, 500);
			glutPositionWindow(50, 50);
		}
	}
}
void mouse(int button, int state, int x, int y)
{
	if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
	{
		mouseDown = true;
		xdiff = x - yrot;
		ydiff = -y + xrot;
	}
	else
		mouseDown = false;
}
void mouseMotion(int x, int y)
{
	if (mouseDown)
	{
		yrot = x - xdiff;
		xrot = y + ydiff;
		glutPostRedisplay();
	}
}

void savemodel(char *filename)
{
FILE* f = fopen(filename,"wb+");
fwrite(&header,sizeof(THeader),1,f);

for (j=0; j < header.vertlen ; j++)  fwrite(&verts[j],sizeof(verts[j]),1,f);
fclose(f);
}
int main(int argc, char *argv[])
{
	glutInit(&argc, argv);
	glutInitWindowPosition(50, 50);
	glutInitWindowSize(500, 500);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
  
	glutCreateWindow("13 - Solid Shapes");
	glutDisplayFunc(display);
	glutKeyboardFunc(keyboard);
	glutSpecialFunc(specialKeyboard);
	glutMouseFunc(mouse);
	glutMotionFunc(mouseMotion);
	glutReshapeFunc(resize);
	glutIdleFunc(idle);
CreateModelArray();
	if (!init())
		return 1;
	glutMainLoop();
	return 0;
}



#4990179 Save openGL objects to file

Posted by WiredCat on 14 October 2012 - 04:48 PM

first thing do not use constructor in structure you want to save(ermove it) sec problem is you are not saving any vertices at all you haven't defined them glutSolidCube(2); will not define the vertices you want to save , last thing you are not saving verts in a function!!!! dude create a function that save verts, place structures in a header so it should be like this:

void saveverts()
{

FILE* f = fopen("vertices.txt","wb+");

fwrite(&header,sizeof(THeader),1,f);
rest of code

}
i am not a fairy please write an error you get
and you have
#include
#include
#include incldue what????


maybe you should start learn how to write programs, as far i can see you have no idea what you are doing


#4989734 Save openGL objects to file

Posted by WiredCat on 13 October 2012 - 05:19 AM

pls tell me what sort of errors, where compiler sees the error? or the progarm breaks when loading saving, pls also give code what you use, cheers
and almost forgot add #include "iostream.h"


#4953176 3D painting

Posted by WiredCat on 26 June 2012 - 05:30 PM

:0


#4952636 3D painting

Posted by WiredCat on 25 June 2012 - 06:57 AM

but you save output image as single image, there is nothing special to obtain a pixel coordinate in image from any perspective and do whatever you like


#4952511 3D painting

Posted by WiredCat on 24 June 2012 - 08:01 PM

i can post a code here but it will be native opengl and glu its simple that you find a point in 3d where your mouse is and then draw a blended or not quad on it

it is REALLY SIMPLE


#4944616 Most Optimized way to draw a circle DirectX

Posted by WiredCat on 30 May 2012 - 04:12 AM

vertex arrays


#4943951 texture mapping really slow

Posted by WiredCat on 28 May 2012 - 04:08 AM

aa and one other thing with doublebuffered make sure you ste opengl window to doublebuffered i don't know how you initialize opengl window so there could be the problem

i create ogl window by this:

void __fastcall TFCOpenGL::TWORZ_GL()
{
angle  = 0;
ppp  = 0;
PIXELFORMATDESCRIPTOR pfd;
int pf;


dc = GetDC( FCOpenGL->Handle );
ZeroMemory( &pfd, sizeof( pfd));
pfd.nSize = sizeof( pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 32;  pfd.cStencilBits	= 8;
pfd.iLayerType = PFD_MAIN_PLANE;

  pf = ChoosePixelFormat(dc, &pfd);   /
  SetPixelFormat(dc, pf, &pfd);
  rc = wglCreateContext(dc);  
  wglMakeCurrent(dc,rc);  

  glInit();

   OnResize(NULL);

}


and make sure that control on what you are displaying is doublebuffered too (*TWinControl)NAME->DoubleBuffered = true; ;]


#4942856 Cos is not returning 0 for 90 degrees or PI/2

Posted by WiredCat on 24 May 2012 - 04:27 AM

mayby you are using degrees instead of radians if you use degrees you must multiply angle by pi/180

const float imopi = 0.017453292519943295769236907684886;


so then you should write this Cos = cos( angle* imopi);


#4941591 BSP to Octree

Posted by WiredCat on 20 May 2012 - 12:24 AM

stupid question, just load map and create an octree


#4915324 Calculating forces, speed,acceleration of a plane

Posted by WiredCat on 21 February 2012 - 05:51 PM

I am trying to make the plane fly by calculating forces of thrust gravity drag and lift (but now i am only using now two forces: gravity and thrust)

nvm because i dont have a lift force because of Cl = 2 * pi * attack angle = 0.0ff


the stupidiest thing now i see that: my plane always goes down towards gravity vector even when thrust force is 2 times greater than gravity force and acts in the opposite direction

second issue is that: i cant calculate proper normalized vector (normalized gravity force vector)
in example: i have plane pos: x=50 000 m y = 100 m z = 30 000 m and the normalized vector is something like this: x = 0.7; y = 1.5, z= 0.4; and i donkt know why the y is fck-ing 1.5 here


i always get this effect (lol clouds are 320 km away form the surface - and we are in south america )
http://www.youtube.com/watch?v=hjHEzhOiURs



i use these equations:
F=m*a
s=v*t
s= v0*t+a*t*t*0.5

i start the simulation with this:

MODEL->t = GetTickCount();
MODEL->pos = position;
MODEL->old = position;

	void __fastcall TVehicle::ProcessFrame()
   {
		 int p = GetTickCount();
float x =  abs(float(p-t))/1000.0f;
if (x <=0 ) return;
t3dpoint kk;
kk = YPRangle.rf; //thrust force orientation

float Front_force = Throttle_to_force( Throttle );   //thrust force val
float Q = eGForce * mass;	// gravity force val

t3dpoint  TForce_vec;
t3dpoint  GForce_vec;

  TForce_vec  = YPRangle.rf;				 //thrust force direction (movement)

  t3dpoint c; c = vectorAB(pos, zero);//center of earth
  GForce_vec  = Normalize( c ); //g force direction

			//density
float drag_force = 0.350*pressure*(V*V/2.0f);

GForce_vec = vector_multiple(GForce_vec, Q);
TForce_vec = vector_multiple(TForce_vec, Front_force);

t3dpoint ALL_FORCES = vectors_add(GForce_vec, TForce_vec);//add forces
		//Cl = 2 * pi * pitch angle (in radians)
		//L = .5 * Cl * air_density * V^2 * A
	 t3dpoint VA;  //acceleration vector
	
VA = ALL_FORCES / mass;	  // a = F / m

float dk = ( x*x ) / 2.0f;	

VA = VA * dk;  //(a * t^2 )/ 2

float h = V*x;
VA = VA + h;				  //V0*t +	(a * t^2 )/ 2

//s = V0*t + (a * t^2 )/ 2


   pos = vectors_add(pos,VA );
   t = GetTickCount();
   V = n3ddistance(pos,old) / x;  // s = V / t	so calculate velocity
		   old = pos;
}


what am i doing wrong ?

now wypadkowa is ALL_FORCES :] no its not irricht its mine engine


#4882855 Texturing more than one poly

Posted by WiredCat on 11 November 2011 - 12:19 AM

it's sad that you treat me like a noob :)




i know how to map uv to verts....

for me wasting of time is downloading then installing 3dsmax and then learning the stuff... that is not the approach i want to achieve

i dont want to be rude but you are pissing me off xD whats your problem ? if you think that writing an application from beginning is waste of time then fair well but pls do not post that i should use others program

i am not a professional game maker or a graphic designer i have just passion, ever if i created first automatic recognition of analog tachographs did i use third party tools for it?[i do not mean compiler] but "it was a waste of time", yes purely waste of time lol ;)

when i was 14 i wrote my first 3d editing tool and why it was a waste of time [maybe it wasn't perfect but it worked and i use some of it's features nowdays],

you do not understand the basic concept that i want to do everything myself ( well with some help from other people ).




i just want to make multiplayer aircraft simulator yes sure for you its waste of time that you can download or buy other sims but mine will be free, there will be ability to explore whole earth in 3d like google earth + you will be able to create models etc just for fun (i wont write what the application can do now and what i am trying to implement), and it will be free and i do not care that if anyone ever will play this so WHO CARES but the basic concept is to create it without blenders without MS PAINT without third party stuff.. well i use NASA heightmap because how do i get the heightmap of the whole world maybe from "GOD" ahahahahhahh




I hope that post will prevent you from posting pointless posts, thank you! i will figure it out myself, i post questions because i want to get answers that point me into right direction of thinking.

if i write molecular dynamic and atom behaviour application is it waste of time ? for you its surely waste of time but not for me... yes there exists apps for such things and they are accurate but you cant add new funcionality to it [and do not tellme that 3dsmax has its own script language, i created scripted language for my 3d modelling tool when i was right! 14 and i had 1 year in programming experience ]







THAT IS NOT A WASTE OF TIME. I WANT TO LEARN learn and learn, BUT I DO NOT WANT TO LEARN A [Mod edit: stuff] LIKE I HAVE BEEN LEARNING IN SCHOOL YEARS AGO :D







and other thing if i sit on bench with friends talking about nothing and drinking beer you think that it is waste of time for me its not







YOUR answer is right in one specific situation: if i want to eat ham with bread and butter i need to buy it in a store UNLESS I AM THE BUTCHER (or farmer) got point?

---


by the way i think that i should check for coplanar faces group them and then in example calculate one of groups center point then apply uv coords but well for you its a waste of time....




I am really confused, your answers about download blender and map this with blender really piss me off REALLY PISS ME OFF the best of your thinking can be described as this how the [Mod edit: goodness me] i am supposed to import my model to blender ohhh sure i need to write a exporter to most common file format that program can read in example obj file well some loops some grouping and done and this is really a waste of time or you think that 'god' or my neighbour do it for me and i wont waste my time then huh?




nooo please do not reply this just read it and shut the hell up it will be nice to lock this topic or delete it because it's meaningless




you remind me those pricks from my team that steal in example tank or helicopter when i am repairing it in battlefield, my friend has a nice word for those guys and the word is:

[Mod edit: Delightful]


[Mod edit: More nonsensical rambling removed]

have a nice [Mod edit: Enjoyable] day



#4882774 Texturing more than one poly

Posted by WiredCat on 10 November 2011 - 06:11 PM

that's not the point. nvm




i think i need to find edges and then compare the distances from one vertex to the first vertex, but how to find edges





#4882652 Texturing more than one poly

Posted by WiredCat on 10 November 2011 - 10:55 AM

lololol, yes i built it myself and want to texture it myself too :P


#4881982 Screen not showing polygons with arrayelement()

Posted by WiredCat on 08 November 2011 - 10:11 PM

why not use glDrawArrays

glDrawArrays(GL_QUADS, verts[4*i], 4);? i didint found nothing else :0






maybe you place verts not there where you want to place them or just do not render them from correct perspective...






PARTNERS