Commit 2149d188 authored by David Llewellyn-Jones's avatar David Llewellyn-Jones

Added initial code to Functy that will be used for rendering curves.

parent 435a0f7f
EXTRA_DIST = linux/build linux/functy.spec windows/*.bat windows/functy.wxs windows/Functy.ico windows/BootStrap/Functy.proj windows/BootStrap/GTK.VSBootstrapperManifest windows/BootStrap/GTK-2.12.9/product.xml windows/BootStrap/GTK-2.12.9/en/package.xml windows/wixui/*.wxs windows/wixui/CPL.TXT windows/wixui/functy/*.wxs windows/wixui/Bitmaps/*.bmp windows/wixui/Bitmaps/*.ico examples/*.xml debian/changelog debian/compat debian/control debian/copyright debian/docs debian/functy.1 debian/menu debian/rules debian/watch
EXTRA_DIST = linux/build linux/functy.spec windows/*.bat windows/functy.wxs windows/Functy.ico windows/BootStrap/Functy.proj windows/BootStrap/GTK.VSBootstrapperManifest windows/BootStrap/GTK-2.12.9/product.xml windows/BootStrap/GTK-2.12.9/en/package.xml windows/wixui/*.wxs windows/wixui/CPL.TXT windows/wixui/functy/*.wxs windows/wixui/Bitmaps/*.bmp windows/wixui/Bitmaps/*.ico examples/*.xml debian/changelog debian/compat debian/control debian/copyright debian/docs debian/functy.1 debian/menu debian/rules debian/watch resources/*
SUBDIRS = src assets
dist_doc_DATA = AUTHORS ChangeLog COPYING INSTALL NEWS README
......
This diff is collapsed.
<?xml version='1.0' encoding='UTF-8' ?>
<functy>
<settings>
<show-axes bool="0"/>
<invert bool="0"/>
<wireframe bool="0"/>
</settings>
<range>
<min>
<coord x="-15.860845" y="-15.860845" z="-15.860845"/>
</min>
<width>
<coord x="31.721691" y="31.721691" z="31.721691"/>
</width>
</range>
<function type="spherical">
<equation>(sin(t+p*10)+3)*(sin((a+ p)*5) + 3)</equation>
<red>0.8 + (0.2*sin((t/2)+(p*7)))</red>
<green>0.8+(0.2*sin((t/3)+(a*6)))</green>
<blue>0.528</blue>
<alpha>1.000</alpha>
<accuracy double="0.010000"/>
<centre-x>0.000</centre-x>
<centre-y>0.000</centre-y>
<centre-z>0.000</centre-z>
<texture-file></texture-file>
<texture-x-scale>1.0</texture-x-scale>
<texture-y-scale>1.0</texture-y-scale>
<texture-x-offset>0.0</texture-x-offset>
<texture-y-offset>0.0</texture-y-offset>
</function>
</functy>
<?xml version='1.0' encoding='UTF-8' ?>
<functy>
<settings>
<show-axes bool="0"/>
<invert bool="0"/>
<wireframe bool="0"/>
</settings>
<range>
<min>
<coord x="-18.500090" y="-18.500090" z="-18.500090"/>
</min>
<width>
<coord x="37.000180" y="37.000180" z="37.000180"/>
</width>
</range>
<function type="spherical">
<equation>(((sin(t+(p*10))**2)**1.5)+3)*(sin((a+ p)*5) + 3)</equation>
<red>0.8 + (0.2*sin((t/2)+(p*7)))</red>
<green>0.8+(0.2*sin((t/3)+(a*6)))</green>
<blue>0.528</blue>
<alpha>1.000</alpha>
<accuracy double="0.005000"/>
<centre-x>0.000</centre-x>
<centre-y>0.000</centre-y>
<centre-z>0.000</centre-z>
<texture-file></texture-file>
<texture-x-scale>1.0</texture-x-scale>
<texture-y-scale>1.0</texture-y-scale>
<texture-x-offset>0.0</texture-x-offset>
<texture-y-offset>0.0</texture-y-offset>
</function>
</functy>
<?xml version='1.0' encoding='UTF-8' ?>
<functy>
<settings>
<show-axes bool="0"/>
<invert bool="0"/>
<wireframe bool="0"/>
</settings>
<range>
<min>
<coord x="-19.980097" y="-19.980097" z="-19.980097"/>
</min>
<width>
<coord x="39.960194" y="39.960194" z="39.960194"/>
</width>
</range>
<function type="spherical">
<equation>(((sin(t+(p*10))**2)**1.5)+3)*(sin((a+ p)*5) + 3)</equation>
<red>0.8 + (0.2*sin((t/2)+(p*7)))</red>
<green>0.8+(0.2*sin((t/3)+(a*6)))</green>
<blue>(1+sin (a*100))/2</blue>
<alpha>1.000</alpha>
<accuracy double="0.010000"/>
<centre-x>0.000</centre-x>
<centre-y>0.000</centre-y>
<centre-z>0.000</centre-z>
<texture-file></texture-file>
<texture-x-scale>1.0</texture-x-scale>
<texture-y-scale>1.0</texture-y-scale>
<texture-x-offset>0.0</texture-x-offset>
<texture-y-offset>0.0</texture-y-offset>
</function>
</functy>
#!/usr/bin/env python
import os, sys, re
if len (sys.argv) < 2:
print "cleanglade.py removes instances of the 'swapped' attribute from glade XML files"
print "Syntax: cleanglade.py <Gladefile>"
else:
input = open (sys.argv[1]);
output = open ("temp.dat", 'w');
for s in input:
output.write (re.sub (' swapped=".*"', '', s))
input.close ()
output.close ()
os.rename ("temp.dat", sys.argv[1])
bin_PROGRAMS = ../functy
___functy_SOURCES = function.c function.h function_private.h functy.c functy.h textures.c textures.h utils.c utils.h vis.c vis.h filesave.c filesave.h cartesian.c cartesian.h spherical.c spherical.h shader.c shader.h
___functy_SOURCES = function.c function.h function_private.h functy.c functy.h textures.c textures.h utils.c utils.h vis.c vis.h filesave.c filesave.h cartesian.c cartesian.h spherical.c spherical.h shader.c shader.h tube.c tube.h vecsym.c vecsym.h
___functy_LDADD = -lsymbolic -lgtkglext-x11-1.0 -lgdkglext-x11-1.0 -lGLU -lglut -lXmu -lXt -lSM -lICE -lgtk-x11-2.0 -lpangox-1.0 -lX11 -lgdk-x11-2.0 -latk-1.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lgio-2.0 -lcairo -lpango-1.0 -lfreetype -lz -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lglee @FUNCTY_LIBS@
......
......@@ -60,10 +60,10 @@ typedef struct _FilesavePersist {
FilesavePersist * NewFilesavePersist (FunctyPersist * psFunctyData);
void DeleteFilesavePersist (FilesavePersist * psFilesaveData);
void Text (GMarkupParseContext * pContext, gchar const * szText, gsize nTextLen, gpointer psData, GError * * ppsError);
void EndElement (GMarkupParseContext * psContext, gchar const * szElementName, gpointer psData, GError * * ppsError);
void StartElement (GMarkupParseContext * psContext, gchar const * szElementName, gchar const * * aszAttributeNames, gchar const * * aszAttributeValues, gpointer psData, GError * * ppsError);
void DestroyUserData (gpointer psData);
void TextFuncty (GMarkupParseContext * pContext, gchar const * szText, gsize nTextLen, gpointer psData, GError * * ppsError);
void EndElementFuncty (GMarkupParseContext * psContext, gchar const * szElementName, gpointer psData, GError * * ppsError);
void StartElementFuncty (GMarkupParseContext * psContext, gchar const * szElementName, gchar const * * aszAttributeNames, gchar const * * aszAttributeValues, gpointer psData, GError * * ppsError);
void DestroyUserDataFuncty (gpointer psData);
void StartElementSettings (FILESAVETAG eTag, gchar const * * aszAttributeNames, gchar const * * aszAttributeValues, FilesavePersist * psFilesaveData);
void StartElementRange (FILESAVETAG eTag, gchar const * * aszAttributeNames, gchar const * * aszAttributeValues, FilesavePersist * psFilesaveData);
......@@ -262,16 +262,16 @@ bool LoadFile (char const * szFilename, bool boConfigure, FunctyPersist * psFunc
psFilesaveData->boConfigure = boConfigure;
psParser = g_new0 (GMarkupParser, 1);
psParser->start_element = StartElement;
psParser->end_element = EndElement;
psParser->text = Text;
psParser->start_element = StartElementFuncty;
psParser->end_element = EndElementFuncty;
psParser->text = TextFuncty;
psParser->passthrough = NULL;
psParser->error = NULL;
fhFile = fopen (szFilename, "rb");
if (fhFile) {
boSuccess = TRUE;
psParseContext = g_markup_parse_context_new (psParser, 0, (gpointer)psFilesaveData, DestroyUserData);
psParseContext = g_markup_parse_context_new (psParser, 0, (gpointer)psFilesaveData, DestroyUserDataFuncty);
nRead = fread (szFileBuffer, sizeof (char), FILE_BUFFER_SIZE, fhFile);
while (boSuccess && (nRead > 0)) {
......@@ -293,7 +293,7 @@ bool LoadFile (char const * szFilename, bool boConfigure, FunctyPersist * psFunc
return boSuccess;
}
void StartElement (GMarkupParseContext * psContext, gchar const * szElementName, gchar const * * aszAttributeNames, gchar const * * aszAttributeValues, gpointer psData, GError * * ppsError) {
void StartElementFuncty (GMarkupParseContext * psContext, gchar const * szElementName, gchar const * * aszAttributeNames, gchar const * * aszAttributeValues, gpointer psData, GError * * ppsError) {
FilesavePersist * psFilesaveData = (FilesavePersist *)psData;
psFilesaveData->nLevel++;
......@@ -412,7 +412,7 @@ void StartElement (GMarkupParseContext * psContext, gchar const * szElementName,
}
}
void EndElement (GMarkupParseContext * psContext, gchar const * szElementName, gpointer psData, GError * * ppsError) {
void EndElementFuncty (GMarkupParseContext * psContext, gchar const * szElementName, gpointer psData, GError * * ppsError) {
FilesavePersist * psFilesaveData = (FilesavePersist *)psData;
if ((psFilesaveData->nLevel >= 0) && (psFilesaveData->nLevel < MAX_LEVELS)) {
......@@ -438,13 +438,13 @@ void EndElement (GMarkupParseContext * psContext, gchar const * szElementName, g
g_string_set_size (psFilesaveData->szText, 0);
}
void Text (GMarkupParseContext * pContext, gchar const * szText, gsize nTextLen, gpointer psData, GError * * ppsError) {
void TextFuncty (GMarkupParseContext * pContext, gchar const * szText, gsize nTextLen, gpointer psData, GError * * ppsError) {
FilesavePersist * psFilesaveData = (FilesavePersist *)psData;
g_string_append_len (psFilesaveData->szText, szText, nTextLen);
}
void DestroyUserData (gpointer psData) {
void DestroyUserDataFuncty (gpointer psData) {
FilesavePersist * psFilesaveData = (FilesavePersist *)psData;
DeleteFilesavePersist (psFilesaveData);
}
......
......@@ -49,6 +49,9 @@ FuncPersist * NewFuncPersist (FUNCTYPE eType, double fAccuracy) {
case FUNCTYPE_SPHERICAL:
psFuncData->Func.psSphericalData = NewSphericalPersist ();
break;
case FUNCTYPE_TUBE:
psFuncData->Func.psTubeData = NewTubePersist ();
break;
default:
psFuncData->Func.psNone = NULL;
break;
......@@ -130,6 +133,10 @@ void DeleteFuncPersist (FuncPersist * psFuncData) {
DeleteSphericalPersist (psFuncData->Func.psSphericalData);
psFuncData->Func.psSphericalData = NULL;
break;
case FUNCTYPE_TUBE:
DeleteTubePersist (psFuncData->Func.psTubeData);
psFuncData->Func.psTubeData = NULL;
break;
default:
// Do absolutely nothing
break;
......@@ -248,6 +255,9 @@ void InitShader (FuncPersist * psFuncData) {
case FUNCTYPE_SPHERICAL:
SphericalInitShader (psFuncData);
break;
case FUNCTYPE_TUBE:
TubeInitShader (psFuncData);
break;
default:
// Do absolutely nothing
break;
......@@ -290,6 +300,9 @@ void SetFunctionShaderActive (bool boActive, FuncPersist * psFuncData) {
case FUNCTYPE_SPHERICAL:
SphericalSetShaderActive (boActive, psFuncData);
break;
case FUNCTYPE_TUBE:
TubeSetShaderActive (boActive, psFuncData);
break;
default:
// Do absolutely nothing
break;
......@@ -304,6 +317,9 @@ void SetFunction (char const * const szFunction, FuncPersist * psFuncData) {
case FUNCTYPE_SPHERICAL:
SphericalSetFunction (szFunction, psFuncData);
break;
case FUNCTYPE_TUBE:
TubeSetFunction ("a", "0", "0", szFunction, psFuncData);
break;
default:
// Do absolutely nothing
break;
......@@ -318,6 +334,9 @@ void SetFunctionColours (char const * const szRed, char const * const szGreen, c
case FUNCTYPE_SPHERICAL:
SphericalSetFunctionColours (szRed, szGreen, szBlue, szAlpha, psFuncData);
break;
case FUNCTYPE_TUBE:
TubeSetFunctionColours (szRed, szGreen, szBlue, szAlpha, psFuncData);
break;
default:
// Do absolutely nothing
break;
......@@ -337,6 +356,9 @@ void FunctionShadersRegenerate (FuncPersist * psFuncData) {
case FUNCTYPE_SPHERICAL:
szShader = SphericalGenerateVertexShader (psFuncData);
break;
case FUNCTYPE_TUBE:
szShader = TubeGenerateVertexShader (psFuncData);
break;
default:
// Do absolutely nothing
break;
......@@ -356,6 +378,9 @@ void FunctionShadersRegenerate (FuncPersist * psFuncData) {
case FUNCTYPE_SPHERICAL:
szShader = SphericalGenerateFragmentShader (psFuncData);
break;
case FUNCTYPE_TUBE:
szShader = TubeGenerateFragmentShader (psFuncData);
break;
default:
// Do absolutely nothing
break;
......@@ -445,6 +470,9 @@ void SetFunctionPosition (double fXMin, double fYMin, double fZMin, FuncPersist
case FUNCTYPE_SPHERICAL:
SphericalSetFunctionPosition (fXMin, fYMin, fZMin, psFuncData);
break;
case FUNCTYPE_TUBE:
TubeSetFunctionPosition (fXMin, fYMin, fZMin, psFuncData);
break;
default:
// Do absolutely nothing
break;
......@@ -532,6 +560,9 @@ void GetVertexDimensions (int * pnV1Vertices, int * pnV2Vertices, FuncPersist *
case FUNCTYPE_SPHERICAL:
SphericalGetVertexDimensions (pnV1Vertices, pnV2Vertices, psFuncData);
break;
case FUNCTYPE_TUBE:
TubeGetVertexDimensions (pnV1Vertices, pnV2Vertices, psFuncData);
break;
default:
// Do absolutely nothing
break;
......@@ -546,6 +577,9 @@ void PopulateVertices (FuncPersist * psFuncData) {
case FUNCTYPE_SPHERICAL:
SphericalPopulateVertices (psFuncData);
break;
case FUNCTYPE_TUBE:
TubePopulateVertices (psFuncData);
break;
default:
// Do absolutely nothing
break;
......@@ -560,6 +594,9 @@ void GenerateVertices (FuncPersist * psFuncData) {
case FUNCTYPE_SPHERICAL:
SphericalGenerateVertices (psFuncData);
break;
case FUNCTYPE_TUBE:
TubeGenerateVertices (psFuncData);
break;
default:
// Do absolutely nothing
break;
......
......@@ -27,6 +27,7 @@ typedef enum _FUNCTYPE {
FUNCTYPE_CARTESIAN,
FUNCTYPE_SPHERICAL,
FUNCTYPE_TUBE,
FUNCTYPE_NUM
} FUNCTYPE;
......
......@@ -16,6 +16,7 @@
#include "cartesian.h"
#include "spherical.h"
#include "tube.h"
#include "shader.h"
#include <symbolic.h>
......@@ -31,6 +32,7 @@ struct _FuncPersist {
union {
CartesianPersist * psCartesianData;
SphericalPersist * psSphericalData;
TubePersist * psTubeData;
void * psNone;
} Func;
......
......@@ -39,6 +39,10 @@
#define RADIUS_SCROLL (1)
#define FUNCTION_NEW_CARTESIAN "0"
#define FUNCTION_NEW_SPHERICAL "1"
#define FUNCTION_NEW_CURVE_RADIUS "1"
#define FUNCTION_NEW_CURVE_X "a"
#define FUNCTION_NEW_CURVE_Y "0"
#define FUNCTION_NEW_CURVE_Z "0"
#define ALPHA_NEW (0.9)
#define COLOUR_NEW_SHIFT (2.3)
#define RANGE_FORMAT "%g"
......@@ -112,8 +116,10 @@ static gboolean SaveFilePress (GtkWidget * psWidget, gpointer psData);
void PauseAnimation (bool boPause, FunctyPersist * psFunctyData);
void NewCartesianFunction (FunctyPersist * psFunctyData);
void NewSphericalFunction (FunctyPersist * psFunctyData);
void NewCurveFunction (FunctyPersist * psFunctyData);
static gboolean AddCartesianPress (GtkColorButton * psWidget, gpointer psData);
static gboolean AddSphericalPress (GtkColorButton * psWidget, gpointer psData);
static gboolean AddCurvePress (GtkColorButton * psWidget, gpointer psData);
gchar * GetTitleFilename (char const * szFilename);
void SetMainWindowTitle (char const * szFilename, FunctyPersist * psFunctyData);
......@@ -1187,6 +1193,14 @@ void NewCartesianFunction (FunctyPersist * psFunctyData) {
psWidget = glade_xml_get_widget (psFunctyData->psXML, "TabContentsCentre");
gtk_widget_hide (psWidget);
// Show the function tab
psWidget = glade_xml_get_widget (psFunctyData->psXML, "TabContentsFunction");
gtk_widget_show (psWidget);
// Hide the curve tab
psWidget = glade_xml_get_widget (psFunctyData->psXML, "TabContentsCurve");
gtk_widget_hide (psWidget);
// Set the window title
psWidget = glade_xml_get_widget (psFunctyData->psXML, "Function");
gtk_window_set_title (GTK_WINDOW (psWidget), "Edit Cartesian function");
......@@ -1281,6 +1295,14 @@ void NewSphericalFunction (FunctyPersist * psFunctyData) {
psWidget = glade_xml_get_widget (psFunctyData->psXML, "TabContentsCentre");
gtk_widget_show (psWidget);
// Show the function tab
psWidget = glade_xml_get_widget (psFunctyData->psXML, "TabContentsFunction");
gtk_widget_show (psWidget);
// Hide the curve tab
psWidget = glade_xml_get_widget (psFunctyData->psXML, "TabContentsCurve");
gtk_widget_hide (psWidget);
// Set the window title
psWidget = glade_xml_get_widget (psFunctyData->psXML, "Function");
gtk_window_set_title (GTK_WINDOW (psWidget), "Edit Spherical function");
......@@ -1299,6 +1321,119 @@ static gboolean AddSphericalPress (GtkColorButton * psWidget, gpointer psData) {
return TRUE;
}
void NewCurveFunction (FunctyPersist * psFunctyData) {
GtkWidget * psWidget;
GtkWidget * psRadiusEdit;
GtkWidget * psCurveXEdit;
GtkWidget * psCurveYEdit;
GtkWidget * psCurveZEdit;
GtkWidget * psColourWidget;
GtkWidget * psTexWidget;
GString * szValue;
GdkColor sColour;
double fRed;
double fGreen;
double fBlue;
double fAlpha;
psFunctyData->eNextFunctionType = FUNCTYPE_TUBE;
psFunctyData->psFuncEdit = NULL;
psRadiusEdit = glade_xml_get_widget (psFunctyData->psXML, "RadiusEdit");
psCurveXEdit = glade_xml_get_widget (psFunctyData->psXML, "CurveXEdit");
psCurveYEdit = glade_xml_get_widget (psFunctyData->psXML, "CurveYEdit");
psCurveZEdit = glade_xml_get_widget (psFunctyData->psXML, "CurveZEdit");
gtk_entry_set_text (GTK_ENTRY (psRadiusEdit), FUNCTION_NEW_CURVE_RADIUS);
gtk_entry_set_text (GTK_ENTRY (psCurveXEdit), FUNCTION_NEW_CURVE_X);
gtk_entry_set_text (GTK_ENTRY (psCurveYEdit), FUNCTION_NEW_CURVE_Y);
gtk_entry_set_text (GTK_ENTRY (psCurveZEdit), FUNCTION_NEW_CURVE_Z);
szValue = g_string_new ("");
GetNextColour (& fRed, & fGreen, & fBlue, & fAlpha, psFunctyData);
sColour.red = (guint16)floor ((65535.0 * fRed) + 0.5);
g_string_printf (szValue, "%.3f", fRed);
psColourWidget = glade_xml_get_widget (psFunctyData->psXML, "Red");
gtk_entry_set_text (GTK_ENTRY (psColourWidget), szValue->str);
sColour.green = (guint16)floor ((65535.0 * fGreen) + 0.5);
g_string_printf (szValue, "%.3f", fGreen);
psColourWidget = glade_xml_get_widget (psFunctyData->psXML, "Green");
gtk_entry_set_text (GTK_ENTRY (psColourWidget), szValue->str);
sColour.blue = (guint16)floor ((65535.0 * fBlue) + 0.5);
g_string_printf (szValue, "%.3f", fBlue);
psColourWidget = glade_xml_get_widget (psFunctyData->psXML, "Blue");
gtk_entry_set_text (GTK_ENTRY (psColourWidget), szValue->str);
g_string_printf (szValue, "%.3f", fAlpha);
psColourWidget = glade_xml_get_widget (psFunctyData->psXML, "Alpha");
gtk_entry_set_text (GTK_ENTRY (psColourWidget), szValue->str);
psWidget = glade_xml_get_widget (psFunctyData->psXML, "Colour");
gtk_color_button_set_color (GTK_COLOR_BUTTON (psWidget), & sColour);
gtk_color_button_set_alpha (GTK_COLOR_BUTTON (psWidget), (guint16)floor ((65535.0 * ALPHA_NEW) + 0.5));
psTexWidget = glade_xml_get_widget (psFunctyData->psXML, "TexFile");
gtk_entry_set_text (GTK_ENTRY (psTexWidget), "");
psTexWidget = glade_xml_get_widget (psFunctyData->psXML, "TexXScale");
gtk_entry_set_text (GTK_ENTRY (psTexWidget), "1.0");
psTexWidget = glade_xml_get_widget (psFunctyData->psXML, "TexYScale");
gtk_entry_set_text (GTK_ENTRY (psTexWidget), "1.0");
psTexWidget = glade_xml_get_widget (psFunctyData->psXML, "TexXOffset");
gtk_entry_set_text (GTK_ENTRY (psTexWidget), "0.0");
psTexWidget = glade_xml_get_widget (psFunctyData->psXML, "TexYOffset");
gtk_entry_set_text (GTK_ENTRY (psTexWidget), "0.0");
// Set up the centre values
g_string_printf (szValue, "%.3f", SPHERICAL_XCENTRE);
psWidget = glade_xml_get_widget (psFunctyData->psXML, "XCentre");
gtk_entry_set_text (GTK_ENTRY (psWidget), szValue->str);
g_string_printf (szValue, "%.3f", SPHERICAL_YCENTRE);
psWidget = glade_xml_get_widget (psFunctyData->psXML, "YCentre");
gtk_entry_set_text (GTK_ENTRY (psWidget), szValue->str);
g_string_printf (szValue, "%.3f", SPHERICAL_ZCENTRE);
psWidget = glade_xml_get_widget (psFunctyData->psXML, "ZCentre");
gtk_entry_set_text (GTK_ENTRY (psWidget), szValue->str);
// Show the centre tab
psWidget = glade_xml_get_widget (psFunctyData->psXML, "TabContentsCentre");
gtk_widget_show (psWidget);
// Show the curve tab
psWidget = glade_xml_get_widget (psFunctyData->psXML, "TabContentsCurve");
gtk_widget_show (psWidget);
// Hide the function tab
psWidget = glade_xml_get_widget (psFunctyData->psXML, "TabContentsFunction");
gtk_widget_hide (psWidget);
// Set the window title
psWidget = glade_xml_get_widget (psFunctyData->psXML, "Function");
gtk_window_set_title (GTK_WINDOW (psWidget), "Edit Curve function");
g_string_free (szValue, TRUE);
psWidget = glade_xml_get_widget (psFunctyData->psXML, "Function");
gtk_widget_show (psWidget);
}
static gboolean AddCurvePress (GtkColorButton * psWidget, gpointer psData) {
FunctyPersist * psFunctyData = (FunctyPersist * )psData;
NewCurveFunction (psFunctyData);
return TRUE;
}
void GetNextColour (double * pfRed, double * pfGreen, double * pfBlue, double * pfAlpha, FunctyPersist * psFunctyData) {
if (pfRed) {
* pfRed = 0.4 + 0.6 * ((cos (psFunctyData->fNewColour) + 1.0) / 2.0);
......@@ -1610,6 +1745,8 @@ int main (int argc, char *argv[]) {
g_signal_connect (psWidget, "clicked", G_CALLBACK (AddCartesianPress), (gpointer)psFunctyData);
psWidget = glade_xml_get_widget (psFunctyData->psXML, "AddSpherical");
g_signal_connect (psWidget, "clicked", G_CALLBACK (AddSphericalPress), (gpointer)psFunctyData);
psWidget = glade_xml_get_widget (psFunctyData->psXML, "AddCurve");
g_signal_connect (psWidget, "clicked", G_CALLBACK (AddCurvePress), (gpointer)psFunctyData);
psWidget = glade_xml_get_widget (psFunctyData->psXML, "DeleteFunction");
g_signal_connect (psWidget, "clicked", G_CALLBACK (DeleteFunctionPress), (gpointer)psFunctyData);
psWidget = glade_xml_get_widget (psFunctyData->psXML, "OpenView");
......
......@@ -509,8 +509,8 @@ void SphericalPopulateVerticesColour (FuncPersist * psFuncData) {
psFuncData->afColours[(nVertex * 4) + 3] = fColour;
// Calculate vertex texture coordinate
psFuncData->afTextureCoords[(nVertex * 2)] = (fAFunc * fTexXScale) + fTexXOffset;
psFuncData->afTextureCoords[(nVertex * 2) + 1] = (fPFunc * fTexYScale) + fTexYOffset;
psFuncData->afTextureCoords[(nVertex * 2)] = (fA * fTexXScale) + fTexXOffset;
psFuncData->afTextureCoords[(nVertex * 2) + 1] = (fP * fTexYScale) + fTexYOffset;
psFuncData->afVertices[(nVertex * 3)] = fXScreen;
psFuncData->afVertices[(nVertex * 3) + 1] = fYScreen;
......
This diff is collapsed.
///////////////////////////////////////////////////////////////////
// Functy
// 3D graph drawing utility
//
// David Llewellyn-Jones
// http://www.flypig.co.uk
//
// Spring 2009
///////////////////////////////////////////////////////////////////
#ifndef TUBE_H
#define TUBE_H
///////////////////////////////////////////////////////////////////
// Includes
///////////////////////////////////////////////////////////////////
// Defines
///////////////////////////////////////////////////////////////////
// Structures and enumerations
typedef struct _TubePersist TubePersist;
///////////////////////////////////////////////////////////////////
// Global variables
///////////////////////////////////////////////////////////////////
// Function prototypes
TubePersist * NewTubePersist ();
void DeleteTubePersist (TubePersist * psTubeData);
void TubeSetFunction (char const * const szXFunction, char const * const szYFunction, char const * const szZFunction, char const * const szRadius, FuncPersist * psFuncData);
void TubeSetFunctionColours (char const * const szRed, char const * const szGreen, char const * const szBlue, char const * const szAlpha, FuncPersist * psFuncData);
void TubePopulateVertices (FuncPersist * psFuncData);
void TubeGetVertexDimensions (int * pnAVertices, int * pnPVertices, FuncPersist * psFuncData);
void TubeGenerateVertices (FuncPersist * psFuncData);
char const * TubeGetXFunctionString (FuncPersist * psFuncData);
char const * TubeGetYFunctionString (FuncPersist * psFuncData);
char const * TubeGetZFunctionString (FuncPersist * psFuncData);
char const * TubeGetRadiusString (FuncPersist * psFuncData);
void TubeSetFunctionPosition (double fXMin, double fYMin, double fZMin, FuncPersist * psFuncData);
char * TubeGenerateVertexShader (FuncPersist * psFuncData);
char * TubeGenerateFragmentShader (FuncPersist * psFuncData);
void TubeInitShader (FuncPersist * psFuncData);
void TubeSetShaderActive (bool boActive, FuncPersist * psFuncData);
///////////////////////////////////////////////////////////////////
// Function definitions
#endif /* TUBE_H */
......@@ -8,29 +8,29 @@
// Spring 2008
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
// Includes
#include "utils.h"
#include "utils.h"
///////////////////////////////////////////////////////////////////
// Defines
///////////////////////////////////////////////////////////////////
// Structures and enumerations
///////////////////////////////////////////////////////////////////
// Global variables
static Matrix3 mId0 = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
static Matrix3 mId0 = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
///////////////////////////////////////////////////////////////////
// Function prototypes
///////////////////////////////////////////////////////////////////
// Function definitions
float absf (float fValue) {
if (fValue < 0.0f) fValue = -fValue;
return fValue;
......@@ -68,6 +68,26 @@ void Normalise3f (float * pfX, float * pfY, float * pfZ) {
*pfZ /= fLength;
}
Vector3 AddVectors (Vector3 const * v1, Vector3 const * v2) {
Vector3 vReturn;
vReturn.fX = (v1->fX + v2->fX);
vReturn.fY = (v1->fY + v2->fY);
vReturn.fZ = (v1->fZ + v2->fZ);
return vReturn;
}
Vector3 ScaleVector (Vector3 const * v1, float fScale) {
Vector3 vReturn;
vReturn.fX = (v1->fX * fScale);
vReturn.fY = (v1->fY * fScale);
vReturn.fZ = (v1->fZ * fScale);
return vReturn;
}
float Length (Vector3 * v1) {
return sqrt ((v1->fX * v1->fX) + (v1->fY * v1->fY) + (v1->fZ * v1->fZ));
}
......@@ -146,4 +166,15 @@ void PrintMatrix (Matrix3 * m1) {
void PrintVector (Vector3 * v1) {
printf ("[ %f, \t%f, \t%f \t]\n", v1->fX, v1->fY, v1->fZ);
}
Vector3 CrossProduct (Vector3 * v1, Vector3 * v2) {
Vector3 vResult;
vResult.fX = (v1->fY * v2->fZ) - (v1->fZ * v2->fY);
vResult.fY = (v1->fZ * v2->fX) - (v1->fX * v2->fZ);
vResult.fZ = (v1->fX * v2->fY) - (v1->fY * v2->fX);
return vResult;
}
......@@ -37,9 +37,14 @@
// Structures and enumerations
typedef struct _Vector3 {
GLfloat fX;
GLfloat fY;
GLfloat fZ;
union {
struct {
GLfloat fX;
GLfloat fY;
GLfloat fZ;
};
GLfloat afV[3];
};
} Vector3;
typedef struct _Matrix3 {
......@@ -62,16 +67,29 @@ typedef struct _Matrix3 {
float absf (float fValue);
Vector3 Normal (Vector3 * v1, Vector3 * v2);
Vector3 AddVectors (Vector3 const * v1, Vector3 const * v2);
//Vector3 SubtractVectors (Vector3 const * v1, Vector3 const * v2);
//Vector3 MultiplyVectors (Vector3 const * v1, Vector3 const * v2);
Vector3 ScaleVector (Vector3 const * v1, float fScale);
void Normalise (Vector3 * v1);
void Normalise3f (float * pfX, float * pfY, float * pfZ);
float Length (Vector3 * v1);
Matrix3 Invert (Matrix3 * m1);
float Determinant (Matrix3 * m1);
float DotProdAngle (float fX1, float fY1, float fX2, float fY2);
//float DotProdAngleVector (Vector3 * v1, Vector3 * v2);
//float DotProdVector (Vector3 const * v1, Vector3 const * v2);
Vector3 MultMatrixVector (Matrix3 * m1, Vector3 * v1);
void PrintMatrix (Matrix3 * m1);
void PrintVector (Vector3 * v1);
Vector3 CrossProduct (Vector3 * v1, Vector3 * v2);
//Matrix3 MultMatrixMatrix (Matrix3 * m1, Matrix3 * m2);
//void SetIdentity (Matrix3 * m1);
//Matrix3 RotationBetweenVectors (Vector3 * v1, Vector3 * v2);
//Matrix3 RotationAngleAxis (Vector3 * vAxis, float fAngle);
//Vector3 PerpendicularVector (Vector3 * pvVector);
///////////////////////////////////////////////////////////////////
// Function definitions
......
///////////////////////////////////////////////////////////////////
// VecSym
// Vector Symbolic structures
//
// David Llewellyn-Jones
// http://www.flypig.co.uk