C++ :: Good Object Oriented Approach To Meshing?
Aug 6, 2013
I'm a newbie to C++ and I've been working on this Delaunay tree in C for some time. I'm ready to port it to C++ which does not mean that the code itself is completed or done.
But I was wondering, how could I design my code to fully utilize C++?
For one, I'm using C++'s built-in stack/queue/vector functions because it's a lot nicer than building my own stacks or queues lol.
So, here's an overview of the code.
The mesh is built of tetrahedrons so I have a "struct tetra" which stores pointers to vertices ("struct particle") and its 4 neighbours. Working in half-plane data, we have:
Code:
struct particle {
double x, y, z;
};
struct tetra {
struct particle *p[4];//vertices
struct tetra *ngb[4];//neighbours
double a[4], b[4], c[4], d[4];//half-plane data
};
I'm fracturing these tetrahedrons by inserting vertices so I can get anywhere from 2 to 4 children per fracture per tetraheron. I'm mapping this history to a quadtree. This looks like :
Code:
struct tree {
int level;
struct tree *parent;
struct tree *children[4];
struct tetra *t;
};
What would be the best OO approach to this problem?
I thought about just using this object,
Code:
struct mesh {
struct tree *root; //pointer to root
/* insert all functions to be used by mesh here */
};
But I'm not sure how effectively this would be taking advantage of the OO paradigm.
View 4 Replies
ADVERTISEMENT
Nov 1, 2013
what are the advantages of files and how do we operate on binary files
View 1 Replies
View Related
Oct 27, 2013
Here is my code ... How to display student with given attributes ...
class student {
private:
int roll_no ;
char name[30];
char phone_no[15];
[Code] ....
View 1 Replies
View Related
Apr 4, 2014
Im having a problem with my sneaky hangman game I feel like im really close just getting an error I can't fix. When I run it, it says something like string subscript out of range when I goggled it. it says im searching past the bounds of what it should be or something.
Also a dictionary.txt file is needed to run the program
code: [URL]
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int guessesUsed = 0;
int wordlength;
[code]....
View 3 Replies
View Related
Mar 25, 2014
I'm getting a bit lost in calling functions correctly. The assignment says to, reprogram this assignment using functions and include the additional features identified below -
Design your program so the main function invokes/calls functions to perform the following tasks:
4) sort the arrays in ascending order by student ID number
Here's what I've got thus far and I'm confused cuz I might be calling my function incorrectly.
Code:
#include <stdio.h>
#define MAX_ENTRIES 50
void s_ID (int student_ID[], int test_score[], char char_val[]);
int main (void) {
[Code] .....
View 7 Replies
View Related
Sep 22, 2013
I realize that implicit int rule was removed in C99 but gcc still takes this approach by default. I wonder why this happens:
bbb = 5; // legal
int main(void) {
aaa = 10; // illegal
auto aaa = 10 // legal
Inside function a specifier is needed. Error message with no specifier used is:
error: ‘aaa’ undeclared (first use in this function)
Is this because of linkage - bbb variable has an external linkage so compiler knows that we are defining a variable here while inside mean() we need to show compiler that aaa is defined right here, it does not come from external functions?
View 4 Replies
View Related
Mar 16, 2013
will copy constructor does object initialization using another already created object? I understand that it can be applied for object initialization and not for assignment.Is it correct?
View 10 Replies
View Related
Jul 3, 2014
I have a method to take a Tile object and make an instances of it based on some data from the original object. Than it is suppose to manipulate the a specific instance and save the results. The first loop through it works but it changes all instance as well as the base.
public static int recurse(int count, Tile[,] b,Huristic h,int check) {
if (check==1) {
boardState.Add(B)/>;
return check;
} if (check == 0)
[Code] .....
View 6 Replies
View Related
Dec 13, 2012
#include "B.h"
class A {
public :
A()
{
s_b = new B();
b = new B();
[Code] ....
In my project i have seen static object as above . But not able to know what is the exact use of it and how they are different from general object .
View 2 Replies
View Related
Sep 11, 2014
a function returns a temporary object like
int myfun(){
int x = 0;
return x;
}
this function will return a temporary integer now void fun1(const int & num); this function can receive from myfun().BUT void fun2(int & num); this function cannot receive from myfun() Why is that, Moreover what is lifetime of a temporary object like one returned in myfun() ???
View 7 Replies
View Related
Mar 28, 2014
I am trying to use web api in order to return custom json response keys. For this i have return a custom class to return json response
Custom Class:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
[Code].....
View 2 Replies
View Related
May 4, 2013
I have a combobox with Items 1024
2048
4096
8192
String cach = form.comboCache.SelectedItem.ToString();
I am using the above code to retrive an item selected by user,But this line is giving an exception "Null Reference Exception, Object reference not set to an instance of an object"
View 1 Replies
View Related
Mar 28, 2014
I am using session to pass object from controller to custom class in MVC Web API. here is my code, i am getting error at session.
public HttpResponseMessage Get()
{
var person = db.Persons.ToList();
[Code]....
View 1 Replies
View Related
Aug 23, 2013
In Visual Studio 2010 C++
I have a series of existing text objects
The text properties names are
item1_lbl,
item2_lbl,
item3_lbl,
….
Based on a selection I want to change an object. I generate the name of the object I want to change in a string so from this string is there a way to get a pointer to the correct text object that is same name?
View 3 Replies
View Related
Sep 22, 2014
I'm trying to figure out how I can create a vertex array object at offset of a vertex buffer object.I've created the buffer object. I'd like the "texs" idnex data to start at the texture coordinate content of the vertex_t structure.
Type definitions:
struct vertex_t {
vector3d_t position;
float s; // Texture coordinate s
float t; // Texture coordinate t
};
Code so far:
// How do I make this start at a certain spot of the VBO?!
glVertexAttribPointer(texs, 2, GL_FLOAT, GL_FALSE, sizeof(vector3d_t), nullptr;
//...
View 1 Replies
View Related
Jan 21, 2013
The case is like
class B{
public:
somedata;
somefunction();
}
class A{
public:
data;
function();
}
in somefunction i want a pointer to current object of class A m new to c++
View 2 Replies
View Related
Oct 31, 2013
I have an assignment that asks me to implement a variant of the classic bouncing balls program.
'Each ball should start off at the top of the screen with a random speed in the x direction. Whenever a ball hits a screen boundary it should bounce off at an angle equal to the impact angle and lose some speed. Eventually each ball should come to a rest at the bottom of the screen. Five seconds after coming to a rest a ball should be removed from the screen.'
'Your code must keep track of objects (balls) by placing the object data structures in a linked list. You need to create your own linked list implementation. Below is a brief description of the object programming interface: CreateObject - Create a new object. The function accepts as input parameters a pointer to the SDL screen, a pointer to a model triangle array, and a variable telling the size of the model triangle array. The function returns a pointer to a new object data structure. The model triangle array specified as input parameter should not be shared across objects. (Not sharing the model triangle array allows e.g. objects to have different colors.)
Perform the necessary memory allocation and copying.DestroyObject - Free object. The function accepts as input parameters a pointer to an object data structure. The function should free all memory allocated to represent the object (memory allocated for the model triangle array and the object data structure itself).
Drawobject - Draw object on screen. The function accepts as input parameters a pointer to an object data structure. The function must draw the object on the screen by calling DrawTriangle on each of the model triangles. Remember to update scale, translation, etc., in each triangle data structure before invoking DrawTriangle.
Hint: Do not make the bouncing algorithm too complex. Bouncing a ball off a vertical or horizontal surface can be accomplished without resorting to calculating impact angles.'
The function I'm stuck at, is the first one - createobject.
My first aim is to get one ball on the screen.
Code:
// Create new object
object_t *CreateObject(SDL_Surface *screen, triangle_t *model, int numtriangles)
{
object_t *object = malloc(sizeof(object_t));
object->model = malloc(sizeof(sphere_model));
object->screen = SDL_Surface;
memcpy(*model, object->model, sizeof(object_t));
return object;
// Implement me
}
This is what I've done so far.
View 4 Replies
View Related
Dec 21, 2013
I have two classes one called Date and the other is University , Date class has two overloaded operators , ostream and istream to take in the data and print them out :
ostream & operator<<(ostream & out, Date & x) {
out<< x.month << "/" << x.day << "/" << x.year ;
return out;
[Code] ....
The University class has an object of type Date called establishDate and I must use this to print out the date along with the University name and location, here's University class :
University.h
class University {
public:
University (); // constructor
friend ostream & operator<<(ostream & out, University & x); // print the university data
friend istream & operator>>(istream & in, University & x); // to read university data
[Code] .....
so how do I use the establishDate object ?
View 2 Replies
View Related
Apr 20, 2013
it is not possible to get a type from an object, only from a type. Even with auto, you can only instantiate another type of the same type.I'd like to get a type from an object given another type, mainly because it is less typing and less error prone.
Some psudocode:
Type1 A<X, Y> a;
int b;
Type2 a.InnerType<b>::type c; // obviously won't work
A work around I thought of would be to use functions:
Type1 A<X, Y> a;
int b;
auto c = a.getInnerType(b);
Which is kinda interesting and looks like the way I'm going to go. However, I'm just wondering if there is any other ways of doing this as I don't really want to instantiate an object if I can avoid it (though the optimizer will probably just dump it anyway).
View 2 Replies
View Related
Jun 27, 2013
I have the following problem, I have an object of a class Subject, and I want that this object points to another object of class Classes, creating a kind of link. How can I do that?
View 4 Replies
View Related
May 26, 2014
So I am trying to develop a sort of 2d spacesim engine for creating games in C++. The project uses SFML for graphics, and I am currently trying to compile it on Linux using g++.
The main issue that I am wrestling with is that of simulation objects having their position, velocity, and rotation variables constantly getting set to NaN for reasons that are beyond me. The behaviour is not consistent, and occasionally will occur or not occur without any discernible pattern.
The github repo for the code is here: [URL] ....
I understand that NaN values can spread easily by operations on one another, but I cant seem to figure out where the initial issue is occurring here.
View 2 Replies
View Related
Mar 11, 2013
is it possible to get object name in the constructor? I would like to initialize an object of circle class without any arguments and put some pretty lines in constructor to get and save as table of chars the name of creating object. Is it possible? I work with MSVS2012.
View 4 Replies
View Related
Apr 18, 2014
int NextPixel(int antIndex, int currentPixel , Ant *ant , IplImage *edgeImg) {
int left = currentPixel - 1 ;
int right = currentPixel + 1 ;
int up = currentPixel - edgeImg->widthStep ;
int down = currentPixel + edgeImg->widthStep ;
[[Code] ....
if those lines are uncommented , program gives heap error.Why?
View 3 Replies
View Related
Mar 24, 2013
why we use this object and what purpose we use it
View 2 Replies
View Related
Nov 8, 2014
How can I return other object's value in a function(see code and comments)?
Person.h
Code:
#include <iostream>
#include <string>
using namespace std;
class Person{
public:
Person();
Person(string pname, int page);
[Code] ....
View 14 Replies
View Related
Apr 24, 2013
I am trying to pass an array of objects however i m finding some problems.
pieces.h
Code: class Cpiece{
public:
Cpiece* board[8][8];// array of objects
virtual char getcolor() =0;
virtual char setcolor(char colour)=0;
[Code] .....
View 10 Replies
View Related