Logic help (general)

Post your questions here
Post Reply
ddmx
Posts: 5376
Joined: Sun Apr 20, 2008 3:36 pm
Location: Midland MI

Logic help (general)

Post by ddmx »

In working on the program, I could use a little boost in the logic department. I've got it pulling the vertexs, pulling the tri indexs, and forming a matrix for each face. What seems to trouble me now, is I'm stuck on how to get it to fill the face with spheres. I've got a little bit of code started for placing the spheres on the tri, but not much. I haven't put a lot of time into it, but a boost is surely welcome. Please don't steal this code and release as your own (even though it's probably sloppy and poorly written).

Code: Select all

%David Diehl, 2010

clear,clc

%Prompt for input
r = input('Radius Size: ');
f = input('Friction Setting: ');
hs = input('High Speed Dampening: ');
ls = input('Low Speed Dampening: ');

%Get number of verts, ending cell, and make vert index matrix
vertCount = dlmread('Tri.jm', ' ', 'A3..A3'); %Number of vertices
vertEnd = num2str(3+vertCount); %ending line of vertice information
endCell = strcat('H', vertEnd); %N/A yet, used to make verts matrix
verts = dlmread('Tri.jm', ' ', 'A4..H12'); %Change '12' to the last ending row of verts
xyz = verts(:,1:3); %x y z coords for verts
[maxVerts,zzz] = size(verts); %max vertices
tris = dlmread('Tri.jm', ' ', [2 1 2 1]); %number of faces (tris) 

faceStart = maxVerts + 3; %line on which tri index starts
faceEnd = faceStart + maxVerts + 2; %line on which tri index ends
faceMatrix = [0 0 0]; %initialize matrix


%Sort vertexs into matrix
v1M = [0 0 0]; %vert 1 2 3 matrix
v2M = [0 0 0];
v3M = [0 0 0];
for i = 1:tris
    v1 = dlmread('Tri.jm', ' ', [faceStart 0 faceStart 0]); %gets vert 1 for tri 1 through max tris
    faceStart = faceStart + 3; %sets the tri index line to the 2nd vertex in the tri
    vertNum1 = xyz((v1+1),1:3); %sets the vertex coords from the # specified in v1
    v1M = [v1M;vertNum1]; %puts all vertNum1 in matrix
end
v1M = v1M(2:end,:) %takes off initial zeros
faceStart = faceStart - (3*tris)+1; %resets the tri starting point to the 2nd vertex index
for i = 1:tris
    v2 = dlmread('Tri.jm', ' ', [faceStart 0 faceStart 0]);
    faceStart = faceStart + 3;
    vertNum2 = xyz((v2+1),1:3);
    v2M = [v2M;vertNum2];
end
v2M = v2M(2:end,:)
faceStart = faceStart - (3*tris)+1;
for i = 1:tris
    v3 = dlmread('Tri.jm', ' ', [faceStart 0 faceStart 0]);
    faceStart = faceStart + 3;
    vertNum3 = xyz((v3+1),1:3);
    v3M = [v3M;vertNum3];
end
v3M = v3M(2:end,:)
faceStart = faceStart - (3*tris)+1;

[rowVM,colVM] = size(v1M) %size of the vert indexs, same as tri count

for k = 1:rowVM
    p1x = v1M(k,1);
    p1y = v1M(k,2);
    p1z = v1M(k,3);
    p2x = v2M(k,1);
    p2y = v2M(k,2);
    p2z = v2M(k,3);
    distR = sqrt(((p1x-p2x)^2) + ((p1y-p2y)^2) + ((p1z-p2z)^2)); %radius bewteen point 1 and 2
    slope12 = asin((p1y-p2y)/distR); %slope in rad
    d = 2*r; %diameter of sphere
    %while(1)
        %for l = 1:m
            col = [p1x p1y p1z r f hs ls]
            R1 = d/cos(slope12); %adjacent side of similar tri
            alpha = atan((p1x-p2x)/(p1y-p2y)); %angle between hypotenuse and adjacent side
            dx = R1*sin(alpha);
            dy = R1*cos(alpha);
            p1x = p1x + dx;
            p1y = p1y + dy
            m = m+1
    %end
    



