PDA

View Full Version : Lightwave "sphere" what library (format) ?



FrankyGTH
09-06-2011, 04:14 AM
hello dear LW friends, I have a simple question if anybody knows what LW uses as library for a SPHERE ? (OpenGL, freeglut, glut or other things) I am programming little openGL app. beside I am working with LW and I am asking last days what library is used for LW primitives? I am interested in knowing this one until version LW 9.6 :)


void glutSolidSphere(GLdouble radius,
GLint slices, GLint stacks);
void glutWireSphere(GLdouble radius,
GLint slices, GLint stacks);

would be very nice to get some infos, best regards from germany, FrankyGTH

Lightwolf
09-06-2011, 04:28 AM
None... the primitives are custom code.

Cheers,
Mike

FrankyGTH
09-06-2011, 06:30 AM
dear mike, do you are meaning that's only "mathematical and physical correct sphere" programming? Can you tell more about this one? therefore the modeller using primitives is therefore damned fast ? thanks for fast reply! kind regards, frank

Lightwolf
09-06-2011, 06:38 AM
dear mike, do you are meaning that's only "mathematical and physical correct sphere" programming? Can you tell more about this one? therefore the modeller using primitives is therefore damned fast ? thanks for fast reply! kind regards, frank
I don't get you.
LW only used OpenGL to display the meshes... but not to actually create any geometry. All of that is using custom code (have a look at the SDK for some sampled on how to develop for Modeler).

What are you trying to achieve?

Cheers,
Mike

FrankyGTH
09-06-2011, 06:59 AM
hello mike! sorry, I haven't still had a look at sdk files (will do it this afternoon!), but I wanted a) to create some primitives in my own little openGL application (I already have done it), and b) then modified these primitives like you can do it with lightwave in modeller and thought there must be perhaps an alternative way to prevent using these common glut headers (I am using at the moment glut, freeglut). I've found some code snippets for a sphere and I wanted to use it, but I am starting programming in that openGL direction, I am not perfect with all these commands and my wish could be to make a sphere via left-mouse-click and modified the faces and much more ;) that's two dimension far from me or much more :D, best regards, thanks, frank

Lightwolf
09-06-2011, 07:06 AM
I'm afraid LW isn't going to help you a single bit then.

Cheers,
Mike

FrankyGTH
09-07-2011, 05:12 AM
thank you mike. But for me it's at the moment important to know or explore how professional programmers (for example these good newtek guys) are basically create primitives. So my idea was to ask here at lw forum I like it. I have written last years some ls scripts but they are using in some parts predefined (lw native) commands (like other 3d applications they're doing in same way!) so I cannot achieve what's the pure basis syntax of programming ;) I wanted only to know if lw developer they are programming the primitives from the scratch with pure c++ code..

something like that code example shows :)


#include "sphere.h"
#include "vertex.h"
#include "face.h"
#include "nurbssurface.h"
#include <algorithm>


Sphere::Sphere( float x, float y, float z, int _radius, int lod )
: Mesh( x, y, z )
{
m_radius = _radius;

float X = 0.525731112119133606;
float Z = 0.850650808352039932;

//base is 12 verts with 20 sides.
float vdata[ 12 ][ 3 ] = {{ -X, 0, Z}, { X, 0, Z}, { -X, 0, -Z}, {X, 0, -Z},
{ 0, Z, X}, { 0, Z, -X}, {0, -Z, X}, {0, -Z, -X},
{Z, X, 0}, { -Z, X, 0}, {Z, -X, 0}, { -Z, -X, 0}
};

//set up the faces...
int fdata[ 20 ][ 3 ] = {{0, 4, 1}, {0, 9, 4}, {9, 5, 4}, {4, 5, 8}, {4, 8, 1},
{8, 10, 1}, {8, 3, 10}, {5, 3, 8}, {5, 2, 3}, {2, 7, 3},
{7, 10, 3}, {7, 6, 10}, {7, 11, 6}, {11, 0, 6}, {0, 1, 6},
{6, 1, 10}, {9, 0, 11}, {9, 11, 2}, {9, 2, 5}, {7, 2, 11}
};



//create the vertices

for ( int i = 0; i < 12; i++ )
{
createVertex( vdata[ i ][ 0 ] * m_radius , vdata[ i ][ 1 ] * m_radius, vdata[ i ][ 2 ] * m_radius );
}

for ( int i = 0; i < 20; i++ )
{
vertex_subdivide( getVertex( fdata[ i ][ 2 ] ), getVertex( fdata[ i ][ 1 ] ), getVertex( fdata[ i ][ 0 ] ), lod );
}

normalize();


midpoints.clear();

}

Sphere::~Sphere()
{}

void Sphere::vertex_subdivide( Vertex *v1, Vertex *v2, Vertex *v3, int depth )
{
if ( depth == 1 )
{
createFace( v1 -> getParentIndex(), v2 -> getParentIndex(), v3 -> getParentIndex() );
return ;
}

Midpoint mp1 = findMidpoint( v1, v2 );
Midpoint mp2 = findMidpoint( v2, v3 );
Midpoint mp3 = findMidpoint( v3, v1 );

vertex_subdivide( v1, mp1.m, mp3.m, depth - 1 );
vertex_subdivide( v2, mp2.m, mp1.m, depth - 1 );
vertex_subdivide( v3, mp3.m, mp2.m, depth - 1 );
vertex_subdivide( mp1.m, mp2.m, mp3.m, depth - 1 );


}


Midpoint Sphere::findMidpoint( Vertex *v1, Vertex *v2 )
{

Midpoint mp;

mp.v1 = v1;
mp.v2 = v2;
mp.m = 0;

list < Midpoint > ::iterator it = std::find( midpoints.begin(), midpoints.end(), mp );

if ( it == midpoints.end() )
{
Vector4 p12;

p12 = ( v1->getPosition() + v2->getPosition() );

p12 *= .5;
p12.normalize();
p12 *= m_radius;

Vertex *v12 = createVertex( p12 );

mp.m = v12;
midpoints.insert( midpoints.end(), mp );
return mp;
}

else
{
return *it;
}
}



nice day, ciao, frank

Lightwolf
09-07-2011, 05:38 AM
I wanted only to know if lw developer they are programming the primitives from the scratch with pure c++ code..

More or less, yes. Except that it's very likely to be C only (especially code as this which is 10s of years old) ;)

Cheers,
Mike