|
Scaling a bitmap (Solved)
#384880
10/10/11 00:36
10/10/11 00:36
|
Joined: Sep 2009
Posts: 84
Theil
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2009
Posts: 84
|
I'm currently working on dijkstra and I'm showing the path chosen with draw_line3d, the problem with it, is that as you may know you can't adjust its width, so I thought about creating a bitmap that would scale itself from one node to the other with the given vectors, let's say scale from point A to point B, how can I achieve this? should I use some particles? thanks for reading I hope to find help soon. Screenshot:
Last edited by Theil; 10/10/11 05:39.
|
|
|
Re: Scale a bitmap
[Re: Theil]
#384881
10/10/11 01:03
10/10/11 01:03
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
i wrote this
#include <acknex.h>
#include <default.c>
BMAP* bmp_r;
BMAP* bmp_m;
void bmap_drawline(VECTOR* p0, VECTOR* p1, var s){
PANEL* pnl_m1 = pan_create("flags = SHOW", 99);
pnl_m1.bmap = bmp_m;
pnl_m1.pos_x = p0.x;
pnl_m1.pos_y = p0.y;
PANEL* pnl_m2 = pan_create("flags = SHOW", 99);
pnl_m2.bmap = bmp_m;
pnl_m2.pos_x = p1.x;
pnl_m2.pos_y = p1.y;
PANEL* pnl = pan_create("flags = SHOW", 100);
pnl.pos_x = p0.x;
pnl.pos_y = p0.y;
pnl.bmap = bmp_r;
pnl.center_x = 16;//bmap_
pnl.angle = atan2v((p0.y-p1.y),(p1.x-p0.x));
var dist = vec_dist(p0, p1);
while(pnl.size_x < dist + 24){
pnl.size_x += time_step * s;
wait(1);
}
}
void do_triangle(){
bmap_drawline(vector(200, 100, 0), vector(100, 100, 0), 10);
wait_for(bmap_drawline);
bmap_drawline(vector(100, 100, 0), vector(100, 300, 0), 10);
wait_for(bmap_drawline);
bmap_drawline(vector(100, 300, 0), vector(200, 100, 0), 10);
wait_for(bmap_drawline);
}
void main(){
wait(1);
bmp_m = bmap_createblack(32, 32, 24);
bmap_fill(bmp_m, COLOR_GREEN, 100);
bmp_r = bmap_createblack(16, 16, 24);
bmap_fill(bmp_r, COLOR_RED, 100);
do_triangle();
return;
}
a while ago, hopefully you'll find some use for it
|
|
|
Re: Scale a bitmap
[Re: MrGuest]
#384882
10/10/11 01:17
10/10/11 01:17
|
Joined: Sep 2009
Posts: 84
Theil
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2009
Posts: 84
|
Can you tell me how can I implement that code to this one? I was trying to do it, the problem is I have to specify each point for the line to get drawn, but as you can see I specify each one of them in a for loop, here you have the piece of code for it: for(i = 0; i < 15; i++) { if(path[i] != 0 || nodeA == 0) { path_line.x = node_x[path[i]]; path_line.y = node_y[path[i]]; draw_line3d(vector(path_line.x,path_line.y,10), vector(0,0,255), 250); } } Thank you very much.
|
|
|
Re: Scale a bitmap
[Re: Theil]
#384884
10/10/11 02:11
10/10/11 02:11
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
with draw_line3d it is drawn every frame which you won't want to do with a bmap, you'll need to create the bmap once and set it in place then just update it when necessary. here's a revised(new) code for drawing between the two nodes which should not be called every frame!
var var_bmapWidth = 8;
ENTITY* ent_node1; //temp for demo
ENTITY* ent_node2;
ENTITY* ent_node3;
void theil_line3d(VECTOR* vFrom, VECTOR* vTo, COLOR* color, var alpha){
VECTOR v;
vec_lerp(v, vFrom, vTo, 0.5);
you = ent_create("esper_drawline.bmp", v, NULL);
your.scale_x = vec_dist(vFrom, vTo) / 16; // change to bmap_width!
vec_set(v, vFrom.x);
vec_sub(v, vTo.x);
vec_to_angle(your.pan, v);
your.pan += 90;
your.tilt += 90;
}
void main(){
level_load(NULL);
ent_node1 = ent_create(CUBE_MDL, vector(100, 100, 0), NULL); //node from
ent_node2 = ent_create(CUBE_MDL, vector(250, -75, 0), NULL);
ent_node3 = ent_create(CUBE_MDL, vector(400, 30, 00), NULL);
vec_set(camera.x, vector(260, 15, 400));
camera.pan = 90; camera.tilt = -90;
theil_line3d(ent_node1.x, ent_node2.x, COLOR_RED, 100);
theil_line3d(ent_node1.x, ent_node3.x, COLOR_RED, 100);
}
also alpha is only from 0...100, you have it set at 250
|
|
|
Re: Scale a bitmap
[Re: MrGuest]
#384885
10/10/11 03:08
10/10/11 03:08
|
Joined: Sep 2009
Posts: 84
Theil
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2009
Posts: 84
|
I can't get it to work, here is the code: void theil_line3d(VECTOR* vFrom, VECTOR* vTo, COLOR* color, var alpha){ VECTOR v; test2++; vec_lerp(v, vFrom, vTo, 0.5); you = ent_create("punto.bmp", v, NULL); your.scale_x = vec_dist(vFrom, vTo) / 16; // change to bmap_width! vec_set(v, vFrom.x); vec_sub(v, vTo.x); vec_to_angle(your.pan, v); your.pan += 90; your.tilt += 90; }
function draw_path() {
VECTOR path_line; VECTOR path_line2; if(draw == 1) { for(i = 0; i < 15; i++) { if(path[i+1] != 0) { path_line.x = node_x[path[i]]; path_line.y = node_y[path[i]]; path_line2.x = node_x[path[i+1]]; path_line2.y = node_y[path[i+1]]; theil_line3d(path_line.x,path_line2.x , COLOR_RED, 100); } } wait(5); } } }
This is what I get:
Last edited by Theil; 10/10/11 03:09.
|
|
|
Re: Scale a bitmap
[Re: Theil]
#384891
10/10/11 05:22
10/10/11 05:22
|
Joined: Sep 2009
Posts: 84
Theil
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2009
Posts: 84
|
I finally solved, I used ptr_for_handle for each line and then made a function to delete them. The result is just beautiful! Thank you very much MrGuest!
Last edited by Theil; 10/10/11 05:23.
|
|
|
|