end


%makes collision file out of spheres set at vertex points (uses after above is complete, used for testing)
x = verts(:,1)';
y = verts(:,2)';
z = verts(:,3)';
nx = verts(:,4)';
ny = verts(:,5)';
nz = verts(:,6)';
u = verts(:,7)';
v = verts(:,8)';
locx = 0;
locy = 0;
locz = 0;
col = [locx locy locz r f hs ls];

for n = 1:maxVerts
    locx = x(1,n)';
    locy = y(1,n)';
    locz = z(1,n)';
    col = [col;locx locy locz r f hs ls];    
end

col = col(2:end,:);

%writes collision file
dlmwrite('collision', maxVerts, ' ')
dlmwrite('collision', col, '-append', 'roffset', 0, 'delimiter', ' ')

type collision

jlv
Site Admin
Posts: 15116
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Re: Logic help (general)

Post by jlv »

Why don't you just subdivide the mesh a few times in blender, turn up the remove double limit and hit remove doubles? Then it's just a matter of outputting one sphere for each vertex and you don't have to worry about the triangles.
Josh Vanderhoof
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
DJ99X
Posts: 15524
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Logic help (general)

Post by DJ99X »

Good logic right there
wheels1758
Posts: 4132
Joined: Tue Oct 21, 2008 5:20 pm
Location: Washington, USA
Contact:

Re: Logic help (general)

Post by wheels1758 »

jlv wrote:Why don't you just subdivide the mesh a few times in blender, turn up the remove double limit and hit remove doubles? Then it's just a matter of outputting one sphere for each vertex and you don't have to worry about the triangles.
Damn. Makes too much sense.


I was going to say :

Image

So just connect P1 and P2, move 1 unit (how ever far depends on how dense you want the object to be) toward P3 from each point. Connect your new line and move to the next set of points.
ddmx
Posts: 5376
Joined: Sun Apr 20, 2008 3:36 pm
Location: Midland MI

Re: Logic help (general)

Post by ddmx »

Definitely the easy alternative. Requires a little bit more user input than I'd hoped for, kinda wanted it to be absolute fool proof. I could easily make a quick script that does that now, but it'll be a goal of mine to make a script that outputs a sphere oriented mesh by selecting a jm file down the road.

and wheels: I was kinda worn out from work and started working on the exact same principle you have there, until i figured out I'd need to concentrate a little to get it working. When i can sit down and focus on it more I'll whip something like that up.
DJ99X
Posts: 15524
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Logic help (general)

Post by DJ99X »

If a person can model, I'm sure that subdividing wouldn't be a difficult task...
ddmx
Posts: 5376
Joined: Sun Apr 20, 2008 3:36 pm
Location: Midland MI

Re: Logic help (general)

Post by ddmx »

Well, it just wrote a collision file for a ramp. 14,768 spheres of radius .075ft in about 1.25 seconds, with subdiving it took about 5 minutes. This may be the easy way out... :D
ddmx
Posts: 5376
Joined: Sun Apr 20, 2008 3:36 pm
Location: Midland MI

Re: Logic help (general)

Post by ddmx »

excuse me, .0375 radius...
ddmx
Posts: 5376
Joined: Sun Apr 20, 2008 3:36 pm
Location: Midland MI

Re: Logic help (general)

Post by ddmx »

Anyways, something so simple (comparitively) got me so excited... pardon that. I'll try to make a little app coded in visual basic that will give you a little more freedom than the script I wrote. Maybe it'll be a little weekend project, and maybe I'll have the full app (mesh of spheres) done by x-mas time. I'll try :wink:
jlv
Site Admin
Posts: 15116
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Re: Logic help (general)

Post by jlv »

I'd stick to at least a .5 radius and more if possible. The smaller the radius the more likely you are to get stuck in it. With the time step being 1/128 second, a bike traveling at 80 feet per second will move .625 feet per step. If the radius is bigger than that there is no chance of the bike punching through at that speed. With a tiny radius like .0375 you could get a reversed collision normal at only 5 ft/s.
Josh Vanderhoof
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
Post Reply